com.sun.tools.javac.code.Type.ClassType Java Examples

The following examples show how to use com.sun.tools.javac.code.Type.ClassType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Symtab.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
    final Completer completer = type.tsym.completer;
    type.tsym.completer = new Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            try {
                completer.complete(sym);
            } catch (CompletionFailure e) {
                sym.flags_field |= (PUBLIC | INTERFACE);
                ((ClassType) sym.type).supertype_field = objectType;
            }
        }

        @Override
        public boolean isTerminal() {
            return completer.isTerminal();
        }
    };
}
 
Example #2
Source File: ParameterizedTypeImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static String parameterizedTypeToString(DocEnv env, ClassType cl,
                                        boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(cl, full);
    }
    StringBuilder s = new StringBuilder();
    if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
        s.append(TypeMaker.getTypeName(cl, full));
    } else {
        ClassType encl = (ClassType)cl.getEnclosingType();
        s.append(parameterizedTypeToString(env, encl, full))
         .append('.')
         .append(cl.tsym.name.toString());
    }
    s.append(TypeMaker.typeArgumentsString(env, cl, full));
    return s.toString();
}
 
Example #3
Source File: TypeMaker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example #4
Source File: Printer.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String visitClassType(ClassType t, Locale locale) {
    StringBuffer buf = new StringBuffer();
    if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
        buf.append(visit(t.getEnclosingType(), locale));
        buf.append(".");
        buf.append(className(t, false, locale));
    } else {
        buf.append(className(t, true, locale));
    }
    if (t.getTypeArguments().nonEmpty()) {
        buf.append('<');
        buf.append(visitTypes(t.getTypeArguments(), locale));
        buf.append(">");
    }
    return buf.toString();
}
 
Example #5
Source File: ParameterizedTypeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static String parameterizedTypeToString(DocEnv env, ClassType cl,
                                        boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(cl, full);
    }
    StringBuilder s = new StringBuilder();
    if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
        s.append(TypeMaker.getTypeName(cl, full));
    } else {
        ClassType encl = (ClassType)cl.getEnclosingType();
        s.append(parameterizedTypeToString(env, encl, full))
         .append('.')
         .append(cl.tsym.name.toString());
    }
    s.append(TypeMaker.typeArgumentsString(env, cl, full));
    return s.toString();
}
 
Example #6
Source File: TypeMaker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example #7
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Read inner class info. For each inner/outer pair allocate a
 *  member class.
 */
void readInnerClasses(ClassSymbol c) {
    int n = nextChar();
    for (int i = 0; i < n; i++) {
        nextChar(); // skip inner class symbol
        ClassSymbol outer = readClassSymbol(nextChar());
        Name name = readName(nextChar());
        if (name == null) name = names.empty;
        long flags = adjustClassFlags(nextChar());
        if (outer != null) { // we have a member class
            if (name == names.empty)
                name = names.one;
            ClassSymbol member = enterClass(name, outer);
            if ((flags & STATIC) == 0) {
                ((ClassType)member.type).setEnclosingType(outer.type);
                if (member.erasure_field != null)
                    ((ClassType)member.erasure_field).setEnclosingType(types.erasure(outer.type));
            }
            if (c == outer) {
                member.flags_field = flags;
                enterMember(c, member);
            }
        }
    }
}
 
Example #8
Source File: ParameterizedTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static String parameterizedTypeToString(DocEnv env, ClassType cl,
                                        boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(cl, full);
    }
    StringBuilder s = new StringBuilder();
    if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
        s.append(TypeMaker.getTypeName(cl, full));
    } else {
        ClassType encl = (ClassType)cl.getEnclosingType();
        s.append(parameterizedTypeToString(env, encl, full))
         .append('.')
         .append(cl.tsym.name.toString());
    }
    s.append(TypeMaker.typeArgumentsString(env, cl, full));
    return s.toString();
}
 
Example #9
Source File: ParameterizedTypeImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static String parameterizedTypeToString(DocEnv env, ClassType cl,
                                        boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(cl, full);
    }
    StringBuilder s = new StringBuilder();
    if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
        s.append(TypeMaker.getTypeName(cl, full));
    } else {
        ClassType encl = (ClassType)cl.getEnclosingType();
        s.append(parameterizedTypeToString(env, encl, full))
         .append('.')
         .append(cl.tsym.name.toString());
    }
    s.append(TypeMaker.typeArgumentsString(env, cl, full));
    return s.toString();
}
 
Example #10
Source File: ParameterizedTypeImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static String parameterizedTypeToString(DocEnv env, ClassType cl,
                                        boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(cl, full);
    }
    StringBuilder s = new StringBuilder();
    if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
        s.append(TypeMaker.getTypeName(cl, full));
    } else {
        ClassType encl = (ClassType)cl.getEnclosingType();
        s.append(parameterizedTypeToString(env, encl, full))
         .append('.')
         .append(cl.tsym.name.toString());
    }
    s.append(TypeMaker.typeArgumentsString(env, cl, full));
    return s.toString();
}
 
Example #11
Source File: TypeMaker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example #12
Source File: TypeMaker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example #13
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitPackageDef(JCPackageDecl tree) {
    if (!needPackageInfoClass(tree))
                    return;

    long flags = Flags.ABSTRACT | Flags.INTERFACE;
    // package-info is marked SYNTHETIC in JDK 1.6 and later releases
    flags = flags | Flags.SYNTHETIC;
    ClassSymbol c = tree.packge.package_info;
    c.setAttributes(tree.packge);
    c.flags_field |= flags;
    ClassType ctype = (ClassType) c.type;
    ctype.supertype_field = syms.objectType;
    ctype.interfaces_field = List.nil();
    createInfoClass(tree.annotations, c);
}
 
Example #14
Source File: RichDiagnosticFormatter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String className(ClassType t, boolean longform, Locale locale) {
    Symbol sym = t.tsym;
    if (sym.name.length() == 0 ||
            !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
        return super.className(t, longform, locale);
    } else if (longform)
        return nameSimplifier.simplify(sym).toString();
    else
        return sym.name.toString();
}
 
Example #15
Source File: HandleDelegate.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
	TypeSymbol tsym = ct.asElement();
	if (tsym == null) return;
	
	for (Symbol member : tsym.getEnclosedElements()) {
		for (Compound am : member.getAnnotationMirrors()) {
			String name = null;
			try {
				name = am.type.tsym.flatName().toString();
			} catch (Exception ignore) {}
			
			if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
				throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
			}
		}
		if (member.getKind() != ElementKind.METHOD) continue;
		if (member.isStatic()) continue;
		if (member.isConstructor()) continue;
		ExecutableElement exElem = (ExecutableElement)member;
		if (!exElem.getModifiers().contains(Modifier.PUBLIC)) continue;
		ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
		String sig = printSig(methodType, member.name, types);
		if (!banList.add(sig)) continue; //If add returns false, it was already in there
		boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
		signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
	}
	
	if (ct.supertype_field instanceof ClassType) addMethodBindings(signatures, (ClassType) ct.supertype_field, types, banList);
	if (ct.interfaces_field != null) for (Type iface : ct.interfaces_field) {
		if (iface instanceof ClassType) addMethodBindings(signatures, (ClassType) iface, types, banList);
	}
}
 
Example #16
Source File: VarTypePrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type visitClassType(ClassType t, Boolean upward) {
    if (upward && !t.isCompound() && t.tsym.name.isEmpty()) {
        //lift anonymous class type to first supertype (class or interface)
        return types.directSupertypes(t).last();
    } else if (t.isCompound()) {
        List<Type> components = types.directSupertypes(t);
        List<Type> components1 = components.map(c -> c.map(this, upward));
        if (components == components1) return t;
        else return types.makeIntersectionType(components1);
    } else {
        Type outer = t.getEnclosingType();
        Type outer1 = visit(outer, upward);
        List<Type> typarams = t.getTypeArguments();
        List<Type> typarams1 = typarams.map(ta -> mapTypeArgument(ta, upward));
        if (typarams1.stream().anyMatch(ta -> ta.hasTag(BOT))) {
            //not defined
            return syms.botType;
        }
        if (outer1 == outer && typarams1 == typarams) return t;
        else return new ClassType(outer1, typarams1, t.tsym, t.getMetadata()) {
            @Override
            protected boolean needsStripping() {
                return true;
            }
        };
    }
}
 
Example #17
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private ImmutableList<MethodDeclarationPair> getDeclaredMethods(ClassType classType) {
  return classType.asElement().getEnclosedElements().stream()
      .filter(
          element ->
              !isSynthetic(element)
                  && (element.getKind() == ElementKind.METHOD
                      || element.getKind() == ElementKind.CONSTRUCTOR))
      .map(MethodSymbol.class::cast)
      .map(
          methodSymbol ->
              new MethodDeclarationPair(
                  (MethodSymbol) methodSymbol.asMemberOf(classType, internalTypes), methodSymbol))
      .collect(toImmutableList());
}
 
Example #18
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private Set<MethodSymbol> getJavaLangObjectMethods() {
  ClassType javaLangObjectTypeBinding =
      (ClassType) elements.getTypeElement("java.lang.Object").asType();
  return getDeclaredMethods(javaLangObjectTypeBinding).stream()
      .map(MethodDeclarationPair::getMethodSymbol)
      .filter(JavaEnvironment::isPolymorphic)
      .collect(ImmutableSet.toImmutableSet());
}
 
Example #19
Source File: TypeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the actual type arguments of a parameterized type as an
 * angle-bracketed string.  Class name are qualified if "full" is true.
 * Return "" if there are no type arguments or we're hiding generics.
 */
static String typeArgumentsString(DocEnv env, ClassType cl, boolean full) {
    if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
        return "";
    }
    StringBuilder s = new StringBuilder();
    for (Type t : cl.getTypeArguments()) {
        s.append(s.length() == 0 ? "<" : ", ");
        s.append(getTypeString(env, t, full));
    }
    s.append(">");
    return s.toString();
}
 
Example #20
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private ImmutableList<MethodDeclarationPair> getMethods(ClassType classType) {
  return elements.getAllMembers((TypeElement) classType.asElement()).stream()
      .filter(
          element ->
              !isSynthetic(element)
                  && (element.getKind() == ElementKind.METHOD
                      || element.getKind() == ElementKind.CONSTRUCTOR))
      .map(MethodSymbol.class::cast)
      .map(
          methodSymbol ->
              new MethodDeclarationPair(
                  (MethodSymbol) methodSymbol.asMemberOf(classType, internalTypes), methodSymbol))
      .collect(toImmutableList());
}
 
Example #21
Source File: TypeMirrorHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitClassType(ClassType t, Void s) {
    if (t.supertype_field != null)
        t.supertype_field.accept(this, s);
    if (t.interfaces_field != null)
        for (com.sun.tools.javac.util.List<Type> l = t.interfaces_field; l.nonEmpty(); l = l.tail)
            l.head.accept(this, s);
    if (t.typarams_field != null)
        for (com.sun.tools.javac.util.List<Type> l = t.typarams_field; l.nonEmpty(); l = l.tail)
            l.head.accept(this, s);
    return null;
}
 
Example #22
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void runPhase(Env<AttrContext> env) {
    JCClassDecl tree = env.enclClass;
    ClassSymbol sym = tree.sym;
    ClassType ct = (ClassType)sym.type;

    Env<AttrContext> baseEnv = baseEnv(tree, env);

    attribSuperTypes(env, baseEnv);

    if (sym.fullname == names.java_lang_Object) {
        if (tree.extending != null) {
            chk.checkNonCyclic(tree.extending.pos(),
                               ct.supertype_field);
            ct.supertype_field = Type.noType;
        }
        else if (tree.implementing.nonEmpty()) {
            chk.checkNonCyclic(tree.implementing.head.pos(),
                               ct.interfaces_field.head);
            ct.interfaces_field = List.nil();
        }
    }

    markDeprecated(sym, tree.mods.annotations, baseEnv);

    chk.checkNonCyclicDecl(tree);
}
 
Example #23
Source File: DocEnv.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Return the ParameterizedType of this instantiation.
//   * ### Could use Type.sameTypeAs() instead of equality matching in hashmap
//   * ### to avoid some duplication.
     */
    ParameterizedTypeImpl getParameterizedType(ClassType t) {
        return new ParameterizedTypeImpl(this, t);
//      ParameterizedTypeImpl result = parameterizedTypeMap.get(t);
//      if (result != null) return result;
//      result = new ParameterizedTypeImpl(this, t);
//      parameterizedTypeMap.put(t, result);
//      return result;
    }
 
Example #24
Source File: InferenceContext.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Void visitClassType(ClassType t, Void _unused) {
    visit(t.getEnclosingType());
    for (Type targ : t.getTypeArguments()) {
        visit(targ);
    }
    return null;
}
 
Example #25
Source File: JavacTrees.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean visitClassType(ClassType t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    return t.tsym == s.tsym;
}
 
Example #26
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Note that we found an inheritance cycle. */
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
    log.error(pos, Errors.CyclicInheritance(c));
    for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
        l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
    Type st = types.supertype(c.type);
    if (st.hasTag(CLASS))
        ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
    c.type = types.createErrorType(c, c.type);
    c.flags_field |= ACYCLIC;
}
 
Example #27
Source File: UClassType.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Unifier visitClassType(ClassType classType, @Nullable Unifier unifier) {
  unifier = classType.tsym.getQualifiedName().contentEquals(fullyQualifiedClass()) 
      ? unifier : null;
  return Unifier.unifyList(unifier, typeArguments(), classType.getTypeArguments());
}
 
Example #28
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Boolean visitClassType(ClassType t, Void s) {
    if (t.isUnion() || t.isIntersection()) {
        return false;
    }
    for (Type targ : t.allparams()) {
        if (!visit(targ, s)) {
            return false;
        }
    }
    return true;
}
 
Example #29
Source File: T6889255.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example #30
Source File: Symtab.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Type enterSyntheticAnnotation(String name) {
    // for now, leave the module null, to prevent problems from synthesizing the
    // existence of a class in any specific module, including noModule
    ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type;
    ClassSymbol sym = (ClassSymbol)type.tsym;
    sym.completer = Completer.NULL_COMPLETER;
    sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
    sym.erasure_field = type;
    sym.members_field = WriteableScope.create(sym);
    type.typarams_field = List.nil();
    type.allparams_field = List.nil();
    type.supertype_field = annotationType;
    type.interfaces_field = List.nil();
    return type;
}