Search in sources :

Example 91 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class FollowElementComputer method collectAbstractElements.

public void collectAbstractElements(Grammar grammar, EStructuralFeature feature, IFollowElementAcceptor followElementAcceptor) {
    for (Grammar superGrammar : grammar.getUsedGrammars()) {
        collectAbstractElements(superGrammar, feature, followElementAcceptor);
    }
    EClass declarator = feature.getEContainingClass();
    for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
        for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
            if (assignment.getFeature().equals(feature.getName())) {
                EClassifier classifier = GrammarUtil.findCurrentType(assignment);
                EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
                if (compType == declarator) {
                    followElementAcceptor.accept(assignment);
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.xtext.Assignment) ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) EClassifier(org.eclipse.emf.ecore.EClassifier) Grammar(org.eclipse.xtext.Grammar)

Example 92 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class IdeContentProposalProvider method _createProposals.

protected void _createProposals(CrossReference reference, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
    EClassifier type = currentTypeFinder.findCurrentTypeAfter(reference);
    if (type instanceof EClass) {
        EReference eReference = GrammarUtil.getReference(reference, ((EClass) type));
        EObject currentModel = context.getCurrentModel();
        if (eReference != null && currentModel != null) {
            IScope scope = scopeProvider.getScope(currentModel, eReference);
            crossrefProposalProvider.lookupCrossReference(scope, reference, context, acceptor, getCrossrefFilter(reference, context));
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EClassifier(org.eclipse.emf.ecore.EClassifier) IScope(org.eclipse.xtext.scoping.IScope) EReference(org.eclipse.emf.ecore.EReference)

Example 93 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class Formatter2Fragment2 method getLocallyAssignedContainmentReferences.

protected void getLocallyAssignedContainmentReferences(final Grammar grammar, final Multimap<EClass, EReference> type2ref) {
    List<Assignment> _containedAssignments = GrammarUtil.containedAssignments(grammar);
    for (final Assignment assignment : _containedAssignments) {
        {
            final EClassifier type = GrammarUtil.findCurrentType(assignment);
            if ((type instanceof EClass)) {
                final EStructuralFeature feature = ((EClass) type).getEStructuralFeature(assignment.getFeature());
                if (((feature instanceof EReference) && ((EReference) feature).isContainment())) {
                    type2ref.put(((EClass) type), ((EReference) feature));
                }
            }
        }
    }
    List<Action> _containedActions = GrammarUtil.containedActions(grammar);
    for (final Action action : _containedActions) {
        {
            final String featureName = action.getFeature();
            if ((featureName != null)) {
                final EClassifier type = action.getType().getClassifier();
                if ((type instanceof EClass)) {
                    final EStructuralFeature feature = ((EClass) type).getEStructuralFeature(featureName);
                    if (((feature instanceof EReference) && ((EReference) feature).isContainment())) {
                        type2ref.put(((EClass) type), ((EReference) feature));
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.xtext.Assignment) EClass(org.eclipse.emf.ecore.EClass) Action(org.eclipse.xtext.Action) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference)

Example 94 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class EMFGeneratorFragment2 method putMappingData.

private void putMappingData(final Map<EObject, EObject> result, final EPackage usedEPackage, final EPackage loadedEPackage) {
    if (((loadedEPackage != null) && (!Objects.equal(usedEPackage, loadedEPackage)))) {
        result.put(usedEPackage, loadedEPackage);
        EList<EClassifier> _eClassifiers = usedEPackage.getEClassifiers();
        for (final EClassifier usedClassifier : _eClassifiers) {
            {
                final EClassifier loadedClassifier = loadedEPackage.getEClassifier(usedClassifier.getName());
                if ((loadedClassifier == null)) {
                    String _name = usedClassifier.getName();
                    String _plus = ("Cannot find classifier \'" + _name);
                    String _plus_1 = (_plus + "\' in loaded EPackage from ");
                    URI _uRI = loadedEPackage.eResource().getURI();
                    String _plus_2 = (_plus_1 + _uRI);
                    throw new RuntimeException(_plus_2);
                }
                result.put(usedClassifier, loadedClassifier);
            }
        }
        EList<EPackage> _eSubpackages = usedEPackage.getESubpackages();
        for (final EPackage usedNestedPackage : _eSubpackages) {
            {
                final Function1<EPackage, Boolean> _function = (EPackage it) -> {
                    String _name = it.getName();
                    String _name_1 = usedNestedPackage.getName();
                    return Boolean.valueOf(Objects.equal(_name, _name_1));
                };
                final EPackage loadedNestedPackage = IterableExtensions.<EPackage>findFirst(loadedEPackage.getESubpackages(), _function);
                if ((loadedNestedPackage != null)) {
                    this.putMappingData(result, usedNestedPackage, loadedNestedPackage);
                }
            }
        }
    }
}
Also used : Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) EClassifier(org.eclipse.emf.ecore.EClassifier) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage)

Example 95 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class ResourceDescriptionStrategyFragment method generateResourceDescriptionStrategy.

protected JavaFileAccess generateResourceDescriptionStrategy(final Iterable<AbstractRule> exportedRules) {
    TypeReference _abstractResourceDescriptionStrategyClass = this.getAbstractResourceDescriptionStrategyClass();
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = ResourceDescriptionStrategyFragment.this.getSuperTypeRef().getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _resourceDescriptionSuperClass = ResourceDescriptionStrategyFragment.this.getResourceDescriptionSuperClass();
            _builder.append(_resourceDescriptionSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("public boolean createEObjectDescriptions(");
            _builder.append(EObject.class, "\t");
            _builder.append(" eObject, ");
            _builder.append(IAcceptor.class, "\t");
            _builder.append("<");
            _builder.append(IEObjectDescription.class, "\t");
            _builder.append("> acceptor) {");
            _builder.newLineIfNotEmpty();
            {
                for (final AbstractRule exportedRule : exportedRules) {
                    _builder.append("\t\t");
                    _builder.append("if(eObject instanceof ");
                    EClassifier _classifier = exportedRule.getType().getClassifier();
                    ResourceSet _resourceSet = ResourceDescriptionStrategyFragment.this.getGrammar().eResource().getResourceSet();
                    TypeReference _typeReference = new TypeReference(((EClass) _classifier), _resourceSet);
                    _builder.append(_typeReference, "\t\t");
                    _builder.append(") {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("return createEObjectDescriptionsFor");
                    String _name = exportedRule.getType().getClassifier().getName();
                    _builder.append(_name, "\t\t\t");
                    _builder.append("(eObject, acceptor);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            {
                boolean _needsToInvokeSuperResourceDescriptionStrategy = ResourceDescriptionStrategyFragment.this.needsToInvokeSuperResourceDescriptionStrategy();
                if (_needsToInvokeSuperResourceDescriptionStrategy) {
                    _builder.append("\t\t");
                    _builder.append("return super.createEObjectDescriptions(eObject, acceptor);");
                    _builder.newLine();
                } else {
                    _builder.append("\t\t");
                    _builder.append("return true;");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            {
                for (final AbstractRule exportedRule_1 : exportedRules) {
                    _builder.append("\t");
                    _builder.append("protected boolean createEObjectDescriptionsFor");
                    String _name_1 = exportedRule_1.getType().getClassifier().getName();
                    _builder.append(_name_1, "\t");
                    _builder.append("(");
                    _builder.append(EObject.class, "\t");
                    _builder.append(" eObject, ");
                    _builder.append(IAcceptor.class, "\t");
                    _builder.append("<");
                    _builder.append(IEObjectDescription.class, "\t");
                    _builder.append("> acceptor) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return super.createEObjectDescriptions(eObject, acceptor);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_abstractResourceDescriptionStrategyClass, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EObject(org.eclipse.emf.ecore.EObject) IAcceptor(org.eclipse.xtext.util.IAcceptor) EClassifier(org.eclipse.emf.ecore.EClassifier) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractRule(org.eclipse.xtext.AbstractRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5