Search in sources :

Example 41 with Resource

use of org.eclipse.emf.ecore.resource.Resource 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 42 with Resource

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

the class MutableJvmTypeParameterDeclarationImpl method remove.

@Override
public void remove() {
    this.checkMutable();
    Resource _eResource = this.getDelegate().eResource();
    boolean _tripleNotEquals = (_eResource != null);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("This element has already been removed: ");
    JvmTypeParameter _delegate = this.getDelegate();
    _builder.append(_delegate);
    Preconditions.checkState(_tripleNotEquals, _builder);
    this.getCompilationUnit().getJvmModelAssociator().removeAllAssociation(this.getDelegate());
    EcoreUtil.remove(this.getDelegate());
    Resource _eResource_1 = this.getDelegate().eResource();
    boolean _tripleEquals = (_eResource_1 == null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("Couldn\'t remove: ");
    JvmTypeParameter _delegate_1 = this.getDelegate();
    _builder_1.append(_delegate_1);
    Preconditions.checkState(_tripleEquals, _builder_1);
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Resource(org.eclipse.emf.ecore.resource.Resource) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 43 with Resource

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

the class ProblemSupportImpl method addError.

@Override
public void addError(final Element element, final String message) {
    this.checkCanceled();
    this.checkValidationAllowed();
    final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
    EList<Resource.Diagnostic> _errors = resAndObj.getKey().getErrors();
    EObject _value = resAndObj.getValue();
    EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue());
    EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, "user.issue", message, _value, _significantFeature, (-1), null);
    _errors.add(_eObjectDiagnosticImpl);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 44 with Resource

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

the class ProblemSupportImpl method getResourceAndEObject.

private Pair<Resource, EObject> getResourceAndEObject(final Element element) {
    this.checkCanceled();
    boolean _matched = false;
    if (element instanceof CompilationUnitImpl) {
        boolean _equals = Objects.equal(element, this.compilationUnit);
        if (_equals) {
            _matched = true;
            Resource _eResource = this.compilationUnit.getXtendFile().eResource();
            XtendFile _xtendFile = this.compilationUnit.getXtendFile();
            return Pair.<Resource, EObject>of(_eResource, _xtendFile);
        }
    }
    if (!_matched) {
        if (element instanceof AbstractElementImpl) {
            _matched = true;
            final Resource resource = ((AbstractElementImpl<? extends EObject>) element).getDelegate().eResource();
            Resource _eResource = this.compilationUnit.getXtendFile().eResource();
            boolean _equals = Objects.equal(resource, _eResource);
            if (_equals) {
                final EObject eobject = this.compilationUnit.getJvmModelAssociations().getPrimarySourceElement(((AbstractElementImpl<? extends EObject>) element).getDelegate());
                if ((eobject == null)) {
                    EObject _delegate = ((AbstractElementImpl<? extends EObject>) element).getDelegate();
                    return Pair.<Resource, EObject>of(resource, _delegate);
                }
                return Pair.<Resource, EObject>of(resource, eobject);
            }
        }
    }
    throw new IllegalArgumentException("You can only add issues on locally declared elements.");
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) AbstractElementImpl(org.eclipse.xtend.core.macro.declaration.AbstractElementImpl) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 45 with Resource

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

the class ProblemSupportImpl method addWarning.

@Override
public void addWarning(final Element element, final String message) {
    this.checkCanceled();
    this.checkValidationAllowed();
    final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
    EList<Resource.Diagnostic> _warnings = resAndObj.getKey().getWarnings();
    EObject _value = resAndObj.getValue();
    EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue());
    EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.WARNING, "user.issue", message, _value, _significantFeature, (-1), null);
    _warnings.add(_eObjectDiagnosticImpl);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)448 Test (org.junit.Test)210 XtextResource (org.eclipse.xtext.resource.XtextResource)157 EObject (org.eclipse.emf.ecore.EObject)109 URI (org.eclipse.emf.common.util.URI)85 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)76 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)71 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)66 StringInputStream (org.eclipse.xtext.util.StringInputStream)50 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)45 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)36 IOException (java.io.IOException)26 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)24 List (java.util.List)23 EClass (org.eclipse.emf.ecore.EClass)23 EPackage (org.eclipse.emf.ecore.EPackage)23 InternalEObject (org.eclipse.emf.ecore.InternalEObject)23 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)21 ArrayList (java.util.ArrayList)19 IFile (org.eclipse.core.resources.IFile)18