Exemplo n.º 1
0
 private Set<JavaType.ClassJavaType> interfacesOfType() {
   ImmutableSet.Builder<JavaType.ClassJavaType> builder = ImmutableSet.builder();
   for (JavaType interfaceType : getInterfaces()) {
     JavaType.ClassJavaType classType = (JavaType.ClassJavaType) interfaceType;
     builder.add(classType);
     builder.addAll(classType.getSymbol().interfacesOfType());
   }
   return builder.build();
 }
Exemplo n.º 2
0
 /**
  * Includes superclass and super interface hierarchy.
  *
  * @return list of classTypes.
  */
 public Set<JavaType.ClassJavaType> superTypes() {
   ImmutableSet.Builder<JavaType.ClassJavaType> types = ImmutableSet.builder();
   JavaType.ClassJavaType superClassType = (JavaType.ClassJavaType) this.superClass();
   types.addAll(this.interfacesOfType());
   while (superClassType != null) {
     types.add(superClassType);
     TypeJavaSymbol superClassSymbol = superClassType.getSymbol();
     types.addAll(superClassSymbol.interfacesOfType());
     superClassType = (JavaType.ClassJavaType) superClassSymbol.superClass();
   }
   return types.build();
 }
Exemplo n.º 3
0
 @Nullable
 private Boolean overridesFromSymbol(JavaType.ClassJavaType classType) {
   Boolean result = false;
   if (classType.isTagged(JavaType.UNKNOWN)) {
     return null;
   }
   List<JavaSymbol> symbols = classType.getSymbol().members().lookup(name);
   for (JavaSymbol overrideSymbol : symbols) {
     if (overrideSymbol.isKind(JavaSymbol.MTH)
         && canOverride((MethodJavaSymbol) overrideSymbol)) {
       Boolean isOverriding = isOverriding((MethodJavaSymbol) overrideSymbol, classType);
       if (isOverriding == null) {
         result = null;
       } else if (BooleanUtils.isTrue(isOverriding)) {
         return true;
       }
     }
   }
   return result;
 }
Exemplo n.º 4
0
  static {
    rootPackage = new JavaSymbol.PackageJavaSymbol("", null);
    unknownSymbol =
        new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "!unknownSymbol!", rootPackage) {
          @Override
          public void addUsage(IdentifierTree tree) {
            // noop
          }

          @Override
          public boolean isTypeSymbol() {
            return false;
          }

          @Override
          public boolean isUnknown() {
            return true;
          }
        };
    unknownSymbol.members =
        new Scope(unknownSymbol) {
          @Override
          public void enter(JavaSymbol symbol) {
            // noop
          }
        };
    unknownType =
        new JavaType.ClassJavaType(unknownSymbol) {
          @Override
          public String toString() {
            return "!unknown!";
          }
        };
    unknownType.tag = JavaType.UNKNOWN;
    unknownType.supertype = null;
    unknownType.interfaces = ImmutableList.of();
    unknownSymbol.type = unknownType;
  }
Exemplo n.º 5
0
  public Symbols(BytecodeCompleter bytecodeCompleter) {
    defaultPackage = new JavaSymbol.PackageJavaSymbol("", rootPackage);

    predefClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", rootPackage);
    predefClass.members = new Scope(predefClass);
    ((JavaType.ClassJavaType) predefClass.type).interfaces = ImmutableList.of();

    // TODO should have type "noType":
    noSymbol = new JavaSymbol.TypeJavaSymbol(0, "", rootPackage);

    methodClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", noSymbol);

    // builtin types
    byteType = initType(JavaType.BYTE, "byte");
    charType = initType(JavaType.CHAR, "char");
    shortType = initType(JavaType.SHORT, "short");
    intType = initType(JavaType.INT, "int");
    longType = initType(JavaType.LONG, "long");
    floatType = initType(JavaType.FLOAT, "float");
    doubleType = initType(JavaType.DOUBLE, "double");
    booleanType = initType(JavaType.BOOLEAN, "boolean");
    nullType = initType(JavaType.BOT, "<nulltype>");
    voidType = initType(JavaType.VOID, "void");

    bytecodeCompleter.init(this);

    // predefined types for java lang
    JavaSymbol.PackageJavaSymbol javalang = bytecodeCompleter.enterPackage("java.lang");
    // define a star import scope to let resolve types to java.lang when needed.
    javalang.members = new Scope.StarImportScope(javalang, bytecodeCompleter);
    javalang.members.enter(javalang);

    objectType = bytecodeCompleter.loadClass("java.lang.Object").type;
    classType = bytecodeCompleter.loadClass("java.lang.Class").type;
    stringType = bytecodeCompleter.loadClass("java.lang.String").type;
    cloneableType = bytecodeCompleter.loadClass("java.lang.Cloneable").type;
    serializableType = bytecodeCompleter.loadClass("java.io.Serializable").type;
    annotationType = bytecodeCompleter.loadClass("java.lang.annotation.Annotation").type;
    enumType = bytecodeCompleter.loadClass("java.lang.Enum").type;

    // Associate boxed types
    boxedTypes = HashBiMap.create();
    boxedTypes.put(byteType, bytecodeCompleter.loadClass("java.lang.Byte").type);
    boxedTypes.put(charType, bytecodeCompleter.loadClass("java.lang.Character").type);
    boxedTypes.put(shortType, bytecodeCompleter.loadClass("java.lang.Short").type);
    boxedTypes.put(intType, bytecodeCompleter.loadClass("java.lang.Integer").type);
    boxedTypes.put(longType, bytecodeCompleter.loadClass("java.lang.Long").type);
    boxedTypes.put(floatType, bytecodeCompleter.loadClass("java.lang.Float").type);
    boxedTypes.put(doubleType, bytecodeCompleter.loadClass("java.lang.Double").type);
    boxedTypes.put(booleanType, bytecodeCompleter.loadClass("java.lang.Boolean").type);

    for (Entry<JavaType, JavaType> entry : boxedTypes.entrySet()) {
      entry.getKey().primitiveWrapperType = entry.getValue();
      entry.getValue().primitiveType = entry.getKey();
    }

    // TODO comment me
    arrayClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "Array", noSymbol);
    JavaType.ClassJavaType arrayClassType = (JavaType.ClassJavaType) arrayClass.type;
    arrayClassType.supertype = objectType;
    arrayClassType.interfaces = ImmutableList.of(cloneableType, serializableType);
    arrayClass.members = new Scope(arrayClass);
    arrayClass
        .members()
        .enter(
            new JavaSymbol.VariableJavaSymbol(
                Flags.PUBLIC | Flags.FINAL, "length", intType, arrayClass));
    // TODO arrayClass implements clone() method

    enterOperators();
  }