本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.getReference方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.getReference方法的具体用法?Java GrammarUtil.getReference怎么用?Java GrammarUtil.getReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.getReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveCrossReferencedElement
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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;
}
示例2: resolveCrossReferencedElement
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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;
}
示例3: serializeCrossRef
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public String serializeCrossRef(EObject context, CrossReference grammarElement, final EObject target, INode node) {
final EReference ref = GrammarUtil.getReference(grammarElement, context.eClass());
String text = null;
if (node != null) {
List<EObject> objects = linkingService.getLinkedObjects(context, ref, node);
if (Iterables.any(objects, new Predicate<EObject>() {
private final URI targetURI = EcoreUtil.getURI(target);
@Override
public boolean apply(EObject input) {
return input == target || EcoreUtil.getURI(input).equals(targetURI);
}
}))
return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
}
text = getUnconvertedLinkText(target, ref, context);
if (text != null)
return getConvertedValue(text, grammarElement);
if (node != null) {
return linkingHelper.getCrossRefNodeAsString(node, false);
}
return null;
}
示例4: isValid
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) {
if ((target == null || target.eIsProxy()) && node != null) {
CrossReference crossrefFromNode = GrammarUtil.containingCrossReference(node.getGrammarElement());
return crossref == crossrefFromNode;
}
final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass());
final IScope scope = scopeProvider.getScope(semanticObject, ref);
if (scope == null) {
if (errors != null)
errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target));
return false;
}
if (target != null && target.eIsProxy()) {
target = handleProxy(target, semanticObject, ref);
}
return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors) != null;
}
示例5: testGetReference
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Test
public void testGetReference() throws Exception {
this.with(LangATestLanguageStandaloneSetup.class);
XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
AbstractElement _terminal = asExtends.getTerminal();
CrossReference xref = ((CrossReference) _terminal);
EObject _model = this.getModel(resource);
Main model = ((Main) _model);
EObject typeA = model.getTypes().get(0);
EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
Assert.assertNotNull(ref);
Assert.assertEquals("extends", ref.getName());
Assert.assertFalse(ref.isMany());
Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
示例6: installProxies
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* Installs proxies for all non containment references and only if the node representing the EObject that contains
* the cross reference has got leaf nodes (as a leaf node represents the cross reference).
*
* @param resource
* the N4JSResource
* @param obj
* the EObject containing the cross reference
* @param producer
* the error/warning producer
* @param parentNode
* the node representing obj inside the node model
*/
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer,
ICompositeNode parentNode, boolean dontCheckParent) {
final EClass eClass = obj.eClass();
if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
return;
for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
EObject grammarElement = node.getGrammarElement();
if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
producer.setNode(node);
CrossReference crossReference = (CrossReference) grammarElement;
final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
if (eRef == null) {
ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName()
+ "::" + feature + "' in parser rule '" + parserRule.getName() + "'.");
}
createAndSetProxy(resource, obj, node, eRef, crossReference, producer);
afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
installProxies(resource, obj, producer, (ICompositeNode) node, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent);
}
}
示例7: getCrossReferencesWithSameEReference
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static List<CrossReference> getCrossReferencesWithSameEReference(CrossReference cr) {
Grammar g = GrammarUtil.getGrammar(cr);
EReference ref = GrammarUtil.getReference(cr);
List<CrossReference> result = Lists.newArrayList();
for (CrossReference c : EcoreUtil2.getAllContentsOfType(g, CrossReference.class))
if (GrammarUtil.getReference(c) == ref)
result.add(c);
return result;
}
示例8: equalsOrReplacesNode
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public boolean equalsOrReplacesNode(EObject context, CrossReference crossref, EObject target, INode node) {
if (crossref != node.getGrammarElement())
return false;
EReference ref = GrammarUtil.getReference(crossref);
if (!ref.isMany())
return true;
List<EObject> objects = linkingService.getLinkedObjects(context, ref, node);
return objects.contains(target);
}
示例9: isValid
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public boolean isValid(EObject context, CrossReference crossref, EObject target, IErrorAcceptor errorAcceptor) {
try {
final EReference ref = GrammarUtil.getReference(crossref, context.eClass());
String text = getUnconvertedLinkText(target, ref, context);
if (text == null)
return true; // maybe we'll find something useful in the node model later on?
getConvertedValue(text, crossref);
return true;
} catch (ValueConverterException e) {
if (errorAcceptor != null)
errorAcceptor.error(e.getMessage());
return false;
}
}
示例10: findValidAssignmentsForCrossRef
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected Set<AbstractElement> findValidAssignmentsForCrossRef(EObject semanticObj,
Iterable<AbstractElement> assignedElements, EObject value, INode node) {
Set<AbstractElement> result = Sets.newLinkedHashSet();
for (AbstractElement ass : assignedElements) {
CrossReference crossref = GrammarUtil.containingCrossReference(ass);
EReference eref = GrammarUtil.getReference(crossref, semanticObj.eClass());
if (EcoreUtil2.isAssignableFrom(eref.getEReferenceType(), value.eClass())
&& crossRefSerializer.isValid(semanticObj, crossref, value, node, null))
result.add(ass);
}
return result;
}
示例11: serializeCrossRef
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
Acceptor errors) {
if ((target == null || target.eIsProxy()) && node != null)
return tokenUtil.serializeNode(node);
final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass());
final IScope scope = scopeProvider.getScope(semanticObject, ref);
if (scope == null) {
if (errors != null)
errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target));
return null;
}
if (target != null && target.eIsProxy()) {
target = handleProxy(target, semanticObject, ref);
}
if (target != null && node != null) {
String text = linkingHelper.getCrossRefNodeAsString(node, true);
QualifiedName qn = qualifiedNameConverter.toQualifiedName(text);
URI targetURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(target);
for (IEObjectDescription desc : scope.getElements(qn)) {
if (targetURI.equals(desc.getEObjectURI()))
return tokenUtil.serializeNode(node);
}
}
return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
示例12: getFullReferenceName
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected String getFullReferenceName(EObject semanticObject, CrossReference reference) {
EReference ref = GrammarUtil.getReference(reference);
String clazz = semanticObject.eClass().getName();
if (ref.getEContainingClass() != semanticObject.eClass())
clazz = ref.getEContainingClass().getName() + "(" + clazz + ")";
return clazz + "." + ref.getName();
}
示例13: installProxies
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private void installProxies(EObject obj, IDiagnosticProducer producer,
Multimap<EStructuralFeature.Setting, INode> settingsToLink, ICompositeNode parentNode, boolean dontCheckParent) {
final EClass eClass = obj.eClass();
if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
return;
for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
EObject grammarElement = node.getGrammarElement();
if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
producer.setNode(node);
CrossReference crossReference = (CrossReference) grammarElement;
final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
if (eRef == null) {
ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
throw new IllegalStateException("Couldn't find EReference for crossreference '"+eClass.getName()+"::"+feature+"' in parser rule '"+parserRule.getName()+"'.");
}
if (!eRef.isResolveProxies() /*|| eRef.getEOpposite() != null see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486*/) {
final EStructuralFeature.Setting setting = ((InternalEObject) obj).eSetting(eRef);
settingsToLink.put(new SettingDelegate(setting), node);
} else {
createAndSetProxy(obj, node, eRef);
afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
}
} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
installProxies(obj, producer, settingsToLink, (ICompositeNode) node, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
installProxies(obj, producer, settingsToLink, parentNode.getParent(), dontCheckParent);
}
}
示例14: testGetLinkedObjects
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Test public void testGetLinkedObjects() throws Exception {
XtextResource r = getResourceFromString("type TypeA extends TypeB type TypeB extends TypeA type AnotherType extends TypeA");
Main model = (Main) r.getParseResult().getRootASTElement();
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(r.getParseResult().getRootNode(), 6);
assertEquals(3, model.getTypes().size());
EObject context = model.getTypes().get(0);
Assignment asExtends = get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
CrossReference xref = (CrossReference) asExtends.getTerminal();
EReference ref = GrammarUtil.getReference(xref, context.eClass());
assertEquals(1, getLinkingService().getLinkedObjects(context, ref, leaf).size());
}
示例15: _createProposals
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected void _createProposals(final CrossReference reference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
final EClassifier type = this._currentTypeFinder.findCurrentTypeAfter(reference);
if ((type instanceof EClass)) {
final EReference ereference = GrammarUtil.getReference(reference, ((EClass)type));
final EObject currentModel = context.getCurrentModel();
if (((ereference != null) && (currentModel != null))) {
final IScope scope = this.scopeProvider.getScope(currentModel, ereference);
this.crossrefProposalProvider.lookupCrossReference(scope, reference, context, acceptor,
this.getCrossrefFilter(reference, context));
}
}
}