Search in sources :

Example 6 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-xtend by eclipse.

the class XtendImportedNamespaceScopeProvider method getScope.

@Override
public IScope getScope(final EObject context, final EReference reference) {
    EClass referenceType = reference.getEReferenceType();
    if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(referenceType)) {
        if (context instanceof XImportDeclaration) {
            Resource resource = context.eResource();
            IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
            AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
            IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
            IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
            if (resourceDescription != null) {
                typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
            }
            RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
            // TODO this scope doesn't support binary syntax for inner types. It should be a KnownTypes scope which doesn't allow simple names
            // Unfortunately I cannot use a RecordingTypeScope as a parent as it is not compatible...
            IScope scope = SelectableBasedScope.createScope(recordingTypeScope, getAllDescriptions(resource), reference.getEReferenceType(), false);
            return scope;
        }
        final XtendFile xtendFile = getXtendFile(context);
        final Resource resource = xtendFile.eResource();
        AbstractScope result = resourceScopeCache.get("type.scope", xtendFile.eResource(), new Provider<AbstractScope>() {

            @Override
            public AbstractScope get() {
                IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
                AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
                IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
                IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
                if (resourceDescription != null) {
                    typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
                }
                RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
                AbstractScope rootTypeScope = getRootTypeScope(xtendFile, recordingTypeScope);
                AbstractScope importScope = getImportScope(xtendFile.getImportSection(), rootTypeScope, recordingTypeScope);
                AbstractScope localTypes = getResourceTypeScope(xtendFile.eResource(), xtendFile.getPackage(), importScope);
                AbstractScope primitiveAware = new PrimitiveAwareScope(localTypes, typeScope);
                AbstractScope caching = new CachingTypeScope(primitiveAware);
                return caching;
            }
        });
        if (context instanceof AnonymousClass) {
            // necessary for the super type of an anonymous class expression
            JvmDeclaredType inferredAnonymousType = associations.getInferredType((AnonymousClass) context);
            if (inferredAnonymousType != null)
                result = new LocalTypeScope(singletonList(inferredAnonymousType), result);
        }
        XtendMember syntacticContainer = EcoreUtil2.getContainerOfType(context, XtendMember.class);
        if (syntacticContainer != null) {
            result = getContainerScope(syntacticContainer, result);
        }
        EObject logicalContainer = logicalContainerProvider.getNearestLogicalContainer(context);
        if (logicalContainer != null) {
            List<List<JvmTypeParameter>> typeParameters = new ArrayList<List<JvmTypeParameter>>();
            while (logicalContainer instanceof JvmTypeParameterDeclarator) {
                JvmTypeParameterDeclarator typeParamProvider = (JvmTypeParameterDeclarator) logicalContainer;
                if (!typeParamProvider.getTypeParameters().isEmpty()) {
                    typeParameters.add(typeParamProvider.getTypeParameters());
                }
                logicalContainer = logicalContainer.eContainer();
            }
            if (!typeParameters.isEmpty())
                result = new TypeParameterScope(typeParameters, result);
        }
        return result;
    } else if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(referenceType)) {
        IScope typeScope = getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        // this is not called from the type resolution where we want to allow constructors to link to interfaces
        // in order to improve the error message, therefore we use a strict wrapper here
        IScope result = new ConstructorTypeScopeWrapper(context, IVisibilityHelper.ALL, typeScope, true);
        return result;
    } else {
        throw new IllegalArgumentException("Unexpected global request for " + reference);
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeParameterDeclarator(org.eclipse.xtext.common.types.JvmTypeParameterDeclarator) AbstractTypeScope(org.eclipse.xtext.common.types.xtext.AbstractTypeScope) ArrayList(java.util.ArrayList) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) EClass(org.eclipse.emf.ecore.EClass) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Resource(org.eclipse.emf.ecore.resource.Resource) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ConstructorTypeScopeWrapper(org.eclipse.xtext.xbase.scoping.batch.ConstructorTypeScopeWrapper)

Example 7 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-xtend by eclipse.

the class XtendJdtRenameParticipantProcessor method isXtendRename.

/**
 * @return true, if the triggering refactoring targets an Xtend element.
 */
protected boolean isXtendRename() {
    JdtRenameParticipant jdtRenameParticipant = ((JvmModelJdtRenameParticipantContext) getRenameElementContext()).getJdtRenameParticipant();
    RefactoringProcessor triggeringProcessor = jdtRenameParticipant.getProcessor().getRefactoring().getProcessor();
    if (triggeringProcessor instanceof RenameElementProcessor) {
        EClass targetElementEClass = ((RenameElementProcessor) triggeringProcessor).getRenameElementContext().getTargetElementEClass();
        return targetElementEClass.getEPackage() == XtendPackage.eINSTANCE;
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JdtRenameParticipant(org.eclipse.xtext.common.types.ui.refactoring.participant.JdtRenameParticipant) JvmModelJdtRenameParticipantContext(org.eclipse.xtext.xbase.ui.jvmmodel.refactoring.JvmModelJdtRenameParticipantContext) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) RenameElementProcessor(org.eclipse.xtext.ui.refactoring.impl.RenameElementProcessor)

Example 8 with EClass

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

the class PartialSerializationTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == EcorePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case EcorePackage.ECLASS:
                sequence_EClassDecl(context, (EClass) semanticObject);
                return;
        }
    else if (epackage == PartialSerializationTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case PartialSerializationTestLanguagePackage.ECLASS_REF:
                sequence_EClassRef(context, (EClassRef) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_CHILD:
                sequence_MandatoryChild(context, (MandatoryChild) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_CHILD_LIST:
                sequence_MandatoryChildList(context, (MandatoryChildList) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_VALUE:
                sequence_MandatoryValue(context, (MandatoryValue) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANY_MANDATORY_VALUES:
                sequence_ManyMandatoryValues(context, (ManyMandatoryValues) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANY_VALUES:
                sequence_ManyOptionalValues(context, (ManyValues) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD:
                sequence_OptionalChild(context, (OptionalChild) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD_LIST:
                sequence_OptionalChildList(context, (OptionalChildList) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_VALUE:
                sequence_OptionalValue(context, (OptionalValue) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) EClass(org.eclipse.emf.ecore.EClass) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 9 with EClass

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

the class NamesAreUniqueValidationHelper method checkUniqueNames.

/**
 * <p>
 * {@inheritDoc}
 * </p>
 * The cancel indicator will be queried everytime a description has been processed.
 * It should provide a fast answer about its canceled state.
 */
@Override
public void checkUniqueNames(Iterable<IEObjectDescription> descriptions, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor) {
    Iterator<IEObjectDescription> iter = descriptions.iterator();
    if (!iter.hasNext())
        return;
    Map<EClass, Map<QualifiedName, IEObjectDescription>> clusterToNames = Maps.newHashMap();
    while (iter.hasNext()) {
        IEObjectDescription description = iter.next();
        checkDescriptionForDuplicatedName(description, clusterToNames, acceptor);
        operationCanceledManager.checkCanceled(cancelIndicator);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Map(java.util.Map) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 10 with EClass

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

the class ConcreteSyntaxConstraintProvider method getConstraints.

@Override
public Collection<ISyntaxConstraint> getConstraints(EClass cls) {
    List<ISyntaxConstraint> eles = type2Elements.get(cls);
    if (eles != null)
        return eles;
    eles = Lists.newArrayList();
    for (ParserRule r : getValidRules()) {
        if (((EClass) r.getType().getClassifier()).isSuperTypeOf(cls)) {
            ISyntaxConstraint e = getConstraint(r);
            if (e != null)
                eles.add(e);
            else {
                eles.clear();
                break;
            }
        }
    }
    type2Elements.put(cls, eles);
    return eles;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)205 Test (org.junit.Test)99 EPackage (org.eclipse.emf.ecore.EPackage)70 EClassifier (org.eclipse.emf.ecore.EClassifier)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)43 EObject (org.eclipse.emf.ecore.EObject)35 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)27 Resource (org.eclipse.emf.ecore.resource.Resource)23 EReference (org.eclipse.emf.ecore.EReference)22 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)16 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)13 ParserRule (org.eclipse.xtext.ParserRule)12 QualifiedName (org.eclipse.xtext.naming.QualifiedName)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)11 IScope (org.eclipse.xtext.scoping.IScope)11 ArrayList (java.util.ArrayList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 List (java.util.List)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9