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


Java NodeModelUtils.findActualSemanticObjectFor方法代码示例

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


在下文中一共展示了NodeModelUtils.findActualSemanticObjectFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkNoJavaStyleTypeCasting

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected void checkNoJavaStyleTypeCasting(INode node) {
	BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
	ILeafNode child = getFirstLeafNode(iterator);
	if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
		INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
		EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
		if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
			XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
			if (featureCall.isTypeLiteral()) {
				ICompositeNode parenthesizedNode = child.getParent();
				ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
				addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseValidator.java

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

示例3: internalResolveElementAt

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected EObject internalResolveElementAt(XtextResource resource, int offset, boolean containment) {
	if(!containment) {
		EObject crossRef = resolveCrossReferencedElementAt(resource, offset);
		if (crossRef != null)
			return crossRef;
	}
	IParseResult parseResult = resource.getParseResult();
	if (parseResult != null) {
		ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
		if (leaf != null && leaf.isHidden() && leaf.getOffset() == offset) {
			leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1);
		}
		if (leaf != null) {
			return NodeModelUtils.findActualSemanticObjectFor(leaf);
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:EObjectAtOffsetHelper.java

示例4: resolveCrossReferencedElement

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
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()) {
			return (EObject) referenceOwner.eGet(crossReference);
		} else {
			List<?> listValue = (List<?>) referenceOwner.eGet(crossReference);
			List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(referenceOwner, crossReference);
			int currentIndex = 0;
			for (INode nodeForFeature : nodesForFeature) {
				if (currentIndex >= listValue.size())
					return null;
				if (nodeForFeature.getTotalOffset() <= node.getTotalOffset()
						&& nodeForFeature.getTotalEndOffset() >= node.getTotalEndOffset())
					return (EObject) listValue.get(currentIndex);
				currentIndex++;
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:EObjectAtOffsetHelper.java

示例5: format

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public IFormattedRegion format(ICompositeNode root, int offset, int length) {
	String indent = getIndentation(root, offset);
	TokenStringBuffer buf = new TokenStringBuffer();
	ITokenStream out = offset == 0 ? buf : new FilterFirstWhitespaceStream(buf);
	ITokenStream fmt;
	if (formatter instanceof IFormatterExtension) {
		EObject semanticElement = NodeModelUtils.findActualSemanticObjectFor(root);
		if (semanticElement != null)
			fmt = ((IFormatterExtension) formatter).createFormatterStream(semanticElement, indent, out, false);
		else {
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=380406
			ITextRegion rootRegion = root.getTextRegion();
			return new FormattedRegion(rootRegion.getOffset(), rootRegion.getLength(), root.getText());
		}
	} else
		fmt = formatter.createFormatterStream(indent, out, false);
	try {
		ITextRegion range = nodeModelStreamer.feedTokenStream(fmt, root, offset, length);
		return new FormattedRegion(range.getOffset(), range.getLength(), buf.toString());
	} catch (IOException e) {
		// this should never happen since TokenStringBuffer doesn't throw IOEs.
		throw new RuntimeException(e);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:DefaultNodeModelFormatter.java

示例6: getSelectedElementType

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Gets the EClass of the semantic element currently selected.
 *
 * @return EClass or null
 */
public EClass getSelectedElementType() {
  if (selection instanceof IStructuredSelection) {
    if (((IStructuredSelection) selection).getFirstElement() instanceof EObject) {
      // structured selection, e.g. GMFEditor
      EObject eObject = (EObject) ((IStructuredSelection) selection).getFirstElement();
      if (eObject.eResource() != null) {
        return eObject.eClass();
      }
    } else if (((IStructuredSelection) selection).getFirstElement() instanceof EObjectNode) {
      // selection in outline
      return ((EObjectNode) ((IStructuredSelection) selection).getFirstElement()).getEClass();
    }
  } else {
    ILeafNode node = nodeAtTextSelection();
    EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (semanticObject != null) {
      return semanticObject.eClass();
    }
  }
  return null;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:XtextElementSelectionListener.java

示例7: getSelectedElementUri

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Gets the URI of the semantic element currently selected.
 *
 * @return URI or null
 */
public URI getSelectedElementUri() {
  if (selection instanceof IStructuredSelection) {
    if (((IStructuredSelection) selection).getFirstElement() instanceof InternalEObject) {
      // structured selection, e.g. GMFEditor
      return EcoreUtil.getURI((EObject) ((IStructuredSelection) selection).getFirstElement());
    } else if (((IStructuredSelection) selection).getFirstElement() instanceof EObjectNode) {
      // selection in outline
      return ((EObjectNode) ((IStructuredSelection) selection).getFirstElement()).getEObjectURI();
    }
  } else {
    ILeafNode node = nodeAtTextSelection();
    EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (semanticObject != null) {
      return EcoreUtil.getURI(semanticObject);
    }
  }
  return null;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:24,代码来源:XtextElementSelectionListener.java

示例8: IEObjectCoveringRegion

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/***/
@Creates
public IEObjectCoveringRegion IEObjectCoveringRegion() {
	final boolean haveRegion = region != null;

	int offset = haveRegion ? region.getOffset() : this.matchedOffset;
	int length = haveRegion ? region.getLength() : 0;
	int endOffset = offset + length;
	EObject semanticObject = null;

	INode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
	while (node != null) {
		EObject actualObject = NodeModelUtils.findActualSemanticObjectFor(node);
		if (actualObject != null) {
			if (haveRegion) {
				int nodeEndOffset = node.getEndOffset();
				if (nodeEndOffset <= endOffset || semanticObject == null) {
					semanticObject = actualObject;
				}
				if (nodeEndOffset >= endOffset) {
					break;
				}
			} else { // no region given, just a matched offset
				if (semanticObject == null) {
					semanticObject = actualObject;
					break;
				}
			}
		}
		node = node.getParent();
	}
	return new EObjectCoveringRegion(semanticObject, offset);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:34,代码来源:N4JSOffsetAdapter.java

示例9: addJavaDocImports

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public void addJavaDocImports(final EObject it, final ITreeAppendable appendable, final List<INode> documentationNodes) {
  for (final INode node : documentationNodes) {
    List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(node);
    for (final ReplaceRegion region : _computeTypeRefRegions) {
      {
        final String text = region.getText();
        if (((text != null) && (text.length() > 0))) {
          final QualifiedName fqn = this.qualifiedNameConverter.toQualifiedName(text);
          final EObject context = NodeModelUtils.findActualSemanticObjectFor(node);
          if (((fqn.getSegmentCount() == 1) && (context != null))) {
            final IScope scope = this.scopeProvider.getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
            final IEObjectDescription candidate = scope.getSingleElement(fqn);
            if ((candidate != null)) {
              EObject _xifexpression = null;
              boolean _eIsProxy = candidate.getEObjectOrProxy().eIsProxy();
              if (_eIsProxy) {
                _xifexpression = EcoreUtil.resolve(candidate.getEObjectOrProxy(), context);
              } else {
                _xifexpression = candidate.getEObjectOrProxy();
              }
              final JvmType jvmType = ((JvmType) _xifexpression);
              if (((jvmType instanceof JvmDeclaredType) && (!jvmType.eIsProxy()))) {
                final JvmDeclaredType referencedType = ((JvmDeclaredType) jvmType);
                final JvmDeclaredType contextDeclarator = EcoreUtil2.<JvmDeclaredType>getContainerOfType(it, JvmDeclaredType.class);
                String _packageName = referencedType.getPackageName();
                String _packageName_1 = contextDeclarator.getPackageName();
                boolean _notEquals = (!Objects.equal(_packageName, _packageName_1));
                if (_notEquals) {
                  final ImportManager importManager = this.getImportManager(appendable);
                  importManager.addImportFor(jvmType);
                }
              }
            }
          }
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:JvmModelGenerator.java

示例10: addJavaDocReferences

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private void addJavaDocReferences(final INode documentationNode, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) {
  List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(documentationNode);
  for (final ReplaceRegion docTypeReference : _computeTypeRefRegions) {
    {
      int _offset = docTypeReference.getOffset();
      int _length = docTypeReference.getLength();
      final TextRegion referenceRange = new TextRegion(_offset, _length);
      boolean _contains = selectedRegion.contains(referenceRange);
      if (_contains) {
        String docTypeText = docTypeReference.getText();
        final EObject element = NodeModelUtils.findActualSemanticObjectFor(documentationNode);
        IScope scope = this.scopeProvider.getScope(element, 
          TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        IEObjectDescription singleElement = scope.getSingleElement(QualifiedName.create(docTypeText));
        JvmType referencedType = null;
        if ((singleElement != null)) {
          EObject _eObjectOrProxy = singleElement.getEObjectOrProxy();
          referencedType = ((JvmType) _eObjectOrProxy);
        }
        if (((referencedType instanceof JvmDeclaredType) && (!referencedType.eIsProxy()))) {
          JvmDeclaredType casted = ((JvmDeclaredType) referencedType);
          boolean _equals = casted.getQualifiedName().equals(docTypeText);
          boolean _not = (!_equals);
          if (_not) {
            acceptor.acceptTypeImport(casted);
          }
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:32,代码来源:ImportsCollector.java

示例11: testFindActualSemanticObjectFor

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testFindActualSemanticObjectFor() throws Exception {
	String modelAsString = "actions attribute ref attr1 attr2;";
	int idx = modelAsString.indexOf("attr1");
	Model model = (Model) getModelAndExpect(modelAsString, 1); /* linking issue */
	INode root = NodeModelUtils.getNode(model).getRootNode();
	ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(root, idx);
	assertEquals("attr1", leafNodeAtOffset.getText());
	
	EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(leafNodeAtOffset);
	assertSame(model.getAttributes().get(0), semanticObject);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:Bug407280Test.java

示例12: testFragmentRecursive_01

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test
public void testFragmentRecursive_01() {
  final ParserRuleFragments fragments = this.parseAndValidate("#10 myName myPrev");
  Assert.assertNotNull(fragments);
  Assert.assertEquals("myName", fragments.getElement().getName());
  PRFNamed _element = fragments.getElement();
  final PRFNamed prev = ((PRFNamedWithAction) _element).getPrev();
  Assert.assertEquals("myPrev", prev.getName());
  final ICompositeNode node = NodeModelUtils.findActualNodeFor(prev);
  Assert.assertEquals(" myPrev", node.getText());
  final EObject lookup = NodeModelUtils.findActualSemanticObjectFor(node);
  Assert.assertSame(prev, lookup);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:AbstractFragmentsTest.java

示例13: testFragmentRecursive_02

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test
public void testFragmentRecursive_02() {
  final ParserRuleFragments fragments = this.parseAndValidate("#10 myName ((myPrev))");
  Assert.assertNotNull(fragments);
  Assert.assertEquals("myName", fragments.getElement().getName());
  PRFNamed _element = fragments.getElement();
  final PRFNamed prev = ((PRFNamedWithAction) _element).getPrev();
  Assert.assertEquals("myPrev", prev.getName());
  final ICompositeNode node = NodeModelUtils.findActualNodeFor(prev);
  Assert.assertEquals(" ((myPrev))", node.getText());
  final EObject lookup = NodeModelUtils.findActualSemanticObjectFor(node);
  Assert.assertSame(prev, lookup);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:AbstractFragmentsTest.java

示例14: testFragmentRecursive_03

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test
public void testFragmentRecursive_03() {
  final ParserRuleFragments fragments = this.parseAndValidate("#11 myName myPrev");
  Assert.assertNotNull(fragments);
  Assert.assertEquals("myName", fragments.getElement().getName());
  PRFNamed _element = fragments.getElement();
  final PRFNamed prev = ((PRFNamedWithAction) _element).getPrev();
  Assert.assertEquals("myPrev", prev.getName());
  final ICompositeNode node = NodeModelUtils.findActualNodeFor(prev);
  Assert.assertEquals(" myPrev", node.getText());
  final EObject lookup = NodeModelUtils.findActualSemanticObjectFor(node);
  Assert.assertSame(prev, lookup);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:AbstractFragmentsTest.java

示例15: testFragmentRecursive_04

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test
public void testFragmentRecursive_04() {
  final ParserRuleFragments fragments = this.parseAndValidate("#11 myName ((myPrev))");
  Assert.assertNotNull(fragments);
  Assert.assertEquals("myName", fragments.getElement().getName());
  PRFNamed _element = fragments.getElement();
  final PRFNamed prev = ((PRFNamedWithAction) _element).getPrev();
  Assert.assertEquals("myPrev", prev.getName());
  final ICompositeNode node = NodeModelUtils.findActualNodeFor(prev);
  Assert.assertEquals("myPrev", node.getText());
  final EObject lookup = NodeModelUtils.findActualSemanticObjectFor(node);
  Assert.assertSame(prev, lookup);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:AbstractFragmentsTest.java


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