コード例 #1
0
  @Test
  public void testResolveUnqualifiedSymbolInSamePackage() {
    final CommonResolvingFilter<EntitySymbol> classResolver =
        new CommonResolvingFilter<>(EntitySymbol.KIND);

    final MutableScope globalScope =
        new GlobalScope(new ModelPath(), new LinkedHashSet<>(), new ResolverConfiguration());
    globalScope.addResolver(classResolver);

    ArtifactScope artifactScope1 =
        new ArtifactScope(Optional.of(globalScope), "p", new ArrayList<>());
    artifactScope1.addResolver(classResolver);
    EntitySymbol classA = new EntitySymbol("A");
    artifactScope1.add(classA);
    Scope classAScope = classA.getSpannedScope();

    ArtifactScope artifactScope2 =
        new ArtifactScope(Optional.of(globalScope), "p", new ArrayList<>());
    artifactScope2.addResolver(classResolver);
    EntitySymbol classB = new EntitySymbol("B");
    artifactScope2.add(classB);

    // resolve B with unqualified name, because it is in the same package as A.
    assertSame(classB, classAScope.resolve("B", EntitySymbol.KIND).get());

    assertSame(classA, classAScope.resolve("A", EntitySymbol.KIND).get());
  }
コード例 #2
0
  @Test
  public void testArtifactScopeWithoutImportStatements() {
    final CommonResolvingFilter<EntitySymbol> classResolver =
        new CommonResolvingFilter<>(EntitySymbol.KIND);

    final MutableScope globalScope =
        new GlobalScope(new ModelPath(), new LinkedHashSet<>(), new ResolverConfiguration());
    globalScope.addResolver(classResolver);

    ArtifactScope artifactScope1 =
        new ArtifactScope(Optional.of(globalScope), "p", new ArrayList<>());
    artifactScope1.addResolver(classResolver);
    EntitySymbol classA = new EntitySymbol("A");
    artifactScope1.add(classA);

    Scope classAScope = classA.getSpannedScope();

    ArtifactScope artifactScope2 =
        new ArtifactScope(Optional.of(globalScope), "q", new ArrayList<>());
    artifactScope2.addResolver(classResolver);
    EntitySymbol classQB = new EntitySymbol("B");
    artifactScope2.add(classQB);

    // resolve by qualified name
    assertSame(classQB, classAScope.resolve("q.B", EntitySymbol.KIND).get());

    // no imports defined, hence, resolving by simple name fails
    assertNull(classAScope.resolve("B", EntitySymbol.KIND).orElse(null));

    ArtifactScope artifactScope3 =
        new ArtifactScope(Optional.of(globalScope), "r", new ArrayList<>());
    artifactScope3.addResolver(classResolver);
    EntitySymbol classRB = new EntitySymbol("B");
    artifactScope3.add(classRB);

    // Now, besides q.B the symbol r.B is defines in the global scope (resp. in the compilation
    // scopes)
    // => Nothing changes

    // resolve by qualified name
    assertSame(classQB, classAScope.resolve("q.B", EntitySymbol.KIND).get());

    // no imports defined, hence, resolving by simple name fails
    assertNull(classAScope.resolve("B", EntitySymbol.KIND).orElse(null));
  }