Search in sources :

Example 16 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class FlattenedGrammarAccess method copyTypeRef.

private TypeRef copyTypeRef(final TypeRef ref) {
    if ((ref == null)) {
        return null;
    }
    final TypeRef copy = this.<TypeRef>copy(ref);
    copy.setClassifier(ref.getClassifier());
    return copy;
}
Also used : TypeRef(org.eclipse.xtext.TypeRef)

Example 17 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class NodeModelSemanticSequencer method createSequence.

@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
    SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
    while (ni.hasNext()) {
        Triple<INode, AbstractElement, EObject> node = ni.next();
        if (node.getSecond() instanceof RuleCall) {
            RuleCall rc = (RuleCall) node.getSecond();
            TypeRef ruleType = rc.getRule().getType();
            if (ruleType == null || ruleType.getClassifier() instanceof EClass)
                acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
            else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
                EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass());
                acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
            } else {
                String strVal = NodeModelUtils.getTokenText(node.getFirst());
                Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst());
                acceptSemantic(semanticObject, rc, val, node.getFirst());
            }
        } else if (node.getSecond() instanceof Keyword)
            acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
        else if (node.getSecond() instanceof Action) {
            acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword) TypeRef(org.eclipse.xtext.TypeRef) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) RuleCall(org.eclipse.xtext.RuleCall) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject)

Example 18 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class TreeConstNFAToDot method newNode.

@Override
protected Node newNode(EObject semanticObject, String label) {
    TreeConstState nfas = nfaProvider.getNFA((AbstractElement) semanticObject);
    List<String> types = Lists.newArrayList();
    for (TypeRef typeRef : nfas.getTypesToCheck()) types.add(typeRef == null ? "null" : typeRef.getClassifier().getName());
    if (semanticObject.eContainer() instanceof AbstractRule) {
        AbstractRule rule = (AbstractRule) semanticObject.eContainer();
        String typesAsString = types.isEmpty() ? "" : " [" + Joiner.on(",").join(types) + "]";
        return new Node(semanticObject, rule.getName() + typesAsString + ":\\n" + label, "record");
    } else {
        String typesAsString = types.isEmpty() ? "" : "[" + Joiner.on(",").join(types) + "]\\n";
        return new Node(semanticObject, typesAsString + label);
    }
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 19 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class Xtext2EcoreTransformer method getOrComputeReturnType.

private TypeRef getOrComputeReturnType(AbstractRule rule) {
    TypeRef result = rule.getType();
    if (result == null) {
        EClassifier classifier = getClassifierFor(rule);
        if (classifier == null) {
            if (rule.getName() == null)
                return null;
            result = getTypeRef(rule.getName());
        } else
            result = getTypeRef(classifier);
        if (result.getMetamodel() == null) {
            AbstractMetamodelDeclaration bestMatch = null;
            for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
                if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
                    bestMatch = decl;
                    break;
                }
            }
            if (result.getMetamodel() == null)
                result.setMetamodel(bestMatch);
        }
        rule.setType(result);
    }
    return result;
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) TypeRef(org.eclipse.xtext.TypeRef) EClassifier(org.eclipse.emf.ecore.EClassifier) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration)

Example 20 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class Xtext2EcoreTransformer method getTypeRef.

TypeRef getTypeRef(EClassifier classifier) {
    TypeRef result = XtextFactory.eINSTANCE.createTypeRef();
    result.setClassifier(classifier);
    EPackage pack = classifier.getEPackage();
    for (AbstractMetamodelDeclaration decl : GrammarUtil.allMetamodelDeclarations(grammar)) {
        if (pack.equals(decl.getEPackage())) {
            result.setMetamodel(decl);
            return result;
        }
    }
    return result;
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

TypeRef (org.eclipse.xtext.TypeRef)27 RuleCall (org.eclipse.xtext.RuleCall)13 ParserRule (org.eclipse.xtext.ParserRule)11 Test (org.junit.Test)9 AbstractRule (org.eclipse.xtext.AbstractRule)8 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 CrossReference (org.eclipse.xtext.CrossReference)7 Action (org.eclipse.xtext.Action)5 EObject (org.eclipse.emf.ecore.EObject)4 Assignment (org.eclipse.xtext.Assignment)4 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 EnumRule (org.eclipse.xtext.EnumRule)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 EClassifier (org.eclipse.emf.ecore.EClassifier)3 EPackage (org.eclipse.emf.ecore.EPackage)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 Keyword (org.eclipse.xtext.Keyword)3 NamedArgument (org.eclipse.xtext.NamedArgument)3 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)3 TerminalRule (org.eclipse.xtext.TerminalRule)3