本文整理汇总了Java中org.eclipse.xtext.nodemodel.util.NodeModelUtils类的典型用法代码示例。如果您正苦于以下问题:Java NodeModelUtils类的具体用法?Java NodeModelUtils怎么用?Java NodeModelUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeModelUtils类属于org.eclipse.xtext.nodemodel.util包,在下文中一共展示了NodeModelUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectAllResolutions
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
/**
* CollectAll resolutions under the cursor at offset.
*
*/
List<IssueResolution> collectAllResolutions(XtextResource resource, RegionWithCursor offset,
Multimap<Integer, Issue> offset2issue) {
EObject script = resource.getContents().get(0);
ICompositeNode scriptNode = NodeModelUtils.getNode(script);
ILeafNode offsetNode = NodeModelUtils.findLeafNodeAtOffset(scriptNode, offset.getGlobalCursorOffset());
int offStartLine = offsetNode.getTotalStartLine();
List<Issue> allIssues = QuickFixTestHelper.extractAllIssuesInLine(offStartLine, offset2issue);
List<IssueResolution> resolutions = Lists.newArrayList();
for (Issue issue : allIssues) {
if (issue.getLineNumber() == offsetNode.getStartLine()
&& issue.getLineNumber() <= offsetNode.getEndLine()) {
Display.getDefault().syncExec(() -> resolutions.addAll(quickfixProvider.getResolutions(issue)));
}
}
return resolutions;
}
示例2: getDeadCodeRegion
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
private DeadCodeRegion getDeadCodeRegion(Set<ControlFlowElement> deadCodeGroup) {
int startIdx = Integer.MAX_VALUE;
int endIdx = 0;
int firstElementOffset = Integer.MAX_VALUE;
ControlFlowElement firstElement = null;
for (ControlFlowElement deadCodeElement : deadCodeGroup) {
ICompositeNode compNode = NodeModelUtils.findActualNodeFor(deadCodeElement);
int elemStartIdx = compNode.getOffset();
int elemEndIdx = elemStartIdx + compNode.getLength();
startIdx = Math.min(startIdx, elemStartIdx);
endIdx = Math.max(endIdx, elemEndIdx);
if (elemStartIdx < firstElementOffset) {
firstElementOffset = elemStartIdx;
firstElement = deadCodeElement;
}
}
ControlFlowElement containerCFE = flowAnalyzer.getContainer(firstElement);
ControlFlowElement reachablePredecessor = findPrecedingStatement(firstElement);
return new DeadCodeRegion(startIdx, endIdx - startIdx, containerCFE, reachablePredecessor);
}
示例3: toAcceptor
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Override
protected Acceptor toAcceptor(IAcceptor<IReferenceDescription> acceptor) {
return new ReferenceAcceptor(acceptor, getResourceServiceProviderRegistry()) {
@Override
public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy,
URI targetURI) {
// Check if we should ignore named import specifier
if (N4JSReferenceQueryExecutor.ignoreNamedImportSpecifier && source instanceof NamedImportSpecifier)
return;
EObject displayObject = calculateDisplayEObject(source);
String logicallyQualifiedDisplayName = N4JSHierarchicalNameComputerHelper
.calculateLogicallyQualifiedDisplayName(displayObject, labelProvider, false);
ICompositeNode srcNode = NodeModelUtils.getNode(source);
int line = srcNode.getStartLine();
LabelledReferenceDescription description = new LabelledReferenceDescription(source, displayObject,
sourceURI,
targetOrProxy,
targetURI,
eReference, index, logicallyQualifiedDisplayName, line);
accept(description);
}
};
}
示例4: enhanceExistingImportDeclaration
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
QualifiedName qualifiedName,
String optionalAlias, MultiTextEdit result) {
addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
int offset = replaceMe.getOffset();
AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
optionalAlias,
offset,
grammarAccess);
try {
serializer.serialize(
importDeclaration,
observableBuffer,
SaveOptions.newBuilder().noValidation().getOptions());
} catch (IOException e) {
throw new RuntimeException("Should never happen since we write into memory", e);
}
result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
return observableBuffer.getAliasLocation();
}
示例5: findInsertionOffset
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
private int findInsertionOffset() {
int result = 0;
List<ScriptElement> scriptElements = script.getScriptElements();
for (int i = 0, size = scriptElements.size(); i < size; i++) {
ScriptElement element = scriptElements.get(i);
if (element instanceof ImportDeclaration) {
// Instead of getting the total offset for the first non-import-declaration, we try to get the
// total end offset for the most recent import declaration which is followed by any other script element
// this is required for the linebreak handling for automatic semicolon insertion.
final ICompositeNode importNode = NodeModelUtils.findActualNodeFor(element);
if (null != importNode) {
result = importNode.getTotalOffset() + getLengthWithoutAutomaticSemicolon(importNode);
}
} else {
// Otherwise, we assume there is no import declarations yet, we can put it to the top of the document.
return result;
}
}
return result;
}
示例6: doWrapAndWrite
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
/**
* Take the content of resource
*
* @param resource
* JS-code snippet which will be treated as text.
* @param outCode
* writer to output to.
*/
private void doWrapAndWrite(N4JSResource resource, Writer outCode) {
// check if wrapping really applies.
boolean moduleWrapping = projectUtils.isModuleWrappingEnabled(resource.getURI());
// get script
EObject script = resource.getContents().get(0);
// obtain text
CharSequence scriptAsText = NodeModelUtils.getNode(script).getRootNode().getText();
// wrap and write
String decorated = (moduleWrapping ? ModuleWrappingTransformation.wrapPlainJSCode(scriptAsText)
: scriptAsText).toString();
try {
outCode.write(decorated);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: toPos
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
private String toPos(EObject eobj) {
if (eobj == null)
return "";
StringBuilder strb = new StringBuilder();
String res = null;
if (eobj.eResource() != null) {
res = eobj.eResource().getURI().toString();
if (res.startsWith("platform:/resource/")) {
res = res.substring("platform:/resource/".length());
}
}
if (res != null)
strb.append(res);
EObject astNode = eobj instanceof SyntaxRelatedTElement ? ((SyntaxRelatedTElement) eobj).getAstElement() : eobj;
ICompositeNode node = NodeModelUtils.findActualNodeFor(astNode);
if (node != null) {
strb.append(":").append(node.getStartLine());
}
return strb.toString();
}
示例8: provideHighligtingFor
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
private void provideHighligtingFor(ElementReferenceExpression expression,
org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) {
EObject reference = expression.getReference();
if (reference instanceof Declaration) {
Declaration decl = (Declaration) expression.getReference();
switch (decl.getName()) {
case "msg":
case "block":
case "tx":
case "now":
case "this":
case "super":
ICompositeNode node = NodeModelUtils.findActualNodeFor(expression);
acceptor.addPosition(node.getTotalOffset(), node.getLength() + 1,
DefaultHighlightingConfiguration.KEYWORD_ID);
}
}
}
示例9: checkNoJavaStyleTypeCasting
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Check
public void checkNoJavaStyleTypeCasting(XBlockExpression blockExpression) {
if(isIgnored(JAVA_STYLE_TYPE_CAST)) {
return;
}
if (blockExpression.getExpressions().size() <= 1) {
return;
}
ICompositeNode node = NodeModelUtils.getNode(blockExpression);
if (node == null) {
return;
}
INode expressionNode = null;
for (INode child : node.getChildren()) {
if (isSemicolon(child)) {
expressionNode = null;
} else if (isXExpressionInsideBlock(child)) {
if (expressionNode != null) {
checkNoJavaStyleTypeCasting(expressionNode);
}
expressionNode = child;
}
}
}
示例10: createUnknownTypeReference
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
private LightweightTypeReference createUnknownTypeReference(JvmParameterizedTypeReference reference) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(reference, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
if (nodes.isEmpty()) {
Set<EObject> sourceElements = owner.getServices().getJvmModelAssociations().getSourceElements(reference);
EObject firstSource = Iterables.getFirst(sourceElements, null);
if (firstSource instanceof JvmParameterizedTypeReference) {
nodes = NodeModelUtils.findNodesForFeature(firstSource, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
}
}
if (nodes.size() == 1) {
String name = nodes.get(0).getText().trim();
if (name != null && name.length() != 0) {
int lastDot = name.lastIndexOf('.');
int lastDollar = name.lastIndexOf('$');
int lastDotOrDollar = Math.max(lastDot, lastDollar);
if (lastDotOrDollar != -1 && lastDotOrDollar != name.length() - 1) {
String shortName = name.substring(lastDotOrDollar + 1);
if (shortName.length() != 0) {
name = shortName;
}
}
return owner.newUnknownTypeReference(name);
}
}
return owner.newUnknownTypeReference();
}
示例11: getSignificantTextRegion
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
if (element instanceof XAbstractFeatureCall) {
XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element);
if (typeLiteral != null) {
if (typeLiteral instanceof XMemberFeatureCall) {
XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget();
if (target.isTypeLiteral()) {
return super.getSignificantTextRegion(typeLiteral);
}
}
INode node = NodeModelUtils.findActualNodeFor(typeLiteral);
if (node != null) {
return toZeroBasedRegion(node.getTextRegionWithLineInformation());
}
}
}
return super.getSignificantTextRegion(element);
}
示例12: resolveCrossReferencedElement
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Override
protected EObject resolveCrossReferencedElement(INode node) {
EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
if (referenceOwner != null) {
EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
referenceOwner.eClass());
if (!crossReference.isMany()) {
EObject resultOrProxy = (EObject) referenceOwner.eGet(crossReference);
if (resultOrProxy != null && resultOrProxy.eIsProxy() && crossReference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR) {
if (referenceOwner instanceof XConstructorCall) {
JvmIdentifiableElement linkedType = batchTypeResolver.resolveTypes(referenceOwner).getLinkedFeature((XConstructorCall)referenceOwner);
if (linkedType != null)
return linkedType;
}
}
return resultOrProxy;
} else {
return super.resolveCrossReferencedElement(node);
}
}
return null;
}
示例13: test1
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Test
public void test1() {
try {
this.with(ReferenceGrammarTestLanguageStandaloneSetup.class);
final String model = "kind (Hugo 13)";
final ParserRule kindRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getKindRule();
final XtextResource resource = this.createResource();
resource.setEntryPoint(kindRule);
StringInputStream _stringInputStream = new StringInputStream(model);
resource.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
Assert.assertTrue(resource.getErrors().isEmpty());
Assert.assertEquals(kindRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
final String originalNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
resource.update(0, model.length(), ((" " + model) + " "));
final String reparsedNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
Assert.assertEquals(originalNodeModel, reparsedNodeModel);
final ParserRule erwachsenerRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getErwachsenerRule();
resource.setEntryPoint(erwachsenerRule);
resource.update(0, model.length(), "erwachsener (Peter 30)");
Assert.assertEquals(erwachsenerRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例14: testTreeIteratorForSyntheticNodes_Backwards
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Test public void testTreeIteratorForSyntheticNodes_Backwards() throws Exception {
EObject object = getModel("d - e / e * d");
ICompositeNode root = NodeModelUtils.getNode(object).getRootNode();
INode firstChild = root.getFirstChild();
INode firstGrandChild = ((ICompositeNode) firstChild).getFirstChild();
INode sibling = firstGrandChild.getNextSibling().getNextSibling().getNextSibling();
INode siblingChild = ((ICompositeNode) sibling).getFirstChild();
INode siblingGrandChild = ((ICompositeNode) siblingChild).getFirstChild();
INode synthetic = ((ICompositeNode) siblingGrandChild).getFirstChild();
assertTrue(synthetic instanceof SyntheticCompositeNode);
INode expectedFirstChild = ((ICompositeNode)synthetic).getFirstChild();
while(expectedFirstChild instanceof ICompositeNode)
expectedFirstChild = ((ICompositeNode)expectedFirstChild).getFirstChild();
INode actualFirstChild = null;
for(INode child: synthetic.getAsTreeIterable().reverse())
actualFirstChild = child;
assertEquals(expectedFirstChild, actualFirstChild);
}
示例15: append
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入依赖的package包/类
@Override
public TreeAppendable append(JvmType type) {
if(type.eIsProxy()) {
String fragment = ((InternalEObject)type).eProxyURI().fragment();
Triple<EObject, EReference, INode> unresolvedLink = encoder.decode(getState().getResource(), fragment);
if(unresolvedLink != null) {
INode linkNode = unresolvedLink.getThird();
if(linkNode != null) {
append(NodeModelUtils.getTokenText(linkNode));
return this;
}
}
append("unresolved type");
return this;
}
return super.append(type);
}