Java 类org.eclipse.xtext.scoping.IScope 实例源码

项目:n4js    文件:ScopeXpectMethod.java   
/**
 * Compares scope including resource name and line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void scopeWithPosition( //
        @N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
        ICrossEReferenceAndEObject arg1 //
) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, true, scope),
            new IsInScopeWithOptionalPositionPredicate(converter,
                    uri, true, scope));
}
项目:n4js    文件:ScopeXpectMethod.java   
/**
 * Compares scope including resource name but not line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void scopeWithResource( //
        @N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
        ICrossEReferenceAndEObject arg1 //
) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, false, scope),
            new IsInScopeWithOptionalPositionPredicate(converter,
                    uri, false, scope));
}
项目:n4js    文件:ImportsAwareReferenceProposalCreator.java   
/**
 * Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
 * proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
 *
 * @param candidate
 *            for which proposal is created
 * @param delegateProposalFactory
 *            delegate proposal factory
 * @return code completion proposal
 */
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model,
        IScope scope,
        EReference reference,
        ContentAssistContext context,
        Predicate<IEObjectDescription> filter,
        Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {

    final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
    final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);

    if (result instanceof ConfigurableCompletionProposal) {
        final FQNImporter importer = fqnImporterFactory.create(
                model.eResource(),
                scope,
                valueConverter,
                filter,
                context.getViewer());

        ((ConfigurableCompletionProposal) result).setTextApplier(importer);
    }
    return result;
}
项目:n4js    文件:ContainerTypesHelper.java   
private List<Type> getPolyfillTypesFromScope(QualifiedName fqn) {

            IScope contextScope = polyfillScopeAccess.getRecordingPolyfillScope(contextResource);
            List<Type> types = new ArrayList<>();

            // contextScope.getElements(fqn) returns all polyfills, since shadowing is handled differently
            // for them!
            for (IEObjectDescription descr : contextScope.getElements(fqn)) {
                Type polyfillType = (Type) descr.getEObjectOrProxy();
                if (polyfillType.eIsProxy()) {
                    // TODO review: this seems odd... is this a test setup problem (since we do not use the
                    // index
                    // there and load the resource separately)?
                    polyfillType = (Type) EcoreUtil.resolve(polyfillType, contextResource);
                    if (polyfillType.eIsProxy()) {
                        throw new IllegalStateException("unexpected proxy");
                    }
                }
                types.add(polyfillType);
            }
            // }

            return types;
        }
项目:n4js    文件:CompositeScope.java   
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
    IEObjectDescription result = null;
    for (IScope currScope : childScopes) {
        final IEObjectDescription currResult = currScope.getSingleElement(name);
        if (currResult != null) {
            if (!(currResult instanceof IEObjectDescriptionWithError)) {
                return currResult; // no error, use scope order as precedence (first one wins) and return
            }
            if (result == null) {
                result = currResult; // with error, maybe we find something w/o error in following scope, do not
                                        // return yet
            }
        }
    }
    return result; // return null or (first) description with error
}
项目:n4js    文件:CompositeScope.java   
@Override
public IEObjectDescription getSingleElement(EObject object) {
    IEObjectDescription result = null;
    for (IScope currScope : childScopes) {
        final IEObjectDescription currResult = currScope.getSingleElement(object);
        if (currResult != null) {
            if (!(currResult instanceof IEObjectDescriptionWithError)) {
                return currResult; // no error, use scope order as precedence (first one wins) and return
            }
            if (result == null) {
                result = currResult; // with error, maybe we find something w/o error in following scope, do not
                                        // return yet
            }
        }
    }
    return result; // return null or (first) description with error
}
项目:n4js    文件:ProjectImportEnablingScope.java   
/**
 * Wraps the given parent scope to enable project imports (see {@link ProjectImportEnablingScope} for details).
 * <p>
 * To support tests that use multiple projects without properly setting up IN4JSCore, we simply return 'parent' in
 * such cases; however, project imports will not be available in such tests.
 *
 * @param importDecl
 *            if an import declaration is provided, imported error reporting will be activated (i.e. an
 *            {@link IEObjectDescriptionWithError} will be returned instead of <code>null</code> in case of
 *            unresolvable references).
 */
public static IScope create(IN4JSCore n4jsCore, Resource resource, Optional<ImportDeclaration> importDecl,
        IScope parent, IScope delegate) {
    if (n4jsCore == null || resource == null || importDecl == null || parent == null) {
        throw new IllegalArgumentException("none of the arguments may be null");
    }
    if (importDecl.isPresent() && importDecl.get().eResource() != resource) {
        throw new IllegalArgumentException("given import declaration must be contained in the given resource");
    }
    final Optional<? extends IN4JSProject> contextProject = n4jsCore.findProject(resource.getURI());
    if (!contextProject.isPresent()) {
        // we failed to obtain an IN4JSProject for the project containing 'importDecl'
        // -> it would be best to throw an exception in this case, but we have many tests that use multiple projects
        // without properly setting up the IN4JSCore; to not break those tests, we return 'parent' here
        return parent;
    }
    return new ProjectImportEnablingScope(n4jsCore, contextProject.get(), importDecl, parent, delegate);
}
项目:n4js    文件:UserDataAwareScope.java   
/**
 * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the
 * produced scope would be empty.
 *
 * @param canLoadFromDescriptionHelper
 *            utility to decide if a resource must be loaded from source or may be loaded from the index.
 */
public static IScope createScope(
        IScope outer,
        ISelectable selectable,
        Predicate<IEObjectDescription> filter,
        EClass type, boolean ignoreCase,
        ResourceSet resourceSet,
        CanLoadFromDescriptionHelper canLoadFromDescriptionHelper,
        IContainer container) {
    if (selectable == null || selectable.isEmpty())
        return outer;
    IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet,
            canLoadFromDescriptionHelper,
            container);
    return scope;
}
项目:n4js    文件:IntersectionMemberScope.java   
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);

    QualifiedName qn = QualifiedName.create(name);
    boolean allDescrWithError = true;
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        allDescrWithError &= descrWithError;
    }
    if (allDescrWithError) {
        return createComposedMemberDescriptionWithErrors(description);
    }

    return description;
}
项目:n4js    文件:UnionMemberScope.java   
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);

    QualifiedName qn = QualifiedName.create(name);
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);

        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        if (descrWithError) {
            return createComposedMemberDescriptionWithErrors(description);
        }
    }

    return description;
}
项目:solidity-ide    文件:SolidityImportedNamespaceAwareLocalScopeProvider.java   
protected IScope getResourceScope(Resource res, EReference reference) {
    if (reference == TypesPackage.Literals.COMPLEX_TYPE__SUPER_TYPES)
        return super.getResourceScope(res, reference);
    EObject context = res.getContents().get(0);
    IScope globalScope = getGlobalScope(res, reference);
    List<ImportNormalizer> normalizers = getSuperTypeImports(res, reference);
    if (!normalizers.isEmpty()) {
        globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(),
                isIgnoreCase(reference));
    }
    return getResourceScope(globalScope, context, reference);
}
项目:xtext-core    文件:ImportedNamespaceAwareLocalScopeProviderTest.java   
@Test public void testLocalElementsNotFromIndex() throws Exception {
    final XtextResource resource = getResource(new StringInputStream(
              "A { " 
            + "  B { " 
            + "    entity D {}" 
            + "  }"
            + "}" 
            + "E {" 
            + "  datatype Context" 
            + "}"), URI.createURI("foo23.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {
        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Datatype datatype = filter(allContents, Datatype.class).iterator().next();
    IScope scope = scopeProvider.getScope(datatype, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("A.B.D")));
}
项目:xtext-core    文件:ReferenceUpdater.java   
@Override
public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference upd) {
    IUpdatableReference updatable = upd;
    if (rewriter.isModified(updatable.getReferenceRegion())) {
        return;
    }
    IScope scope = scopeProvider.getScope(updatable.getSourceEObject(), updatable.getEReference());
    ISemanticRegion region = updatable.getReferenceRegion();
    QualifiedName oldName = nameConverter.toQualifiedName(region.getText());
    IEObjectDescription oldDesc = scope.getSingleElement(oldName);
    if (oldDesc != null && oldDesc.getEObjectOrProxy() == updatable.getTargetEObject()) {
        return;
    }
    String newName = findValidName(updatable, scope);
    if (newName != null) {
        rewriter.replace(region, newName);
    }
}
项目:xtext-extras    文件:ExpressionScope.java   
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
    if (containedElements == null) {
        if (getParent() != IScope.NULLSCOPE) {
            Iterable<IEObjectDescription> result = delegate.getAllElements();
            List<IEObjectDescription> list = Lists.newArrayList(result);
            Set<String> keys = Sets.newHashSet();
            for(IEObjectDescription desc: result) {
                list.add(desc);
                keys.add(getShadowingKey(desc));
            }
            containedKeys = keys;
            containedElements = list;
            return list;
        } else {
            return delegate.getAllElements();
        }
    }
    return containedElements;
}
项目:xtext-extras    文件:SerializerScopeProvider.java   
public IScope createFeatureCallSerializationScope(EObject context) {
    if (!(context instanceof XAbstractFeatureCall)) {
        return IScope.NULLSCOPE;
    }
    XAbstractFeatureCall call = (XAbstractFeatureCall) context;
    JvmIdentifiableElement feature = call.getFeature();
    // this and super - logical container aware FeatureScopes
    if (feature instanceof JvmType) {
        return getTypeScope(call, (JvmType) feature);
    }
    if (feature instanceof JvmConstructor) {
        return getThisOrSuperScope(call, (JvmConstructor) feature);
    }
    if (feature instanceof JvmExecutable) {
        return getExecutableScope(call, feature);
    }
    if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) {
        return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE);
    }
    return IScope.NULLSCOPE;
}
项目:xtext-extras    文件:SyntaxFilteredScope.java   
@SuppressWarnings("serial")
public SyntaxFilteredScope(IScope parent, List<String> values) {
    this.parent = parent;
    this.values = new HashSet<QualifiedName>() {
        @Override
        public boolean contains(Object o) {
            if (o instanceof IEObjectDescription) {
                return super.contains(((IEObjectDescription) o).getName());
            }
            return super.contains(o);
        }
    };
    for(String value: values) {
        this.values.add(QualifiedName.create(value));
    }
}
项目:xtext-core    文件:SimpleNameScopeProviderTest.java   
@Test public void testGetAllContents() throws Exception {
    SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter();
    ResourceSetImpl rs = new ResourceSetImpl();
    rs.setURIConverter(models);

    models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type Foo");
    models.addModel("bar.importuritestlanguage", "type A type B type C");

    Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);

    IScope scope = getScopeProvider().getScope(((Main)resource.getContents().get(0)).getTypes().get(0), ImportedURIPackage.Literals.TYPE__EXTENDS);
    HashSet<IEObjectDescription> set = Sets.newHashSet(scope.getAllElements());
    assertEquals(4,set.size());
}
项目:xtext-core    文件:MapBasedScope.java   
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase) {
    Map<QualifiedName, IEObjectDescription> map = null;
    for(IEObjectDescription description: descriptions) {
        if (map == null)
            map = new LinkedHashMap<QualifiedName, IEObjectDescription>(4);
        QualifiedName name = ignoreCase ? description.getName().toLowerCase() : description.getName();
        IEObjectDescription previous = map.put(name, description);
        // we are optimistic that no duplicate names are used
        // however, if the name was already used, the first one should win
        if (previous != null) {
            map.put(name, previous);
        }
    }
    if (map == null || map.isEmpty()) {
        return parent;
    }
    return new MapBasedScope(parent, map, ignoreCase);
}
项目:dsl-devkit    文件:DelegatingScope.java   
/**
 * Evaluate the delegate scopes.
 *
 * @return The delegate scopes.
 */
protected Iterable<IScope> getDelegates() {
  if (delegates == null) {
    delegates = Iterables.transform(contexts.get(), new Function<EObject, IScope>() {
      @Override
      public IScope apply(final EObject from) {
        IScope scope = eReference != null ? scopeProvider.getScope(from, eReference, scopeName, originalResource)
            : scopeProvider.getScope(from, eClass, scopeName, originalResource);
        if (scope == DelegatingScope.this) { // NOPMD
          LOGGER.error("Cyclic delegate detected in scope \"" + getId() + "\" while computing scope for " + EObjectUtil.getLocationString(from)); //$NON-NLS-1$ //$NON-NLS-2$
          return IScope.NULLSCOPE;
        }
        return scope;
      }
    });
  }
  return delegates;
}
项目:xtext-core    文件:XtextLinkingService.java   
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
    final ICompositeNode parentNode = text.getParent();
    BidiIterator<INode> iterator = parentNode.getChildren().iterator();
    while(iterator.hasPrevious()) {
        INode child = iterator.previous();
        if (child instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) child;
            if (text == leaf)
                return super.getLinkedObjects(context, ref, text);
            if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
                IScope scope = getScope(context, ref);
                return XtextMetamodelReferenceHelper.findBestMetamodelForType(
                        context, text.getText(), leaf.getText(), scope);
            }
        }
    }
    return Collections.emptyList();
}
项目:xtext-core    文件:URINormalizationTest.java   
@Test public void testGetElementByClasspathURIEObject() throws Exception {
    with(ImportUriTestLanguageStandaloneSetup.class);
    Main main = (Main) getModel("import 'classpath:/org/eclipse/xtext/linking/05.importuritestlanguage'\n"
            + "type Bar extends Foo");
    Type bar = main.getTypes().get(0);
    Type foo = bar.getExtends();
    assertNotNull(foo);
    assertFalse(foo.eIsProxy());
    // we don't put contextual classpath:/ uris into the index thus
    // they are partially normalized
    if (Platform.isRunning()) {
        assertEquals("bundleresource", EcoreUtil.getURI(foo).scheme());
    } else {
        assertEquals("file", EcoreUtil.getURI(foo).scheme());
    }
    IScopeProvider scopeProvider = get(IScopeProvider.class);
    IScope scope = scopeProvider.getScope(bar, ImportedURIPackage.Literals.TYPE__EXTENDS);
    Iterable<IEObjectDescription> elements = scope.getElements(foo);
    assertEquals(1, size(elements));
    assertEquals(EcoreUtil2.getPlatformResourceOrNormalizedURI(foo), elements.iterator().next().getEObjectURI());
}
项目:xtext-core    文件:IdeCrossrefProposalProvider.java   
public void lookupCrossReference(final IScope scope, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor, final Predicate<IEObjectDescription> filter) {
  try {
    Iterable<IEObjectDescription> _queryScope = this.queryScope(scope, crossReference, context);
    for (final IEObjectDescription candidate : _queryScope) {
      {
        boolean _canAcceptMoreProposals = acceptor.canAcceptMoreProposals();
        boolean _not = (!_canAcceptMoreProposals);
        if (_not) {
          return;
        }
        boolean _apply = filter.apply(candidate);
        if (_apply) {
          final ContentAssistEntry entry = this.createProposal(candidate, crossReference, context);
          acceptor.accept(entry, this.proposalPriorities.getCrossRefPriority(candidate, entry));
        }
      }
    }
  } catch (final Throwable _t) {
    if (_t instanceof UnsupportedOperationException) {
      final UnsupportedOperationException uoe = (UnsupportedOperationException)_t;
      IdeCrossrefProposalProvider.LOG.error("Failed to create content assist proposals for cross-reference.", uoe);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
项目:xtext-core    文件:ImportedNamespaceAwareLocalScopeProviderTest.java   
@Test public void testRelativePath() throws Exception {
    final XtextResource resource = getResource(new StringInputStream(
              "stuff { " 
            + "  import baz.*" 
            + "  baz { "
            + "    datatype String " 
            + "  } " 
            + "  entity Person {" 
            + "  }" 
            + "}"), URI
            .createURI("relative.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {
        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Entity entity = filter(allContents, Entity.class).iterator().next();

    IScope scope = scopeProvider.getScope(entity, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("String")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("baz.String")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("stuff.baz.String")));
}
项目:xtext-extras    文件:XbaseIdeContentProposalProvider.java   
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver);
  final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
  if (((receiverType == null) || receiverType.isPrimitiveVoid())) {
    return;
  }
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
  IScope scope = null;
  final EObject currentModel = context.getCurrentModel();
  if ((currentModel != receiver)) {
    if (((currentModel instanceof XMemberFeatureCall) && 
      (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference);
    } else {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
    }
  } else {
    scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
  }
  this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate);
}
项目:n4js    文件:GrammarPrettyPrinter.java   
@Override
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref,
        EObject target, IScope scope, Acceptor errors) {
    if (target instanceof AbstractRule) {
        return ((AbstractRule) target).getName();
    }
    if (target instanceof ENamedElement) {
        return ((ENamedElement) target).getName();
    }
    return super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
项目:n4js    文件:BuiltInTypesGlobalScopeProvider.java   
@Override
protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type,
        Predicate<IEObjectDescription> filter) {
    // we are only interested in the builtin types
    // and don't care about other types from the index / available on the classpath
    return parent;
}
项目:n4js    文件:DefaultN4GlobalScopeProvider.java   
/**
 * If the type is a {@link Type} a new {@link BuiltInTypeScope} is created.
 */
@Override
protected IScope getScope(Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
    if (isSubtypeOfType(type)) {
        return getScope(getBuiltInTypeScope(context), context, ignoreCase, type, filter);
    }
    // do not call super but directly redirect with nullscope, using IScopeExt.NULLSCOPE instead of IScope.NULLSCOPE
    return getScope(IScope.NULLSCOPE, context, ignoreCase, type, filter);
}
项目:n4js    文件:PolyfillAwareSelectableBasedScope.java   
/**
 * Creates this scope if container is present, otherwise parent is returned.
 */
public static IScope createPolyfillAwareScope(IScope parent, IContainer container,
        Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) {
    if (container == null || container.isEmpty())
        return parent;
    return new PolyfillAwareSelectableBasedScope(parent, container, filter, type, ignoreCase);
}
项目:n4js    文件:IsInScopeWithOptionalPositionPredicate.java   
public IsInScopeWithOptionalPositionPredicate(IQualifiedNameConverter converter, URI currentURI,
        boolean withLineNumber, IScope scope) {
    super();
    this.converter = converter;
    this.scope = scope;
    this.currentURI = currentURI;
    this.withLineNumber = withLineNumber;
}
项目:n4js    文件:FilterWithErrorMarkerScope.java   
/**
 * Returns true if given scope is already decorated with given filter scope type.
 */
public static boolean isDecoratedWithFilter(IScope scope,
        Class<? extends FilterWithErrorMarkerScope> filterScopeType) {
    if (filterScopeType.isInstance(scope)) {
        return true;
    }
    if (scope instanceof FilterWithErrorMarkerScope) {
        return isDecoratedWithFilter(((FilterWithErrorMarkerScope) scope).parent, filterScopeType);
    }
    return false;
}
项目:n4js    文件:FQNImporter.java   
FQNImporter(
        Resource context,
        IScope scope,
        IValueConverter<String> valueConverter,
        Predicate<IEObjectDescription> filter,
        ITextViewer viewer) {
    this.context = context;
    this.scope = scope;
    this.valueConverter = valueConverter;
    this.filter = filter;
    this.viewer = viewer;
}
项目:n4js    文件:ErrorAwareLinkingService.java   
/**
 * Override to get scope based on the context, otherwise we might get scope for main language, while context is from
 * sub-language.
 */
@Override
protected IScope getScope(EObject context, EReference reference) {
    IScopeProvider scopeProvider = N4LanguageUtils.getServiceForContext(context, IScopeProvider.class)
            .orElse(super.getScopeProvider());
    if (getScopeProvider() == null)
        throw new IllegalStateException("scopeProvider must not be null.");
    try {
        registerImportedNamesAdapter(scopeProvider, context);
        return scopeProvider.getScope(context, reference);
    } finally {
        unRegisterImportedNamesAdapter(scopeProvider);
    }
}
项目:n4js    文件:ErrorAwareLinkingService.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null)
        return Collections.<EObject> emptyList();

    final String crossRefString = getCrossRefNodeAsString(context, ref, node);
    if (crossRefString != null && !crossRefString.equals("")) {
        final IScope scope = getScope(context, ref);
        QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
        IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
        if (IEObjectDescriptionWithError.isErrorDescription(eObjectDescription) && context.eResource() != null
                && !n4jsCore.isNoValidate(context.eResource().getURI())) {
            addError(context, node, IEObjectDescriptionWithError.getDescriptionWithError(eObjectDescription));
        } else if (eObjectDescription instanceof UnresolvableObjectDescription) {
            return Collections.<EObject> singletonList((EObject) context.eGet(ref, false));
        }
        if (eObjectDescription != null) {
            EObject candidate = eObjectDescription.getEObjectOrProxy();
            if (!candidate.eIsProxy() && candidate.eResource() == null) {
                // Error is necessary since EMF catches all exceptions in EcoreUtil#resolve
                throw new AssertionError("Found an instance without resource and without URI");
            }
            return Collections.singletonList(candidate);
        }
    }
    return Collections.emptyList();
}
项目:n4js    文件:ImportedNamesRecordingScopeAccess.java   
/**
 * Obtain a global scope to lookup polyfills. Any request by name on the returned scope will record the name in the
 * list of imported names of the given context resource.
 */
public IScope getRecordingPolyfillScope(Resource context) {
    ImportedNamesAdapter importedNamesAdapter = getImportedNamesAdapter(context);
    IScope scope = globalScopeProvider.getScope(context,
            TypeRefsPackage.Literals.PARAMETERIZED_TYPE_REF__DECLARED_TYPE, null);
    return importedNamesAdapter.wrap(scope);
}
项目:n4js    文件:N4JSGlobalScopeProvider.java   
@Override
protected IScope getScope(IScope parent, Resource context, boolean ignoreCase, EClass type,
        Predicate<IEObjectDescription> filter) {
    IScope result = super.getScope(parent, context, ignoreCase, type, filter);

    if (isSubtypeOfType(type)) {
        result = new VisibilityAwareTypeScope(result, typeVisibilityChecker, context);
        return result;
    }
    if (isSubtypeOfIdentifiable(type)) {
        result = new VisibilityAwareIdentifiableScope(result, varVisibilityChecker, typeVisibilityChecker, context);
        return result;
    }
    return result;
}
项目:n4js    文件:CompositeScope.java   
/**
 * Creates a new {@link CompositeScope}; if no scopes are given, {@link IScope#NULLSCOPE} is returned.
 */
public static final IScope create(IScope... scopes) {
    if (scopes.length == 0) {
        return IScope.NULLSCOPE;
    }
    return new CompositeScope(scopes);
}
项目:n4js    文件:CompositeScope.java   
/**
 * Creates a new {@link CompositeScope}; if no scopes are given, {@link IScope#NULLSCOPE} is returned.
 */
public static final IScope create(List<IScope> scopes) {
    if (scopes == null || scopes.isEmpty()) {
        return IScope.NULLSCOPE;
    }
    IScope[] arrayScopes = new IScope[scopes.size()];
    scopes.toArray(arrayScopes);
    return new CompositeScope(arrayScopes);
}
项目:n4js    文件:ProjectImportEnablingScope.java   
/**
 *
 * @param contextProject
 *            the project containing the import declaration (not the project containing the module to import from)!
 */
private ProjectImportEnablingScope(IN4JSCore n4jsCore, IN4JSProject contextProject,
        Optional<ImportDeclaration> importDecl, IScope parent, IScope delegate) {
    if (n4jsCore == null || contextProject == null || importDecl == null || parent == null) {
        throw new IllegalArgumentException("none of the arguments may be null");
    }
    this.n4jsCore = n4jsCore;
    this.contextProject = contextProject;
    this.parent = parent;
    this.importDeclaration = importDecl;
    this.delegate = delegate;
}
项目:n4js    文件:UserDataAwareScope.java   
UserDataAwareScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type,
        boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper,
        IContainer container) {
    super(outer, selectable, filter, type, ignoreCase);
    this.resourceSet = resourceSet;
    this.canLoadFromDescriptionHelper = canLoadFromDescriptionHelper;
    this.container = container;
    this.type = type;
}
项目:n4js    文件:NoPrimitiveTypesScope.java   
/**
 * Instantiates a new {@link NoPrimitiveTypesScope}
 *
 * @param parent
 *            The parent scope whose results will be filtered
 */
public NoPrimitiveTypesScope(IScope parent) {
    super(parent, elementDescription -> {
        if (null == elementDescription || null == elementDescription.getEClass()) {
            return true;
        }
        int elementClassifierId = elementDescription.getEClass().getClassifierID();
        return elementClassifierId != TypesPackage.PRIMITIVE_TYPE &&
                elementClassifierId != TypesPackage.ANY_TYPE;
    });
}