当前位置: 首页>>代码示例>>Java>>正文


Java NodeModelUtils.getNode方法代码示例

本文整理汇总了Java中org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode方法的典型用法代码示例。如果您正苦于以下问题:Java NodeModelUtils.getNode方法的具体用法?Java NodeModelUtils.getNode怎么用?Java NodeModelUtils.getNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.nodemodel.util.NodeModelUtils的用法示例。


在下文中一共展示了NodeModelUtils.getNode方法的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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:QuickFixXpectMethod.java

示例2: 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);
		}
	};
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:26,代码来源:LabellingReferenceFinder.java

示例3: 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();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:25,代码来源:ImportRewriter.java

示例4: getErrorNode

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns the node that best describes the error, e.g. if there is an expression
 * <code>com::foo::DoesNotExist::method()</code> the error will be rooted at <code>com</code>, but
 * the real problem is <code>com::foo::DoesNotExist</code>.
 */
private INode getErrorNode(XExpression expression, INode node) {
	if (expression instanceof XFeatureCall) {
		XFeatureCall featureCall = (XFeatureCall) expression;
		if (!canBeTypeLiteral(featureCall)) {
			return node;
		}
		if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
			XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer();
			if (canBeTypeLiteral(container)) {
				boolean explicitStatic = container.isExplicitStatic();
				XMemberFeatureCall outerMost = getLongestTypeLiteralCandidate(container, explicitStatic);
				if (outerMost != null)
					return NodeModelUtils.getNode(outerMost);
			}
		}
	}
	return node;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:ScopeProviderAccess.java

示例5: getLocationWithoutTypeArguments

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected ILocationData getLocationWithoutTypeArguments(XAbstractFeatureCall call) {
	final ICompositeNode startNode = NodeModelUtils.getNode(call);
	if (startNode != null) {
		List<INode> resultNodes = Lists.newArrayList();
		if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) {
			boolean featureReferenceSeen = false;
			for (INode child : startNode.getChildren()) {
				if (featureReferenceSeen) {
					resultNodes.add(child);
				} else {
					EObject grammarElement = child.getGrammarElement();
					if (grammarElement instanceof CrossReference) {
						Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
						if (assignment != null && "feature".equals(assignment.getFeature())) {
							featureReferenceSeen = true;
							resultNodes.add(child);
						}
					}
				}
			}
		}
		return toLocationData(resultNodes);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:FeatureCallCompiler.java

示例6: completeXFeatureCall

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected void completeXFeatureCall(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model != null)) {
    boolean _hasExpressionScope = this.typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN);
    if (_hasExpressionScope) {
      return;
    }
  }
  if ((model instanceof XMemberFeatureCall)) {
    final ICompositeNode node = NodeModelUtils.getNode(model);
    boolean _isInMemberFeatureCall = this.isInMemberFeatureCall(model, node.getEndOffset(), context);
    if (_isInMemberFeatureCall) {
      return;
    }
  }
  this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseIdeContentProposalProvider.java

示例7: getFileLocation

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Return the fie location of a given object in a text resource as the path to the file and the line number.
 * <p>
 * This is very similar to {@link #getLocationString(EObject)} but it will not include the {@link Object#toString()} representation of the object.
 *
 * @param object
 *          any EObject
 * @return a string representation of the location of this object in its file, never {@code null}
 */
public static String getFileLocation(final EObject object) {
  if (object == null || object.eResource() == null) {
    return ""; //$NON-NLS-1$
  }

  URI uri = object.eResource().getURI();
  // CHECKSTYLE:CHECK-OFF MagicNumber
  String path = uri.isPlatform() ? '/' + String.join("/", uri.segmentsList().subList(3, uri.segmentCount())) : uri.path(); //$NON-NLS-1$
  // CHECKSTYLE:CHECK-ON MagicNumber
  StringBuilder result = new StringBuilder(path);
  final ICompositeNode node = NodeModelUtils.getNode(object);
  if (node != null) {
    result.append(':').append(node.getStartLine());
  }

  return result.toString();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:EObjectUtil.java

示例8: findComment

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Performs a special check on check catalogs: the first node belonging to check catalog and
 * having a multi-line comment as grammar element is used for {@link #getJavaDocComment(INode)}.
 * <p>
 * {@inheritDoc}
 */
@Override
protected String findComment(final EObject object) {
  if (object instanceof CheckCatalog) {
    ICompositeNode node = NodeModelUtils.getNode(object);
    try {
      INode find = Iterables.find(node.getAsTreeIterable(), new Predicate<INode>() {
        public boolean apply(final INode abstractNode) {
          return abstractNode.getSemanticElement() instanceof CheckCatalog && abstractNode.getGrammarElement() == grammarAccess.getML_COMMENTRule();
        }
      });
      return getJavaDocComment(find);
    } catch (NoSuchElementException e) {
      return null;
    }
  }
  return super.findComment(object);
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:24,代码来源:CheckEObjectDocumentationProvider.java

示例9: setTarget

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public void setTarget(EObject object, EStructuralFeature feature) {
	EObject myObject = object;
	INode result = NodeModelUtils.getNode(myObject);
	while(result == null && myObject.eContainer() != null) {
		myObject = myObject.eContainer();
		result = NodeModelUtils.getNode(myObject);
	}
	if (result == null)
		throw new IllegalStateException("Cannot find NodeAdapter for object: " + object);
	else {
		if (feature == null) {
			feature = myObject.eClass().getEStructuralFeature("name");
		}
		if (feature != null) {
			List<INode> nodes = NodeModelUtils.findNodesForFeature(myObject, feature);
			if (nodes.size() == 1) {
				result = nodes.get(0);
			}
		}
	}
	setNode(result);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:TransformationDiagnosticsProducer.java

示例10: getDocumentationNodes

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns the nearest multi line comment node that precedes the given object. 
 * @since 2.3
 * @return a list with exactly one node or an empty list if the object is undocumented.
 */
/* @NonNull */
@Override
public List<INode> getDocumentationNodes(/* @NonNull */ EObject object) {
	ICompositeNode node = NodeModelUtils.getNode(object);
	List<INode> result = Collections.emptyList();
	if (node != null) {
		// get the last multi line comment before a non hidden leaf node
		for (ILeafNode leafNode : node.getLeafNodes()) {
			if (!leafNode.isHidden())
				break;
			if (leafNode.getGrammarElement() instanceof TerminalRule
					&& ruleName.equalsIgnoreCase(((TerminalRule) leafNode.getGrammarElement()).getName())) {
				String comment = leafNode.getText();
				if (commentStartTagRegex.matcher(comment).matches()) {
					result = Collections.<INode>singletonList(leafNode);
				}
			}
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:MultiLineCommentDocumentationProvider.java

示例11: createEObjectNode

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns N4JSEObjectNode instead of simple EObjectNode to allow for attaching additional information such as
 * inheritance state of members.
 */
@Override
public N4JSEObjectNode createEObjectNode(IOutlineNode parentNode, EObject modelElement,
		ImageDescriptor imageDescriptor,
		Object text,
		boolean isLeaf) {
	N4JSEObjectNode eObjectNode = new N4JSEObjectNode(modelElement, parentNode, imageDescriptor, text, isLeaf);
	ICompositeNode parserNode = NodeModelUtils.getNode(modelElement);
	if (parserNode != null)
		eObjectNode.setTextRegion(parserNode.getTextRegion());
	if (isLocalElement(parentNode, modelElement))
		eObjectNode.setShortTextRegion(getLocationInFileProvider().getSignificantTextRegion(modelElement));
	return eObjectNode;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:18,代码来源:N4JSOutlineNodeFactory.java

示例12: withLine

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns a (maybe new) RepoRelativePath with line number of the given test member.
 */
public RepoRelativePath withLine(SyntaxRelatedTElement testMember) {
	ICompositeNode node = NodeModelUtils.getNode(testMember.getAstElement());
	if (node != null) {
		final int line = node.getStartLine();
		final RepoRelativePath rrp = new RepoRelativePath(repositoryName, pathInRepository, projectName,
				pathInProject, line);
		return rrp;
	}
	return this;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:14,代码来源:RepoRelativePath.java

示例13: getDocumentation

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private String getDocumentation(/* @NonNull */EObject object) {
	if (object.eContainer() == null) {
		// if a comment is at the beginning of the file it will be returned for
		// the root element (e.g. Script in N4JS) as well -> avoid this!
		return null;
	}

	ICompositeNode node = NodeModelUtils.getNode(object);
	if (node != null) {
		// get the last multi line comment before a non hidden leaf node
		for (ILeafNode leafNode : node.getLeafNodes()) {
			if (!leafNode.isHidden())
				break;

			EObject grammarElem = leafNode.getGrammarElement();
			if (grammarElem instanceof TerminalRule
					&& "ML_COMMENT".equalsIgnoreCase(((TerminalRule) grammarElem).getName())) {

				String comment = leafNode.getText();
				if (commentStartTagRegex.matcher(comment).matches()) {
					return leafNode.getText();
				}
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:28,代码来源:ASTGraphProvider.java

示例14: getDocumentationNodes

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns documentation nodes for N4JS AST and type elements (in which case the method returns the nodes of the
 * corresponding AST element). If the AST element has no documentation nodes itself, but is an exportable element,
 * then the documentation of the export statement is returned if present.
 */
@Override
public List<INode> getDocumentationNodes(EObject object) {
	final EObject astNode = N4JSASTUtils.getCorrespondingASTNode(object);
	if (astNode != null) {
		List<INode> nodes = super.getDocumentationNodes(astNode);
		if (nodes.isEmpty() && astNode instanceof VariableDeclaration) {
			TypeRef typeRef = ((VariableDeclaration) astNode).getDeclaredTypeRef();
			if (typeRef != null) {
				nodes = getDocumentationNodes(typeRef);
			}
		}
		if (nodes.isEmpty()) {
			if (astNode instanceof ExportedVariableDeclaration
					&& astNode.eContainer() instanceof ExportedVariableStatement) {
				EList<VariableDeclaration> decls = ((ExportedVariableStatement) astNode.eContainer()).getVarDecl();
				if (decls.size() == 1) {
					return getDocumentationNodes(astNode.eContainer());
				}
			}
			if (astNode instanceof ExportableElement && astNode.eContainer() instanceof ExportDeclaration) {
				nodes = super.getDocumentationNodes(astNode.eContainer());
			}
		}
		if (nodes.isEmpty()) {
			// failure case, was ASI grabbing the doc?
			// backward search for first non-hidden element, over-stepping if it is a LeafNodeWithSyntaxError from
			// ASI.
			ICompositeNode ptNodeOfASTNode = NodeModelUtils.getNode(astNode);
			LeafNode lNode = searchLeafNodeDocumentation(ptNodeOfASTNode);
			if (lNode != null) {
				return Collections.<INode> singletonList(lNode);
			}
		}
		return nodes;
	}
	return super.getDocumentationNodes(object);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:43,代码来源:N4JSDocumentationProvider.java

示例15: installProxies

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Installs only a proxy for EObjects that have a representation in the Xtext document node model.
 */
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer) {
	ICompositeNode node = NodeModelUtils.getNode(obj);
	if (node == null)
		return;
	installProxies(resource, obj, producer, node, false);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:10,代码来源:N4JSLinker.java


注:本文中的org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。