Search in sources :

Example 1 with GeneratedMetamodel

use of org.eclipse.xtext.GeneratedMetamodel in project xtext-eclipse by eclipse.

the class XtextHyperlinkHelper method acceptHyperLink.

protected boolean acceptHyperLink(XtextResource resource, EObject objectAtOffset) {
    if (objectAtOffset instanceof EClass) {
        EClass eClass = (EClass) objectAtOffset;
        Grammar grammar = GrammarUtil.getGrammar(resource.getEObject("/"));
        List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar);
        for (GeneratedMetamodel generatedMetamodel : Iterables.filter(allMetamodelDeclarations, GeneratedMetamodel.class)) {
            if (eClass.getEPackage().equals(generatedMetamodel.getEPackage())) {
                return false;
            }
        }
    }
    return true;
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EClass(org.eclipse.emf.ecore.EClass) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration)

Example 2 with GeneratedMetamodel

use of org.eclipse.xtext.GeneratedMetamodel in project xtext-eclipse by eclipse.

the class XtextProposalProvider method completeGeneratedMetamodel_Alias.

@Override
public void completeGeneratedMetamodel_Alias(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model instanceof GeneratedMetamodel) {
        EPackage ePackage = ((GeneratedMetamodel) model).getEPackage();
        String name = ((GeneratedMetamodel) model).getName();
        createAliasProposal(context, acceptor, ePackage, name);
    }
    super.completeGeneratedMetamodel_Alias(model, assignment, context, acceptor);
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) StyledString(org.eclipse.jface.viewers.StyledString) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with GeneratedMetamodel

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

the class XtextLinker method createDiagnosticProducer.

@Override
protected IDiagnosticProducer createDiagnosticProducer(final IDiagnosticConsumer consumer) {
    return new AbstractDiagnosticProducerDecorator(super.createDiagnosticProducer(consumer)) {

        private boolean filter = false;

        @Override
        public void addDiagnostic(DiagnosticMessage message) {
            if (!filter)
                super.addDiagnostic(message);
        }

        @Override
        public void setTarget(EObject object, EStructuralFeature feature) {
            super.setTarget(object, feature);
            // we don't want to mark generated types as errors unless generation fails
            filter = isTypeRef(object, feature) || isGeneratedPackage(object, feature) || isEnumLiteral(object, feature);
        }

        private boolean isEnumLiteral(EObject object, EStructuralFeature feature) {
            if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_EnumLiteral()) {
                EnumRule rule = GrammarUtil.containingEnumRule(object);
                return rule.getType() == null || rule.getType().getClassifier() == null;
            }
            return false;
        }

        private boolean isGeneratedPackage(EObject object, EStructuralFeature feature) {
            return (feature == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage() && (object instanceof GeneratedMetamodel));
        }

        private boolean isTypeRef(EObject object, EStructuralFeature feature) {
            return (feature == XtextPackage.eINSTANCE.getTypeRef_Classifier() && ((TypeRef) object).getMetamodel() instanceof GeneratedMetamodel);
        }
    };
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) AbstractDiagnosticProducerDecorator(org.eclipse.xtext.diagnostics.AbstractDiagnosticProducerDecorator) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 4 with GeneratedMetamodel

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

the class XtextValidator method checkGeneratedEnumIsValid.

@Check
public void checkGeneratedEnumIsValid(EnumLiteralDeclaration decl) {
    EnumRule rule = GrammarUtil.containingEnumRule(decl);
    if (!(rule.getType().getMetamodel() instanceof GeneratedMetamodel))
        return;
    if (!(rule.getType().getClassifier() instanceof EEnum))
        return;
    EEnum eEnum = (EEnum) rule.getType().getClassifier();
    List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
    if (declarations.size() == eEnum.getELiterals().size())
        return;
    for (EnumLiteralDeclaration otherDecl : declarations) {
        if (decl == otherDecl) {
            return;
        }
        if (otherDecl.getEnumLiteral() == decl.getEnumLiteral()) {
            if (!decl.getEnumLiteral().getLiteral().equals(decl.getLiteral().getValue()))
                addIssue("Enum literal '" + decl.getEnumLiteral().getName() + "' has already been defined with literal '" + decl.getEnumLiteral().getLiteral() + "'.", decl, XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL, DUPLICATE_ENUM_LITERAL);
            return;
        }
    }
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) EEnum(org.eclipse.emf.ecore.EEnum) Check(org.eclipse.xtext.validation.Check)

Example 5 with GeneratedMetamodel

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

the class Xtext2EcoreTransformerTest method testBug296496_02.

@Test
public void testBug296496_02() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("import \"classpath:/org/eclipse/xtext/enumrules/enums.ecore\"");
    _builder.newLine();
    _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\"");
    _builder.newLine();
    _builder.append("CreatedType:");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("enumFeature=ExistingEnum otherEnumFeature=ExistingEnum;");
    _builder.newLine();
    _builder.append("enum ExistingEnum:");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("SameName | OverriddenLiteral = \"overridden\" | DifferentName;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    final XtextResource resource = this.getResourceFromStringAndExpect(grammarAsString, 0);
    Assert.assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final Grammar grammar = ((Grammar) _head);
    AbstractMetamodelDeclaration _get = grammar.getMetamodelDeclarations().get(1);
    GeneratedMetamodel generatedMetamodel = ((GeneratedMetamodel) _get);
    Assert.assertEquals("myDsl", generatedMetamodel.getName());
    EClassifier _type = this.<EClassifier>type(generatedMetamodel.getEPackage(), "CreatedType");
    EClass createdType = ((EClass) _type);
    Assert.assertEquals(this.<EStructuralFeature>feature(createdType, "enumFeature").getEType(), this.<EStructuralFeature>feature(createdType, "otherEnumFeature").getEType());
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) Test(org.junit.Test)

Aggregations

GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)18 Grammar (org.eclipse.xtext.Grammar)9 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 EObject (org.eclipse.emf.ecore.EObject)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 EPackage (org.eclipse.emf.ecore.EPackage)5 EClass (org.eclipse.emf.ecore.EClass)4 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)4 Test (org.junit.Test)4 EClassifier (org.eclipse.emf.ecore.EClassifier)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 EnumRule (org.eclipse.xtext.EnumRule)3 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)3 TypeRef (org.eclipse.xtext.TypeRef)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 StyledString (org.eclipse.jface.viewers.StyledString)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)2 ArrayList (java.util.ArrayList)1