예제 #1
0
  /**
   *
   *
   * <pre>
   * public class OutermostClass {
   *   private static class TargetClass {
   *   }
   *   // accessible
   * }
   * class AnotherOutermostClass {
   *   // not accessible
   * }
   * </pre>
   */
  @Test
  public void access_private_class() {
    env.enclosingClass = new JavaSymbol.TypeJavaSymbol(0, "OutermostClass", env.packge);
    JavaSymbol.TypeJavaSymbol targetClassSymbol =
        new JavaSymbol.TypeJavaSymbol(Flags.PRIVATE, "TargetClass", env.enclosingClass);

    assertThat(resolve.isAccessible(env, targetClassSymbol)).isTrue();

    env.enclosingClass = new JavaSymbol.TypeJavaSymbol(0, "AnotherOutermostClass", env.packge);
    assertThat(resolve.isAccessible(env, targetClassSymbol)).isFalse();
  }
예제 #2
0
 public void complete(Symbol.VariableSymbol symbol) {
   VariableTree variableTree = (VariableTree) semanticModel.getTree(symbol);
   Resolve.Env env = semanticModel.getEnv(symbol);
   if (variableTree.is(Tree.Kind.ENUM_CONSTANT)) {
     symbol.type = env.enclosingClass().type;
   } else {
     symbol.type = castToTypeIfPossible(resolveType(env, variableTree.type()));
   }
 }
예제 #3
0
 @Override
 public void visitMemberSelectExpression(MemberSelectExpressionTree tree) {
   scan(tree.expression());
   if (site.kind >= Symbol.ERRONEOUS) {
     return;
   }
   String name = tree.identifier().name();
   if (site.kind == Symbol.PCK) {
     env.packge = (Symbol.PackageSymbol) site;
     site = resolve.findIdentInPackage(env, site, name, Symbol.TYP | Symbol.PCK);
   } else {
     env.enclosingClass = (Symbol.TypeSymbol) site;
     site =
         resolve.findMemberType(env, (Symbol.TypeSymbol) site, name, (Symbol.TypeSymbol) site);
   }
   associateReference(tree.identifier(), site);
 }