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; }
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(); }