本文整理汇总了Java中org.eclipse.xtext.nodemodel.util.NodeModelUtils.findActualNodeFor方法的典型用法代码示例。如果您正苦于以下问题:Java NodeModelUtils.findActualNodeFor方法的具体用法?Java NodeModelUtils.findActualNodeFor怎么用?Java NodeModelUtils.findActualNodeFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.nodemodel.util.NodeModelUtils
的用法示例。
在下文中一共展示了NodeModelUtils.findActualNodeFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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();
}
示例4: 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);
}
}
}
示例5: 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);
}
示例6: getNodeSequence
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
List<String> result = Lists.newArrayList();
GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
// System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni =
new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model), null, true, true);
while (ni.hasNext()) {
INode next = ni.next();
if (next instanceof ILeafNode)
result.add(titleSwitch.doSwitch(next.getGrammarElement()) + " -> " + next.getText());
if (next instanceof ICompositeNode)
result.add(titleSwitch.doSwitch(next.getGrammarElement()));
}
return result;
}
示例7: assertLastCompleteNode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private void assertLastCompleteNode(final String model, final String expectation) {
try {
int offset = model.indexOf("<|>");
if ((offset == (-1))) {
offset = model.length();
}
int completionOffset = model.indexOf("<|>", offset);
if ((completionOffset == (-1))) {
completionOffset = offset;
}
final Tree tree = this.parseHelper.parse(model.replace("<|>", ""));
final ICompositeNode nodeModel = NodeModelUtils.findActualNodeFor(tree);
final INode completeNode = this.getTestee().getLastCompleteNodeByOffset(nodeModel, offset, completionOffset);
this.assertNodeModel(expectation, completeNode);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例8: getImportDeletionChanges
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Compute changes that will remove all imports.
*
* @param resource
* the resource to modify
* @param document
* the document connected to the xtextResource, for textual changes.
* @return list of changes to the document.
*/
public static List<IChange> getImportDeletionChanges(XtextResource resource, IXtextDocument document)
throws BadLocationException {
List<IChange> changes = new ArrayList<>();
List<ScriptElement> elements = XtextResourceUtils.getScript(resource).getScriptElements();
// elements.filter(ImportDeclaration).map[findActualNodeFor(it)].forEach[changes.add(document.removeNodeButKeepComments(it))]
for (ScriptElement el : elements) {
if (el instanceof ImportDeclaration) {
INode nodeToRemove = NodeModelUtils.findActualNodeFor(el);
changes.add(removeNodeButKeepComments(document, nodeToRemove));
}
}
return changes;
}
示例9: checkClassDefinition
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Checks that no "with" is used and that list of implemented interfaces is separated with commas and not with
* keywords. These checks (with some warnings created instead of errors) should help the transition from roles to
* interfaces. However, they may be useful later on as well, e.g., if an interface is manually refactored into a
* class or vice versa.
* <p>
* Note that "with" is used in Dart for roles, so maybe it is useful to have a user-friendly message instead of a
* parser error.
*/
@Check
public void checkClassDefinition(N4ClassDefinition n4ClassDefinition) {
holdsNoKeywordInsteadOfComma(n4ClassDefinition);
ICompositeNode node = NodeModelUtils.findActualNodeFor(n4ClassDefinition);
ILeafNode keywordNode = findSecondLeafWithKeyword(n4ClassDefinition, "{", node, "extends", false);
if (keywordNode != null) {
TClass tclass = n4ClassDefinition.getDefinedTypeAsClass();
if (tclass == null) {
return; // avoid consequential errors
}
if (StreamSupport.stream(tclass.getImplementedInterfaceRefs().spliterator(), false).allMatch(
superTypeRef -> superTypeRef.getDeclaredType() instanceof TInterface)) {
List<? extends IdentifiableElement> interfaces = StreamSupport.stream(
tclass.getImplementedInterfaceRefs().spliterator(), false)
.map(ref -> (TInterface) (ref.getDeclaredType())).collect(Collectors.toList());
String message = getMessageForSYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP(
validatorMessageHelper.description(tclass), "extend",
"interface" + (interfaces.size() > 1 ? "s " : " ") + validatorMessageHelper.names(interfaces),
"implements");
addIssue(message, n4ClassDefinition, keywordNode.getTotalOffset(),
keywordNode.getLength(), SYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP);
}
}
}
示例10: holdsNoKeywordInsteadOfComma
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private boolean holdsNoKeywordInsteadOfComma(EObject semanticElement) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(semanticElement);
List<ILeafNode> commaAlternatives = filterLeafsWithKeywordInsteadOfComma(semanticElement, "{", node, "extends",
"implements",
"with");
boolean result = true;
for (ILeafNode n : commaAlternatives) {
addIssue(getMessageForSYN_KW_INSTEAD_OF_COMMA_WARN(n.getText()), semanticElement, n.getTotalOffset(),
n.getLength(), SYN_KW_INSTEAD_OF_COMMA_WARN);
result = false;
}
return result;
}
示例11: getMessageWithLocation
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Returns this error's message with a suffix explaining where the error occurred if {@link #astNode} is given. This
* method ignores field {@link #feature}.
*/
public String getMessageWithLocation() {
if (astNode == null) {
return message;
}
final INode node = NodeModelUtils.findActualNodeFor(astNode);
final String tokenText = node != null ? NodeModelUtils.getTokenText(node) : null;
if (tokenText == null) {
return message;
}
return message + " at \"" + tokenText + "\"";
}
示例12: findMultiLineComments
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Finds multi line comments on eObject. Comment is consider multiline by its type (e.g. start-end markers). Actual
* conents can be either single line, or multiline content.
*
* @param eObject
* on which we look for multiline comment
* @return list of nodes with comment, can be empty if no comments
*/
protected List<INode> findMultiLineComments(EObject eObject) {
// get node
INode elementNode = NodeModelUtils.findActualNodeFor(eObject);
HiddenLeafs hLeafs = hla.getHiddenLeafsBefore(elementNode);
// check for comments
if (!hLeafs.containsComment()) {
return null;
}
// get all comments
List<LeafInfo> leafs = hLeafs.getLeafs();
List<INode> comments = new ArrayList<>();
final TerminalRule SL = grammarAccess.getSL_COMMENTRule();
// get only MultiLine comments
for (LeafInfo li : leafs) {
if (li instanceof CommentInfo) {
INode commentNode = li.getNode();
EObject ge = commentNode.getGrammarElement();
// are we sure we get here only ML/SL ?
if (ge != SL) { // ignore SL
// finds ML and SML
comments.add(commentNode);
}
}
}
return comments;
}
示例13: rewrite
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public List<ReplaceRegion> rewrite() {
removeObsoleteStaticImports();
final List<ReplaceRegion> replaceRegions = newArrayList();
if (isSort) {
List<XImportDeclaration> allImportDeclarations = newArrayList();
allImportDeclarations.addAll(originalImportDeclarations);
allImportDeclarations.addAll(addedImportDeclarations);
allImportDeclarations.removeAll(removedImportDeclarations);
String newImportSection = serializeImports(allImportDeclarations);
importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
importRegion = regionUtil.addTrailingWhitespace(importRegion, resource);
return singletonList(new ReplaceRegion(importRegion, newImportSection));
} else {
for (XImportDeclaration removedImportDeclaration : removedImportDeclarations) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(removedImportDeclaration);
if (node != null) {
ITextRegion textRegion = node.getTextRegion();
textRegion = regionUtil.addTrailingSingleWhitespace(textRegion, lineSeparator, resource);
replaceRegions.add(new ReplaceRegion(textRegion, ""));
}
}
addSectionToAppend(new IAcceptor<ReplaceRegion>() {
@Override
public void accept(ReplaceRegion t) {
replaceRegions.add(t);
}
});
}
return replaceRegions;
}
示例14: computeRegion
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public ITextRegion computeRegion(XtextResource resource) {
XImportSection xImportSection = config.getImportSection(resource);
// try to obtain the region from the text if it is not a synthetic region.
if (xImportSection != null && xImportSection.eResource() != null) {
INode node = NodeModelUtils.findActualNodeFor(xImportSection);
if(node == null)
LOG.error("Cannot detect node for original import section");
else
return node.getTextRegion();
}
return new TextRegion(config.getImportSectionOffset(resource), 0);
}
示例15: nodeForKeyword
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public ILeafNode nodeForKeyword(final EObject obj, final String kw) {
ILeafNode _xblockexpression = null;
{
final ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
final Function1<INode, Boolean> _function = (INode it) -> {
return Boolean.valueOf(((Objects.equal(it.getSemanticElement(), obj) && (it.getGrammarElement() instanceof Keyword)) && Objects.equal(it.getText(), kw)));
};
INode _findFirst = IterableExtensions.<INode>findFirst(node.getAsTreeIterable(), _function);
_xblockexpression = ((ILeafNode) _findFirst);
}
return _xblockexpression;
}