Refine search
@Override public String visitType(Type t, Void unused) { return t.toString(); } },
/** Ignore some common ThreadLocal type arguments that are fine to have per-instance copies of. */ private boolean wellKnownTypeArgument(NewClassTree tree, VisitorState state) { Type type = getType(tree); if (type == null) { return false; } type = state.getTypes().asSuper(type, state.getSymbolFromString("java.lang.ThreadLocal")); if (type == null) { return false; } if (type.getTypeArguments().isEmpty()) { return false; } Type argType = getOnlyElement(type.getTypeArguments()); if (WELL_KNOWN_TYPES.contains(argType.asElement().getQualifiedName().toString())) { return true; } if (isSubtype(argType, state.getTypeFromString("java.text.DateFormat"), state)) { return true; } return false; } }
private String getSimpleTypeName(Type typ) { if (typ.getKind() == TypeKind.TYPEVAR) return typ.getUpperBound().tsym.getSimpleName().toString(); else return typ.tsym.getSimpleName().toString(); }
/** * Checks that the return value of a functional interface is void. Note, we do not use * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only * void-returning functions silently ignore return values of any type. */ private static boolean functionalInterfaceReturnsExactlyVoid( Type interfaceType, VisitorState state) { return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind() == TypeKind.VOID; }
/** * Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles * wildcards and capture variables. */ public static Type getUpperBound(Type type, Types types) { if (type.hasTag(TypeTag.WILDCARD)) { return types.wildUpperBound(type); } if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) { return types.cvarUpperBound(type); } if (type.getUpperBound() != null) { return type.getUpperBound(); } // concrete type, e.g. java.lang.String, or a case we haven't considered return type; }
return; mixin = context.getAnnotationValue(classdecl.sym, JSweetConfig.ANNOTATION_MIXIN, Type.class, null); for (Compound c : classdecl.sym.getAnnotationMirrors()) { if (JSweetConfig.ANNOTATION_MIXIN.equals(c.type.toString())) { String targetName = getRootRelativeName(((Attribute.Class) c.values.head.snd).classType.tsym); String mixinName = getRootRelativeName(classdecl.sym); && !(JSweetConfig.OBJECT_CLASSNAME.equals(classdecl.extending.type.toString()) || Object.class.getName().equals(classdecl.extending.type.toString())) && !(mixin != null && context.types.isSameType(mixin, classdecl.extending.type)) && !(getAdapter().eraseSuperClass(classdecl.sym, if (classdecl.implementing != null && !classdecl.implementing.isEmpty() && !getScope().enumScope) { List<JCExpression> implementing = new ArrayList<>(classdecl.implementing); || (def instanceof JCVariableDecl && ((JCVariableDecl) def).sym.isStatic()))) { Overload o = context.getOverload(classdecl.sym, meth); if (o != null && o.methods.size() > 1 && !o.isValid) { if (!meth.type.equals(o.coreMethod.type)) { printAbstractDeclaration = false; String signature = getContext().types.erasure(meth.type).toString(); if (!(signatures.containsKey(meth.name) && signatures.get(meth.name).equals(signature))) { printAbstractMethodDeclaration(meth);
public void visitNewClass(JCNewClass newClass) { ClassSymbol clazz = ((ClassSymbol) newClass.clazz.type.tsym); if (clazz.getSimpleName().toString().equals(JSweetConfig.GLOBALS_CLASS_NAME)) { report(newClass, JSweetProblem.GLOBAL_CANNOT_BE_INSTANTIATED); return; if (getScope().localClasses.stream().map(c -> c.type).anyMatch(t -> t.equals(newClass.type))) { print("new ").print(getScope().name + ".").print(newClass.clazz.toString()); print("(").printConstructorArgList(newClass, true).print(")"); if (assignment.lhs instanceof JCFieldAccess) { var = Util.findFieldDeclaration(clazz, ((JCFieldAccess) assignment.lhs).name); printIndent().print(var.getSimpleName().toString()); } else if (assignment.lhs instanceof JCIdent) { var = Util.findFieldDeclaration(clazz, ((JCIdent) assignment.lhs).name); print(param.getName() + ", "); if (!method.getParameters().isEmpty()) { removeLastChars(2); if (assignment.lhs instanceof JCFieldAccess) { var = Util.findFieldDeclaration(clazz, ((JCFieldAccess) assignment.lhs).name); printIndent().print("target['").print(var.getSimpleName().toString()).print("']"); } else if (assignment.lhs instanceof JCIdent) { printIndent().print("target['").print(assignment.lhs.toString()).print("']");
public void addShadowType(TypeElement shadowType, TypeElement actualType, TypeElement shadowPickerType) { TypeElement shadowBaseType = null; if (shadowPickerType != null) { TypeMirror iface = helpers.findInterface(shadowPickerType, ShadowPicker.class); if (iface != null) { com.sun.tools.javac.code.Type type = ((com.sun.tools.javac.code.Type.ClassType) iface) .allparams().get(0); String baseClassName = type.asElement().getQualifiedName().toString(); shadowBaseType = helpers.getTypeElement(baseClassName); } } ShadowInfo shadowInfo = new ShadowInfo(shadowType, actualType, shadowPickerType, shadowBaseType); if (shadowInfo.isInAndroidSdk()) { registerType(shadowInfo.shadowType); registerType(shadowInfo.actualType); registerType(shadowInfo.shadowBaseClass); } shadowTypes.put(shadowType.getQualifiedName().toString(), shadowInfo); }
private boolean containerOfSubtyping( Set<String> containerTypeParameters, AnnotationInfo annotation, TypeVariableSymbol typaram, Type tyargument) { // (1) if (!tyargument.hasTag(TypeTag.TYPEVAR)) { return false; } // (2) if (!containerTypeParameters.contains(tyargument.asElement().getSimpleName().toString()) || isTypeParameterThreadSafe( (TypeVariableSymbol) tyargument.asElement(), containerTypeParameters)) { return false; } // (3) if (annotation.containerOf().contains(typaram.getSimpleName().toString())) { return false; } return true; }
Symtab symtab = state.getSymtab(); List<? extends ExpressionTree> args = invocation.getArguments(); switch (symbol.getSimpleName().toString()) { case "expect": Type type = ASTHelpers.getType(getOnlyElement(invocation.getArguments())); Type matcherType = state.getTypes().asSuper(type, state.getSymbolFromString("org.hamcrest.Matcher")); if (!matcherType.getTypeArguments().isEmpty()) { Type matchType = getOnlyElement(matcherType.getTypeArguments()); if (isSubtype(matchType, symtab.throwableType, state)) { exceptionClassName = SuggestedFixes.qualifyType(state, fix, matchType); case "expectMessage": if (isSubtype( getOnlyElement(symbol.getParameters()).asType(), symtab.stringType, state)) {
private static boolean isMapMethod(Symbol.MethodSymbol symbol, Types types, String methodName) { if (!symbol.getSimpleName().toString().equals(methodName)) { return false; } Symbol owner = symbol.owner; if (owner.getQualifiedName().toString().equals("java.util.Map")) { return true; } com.sun.tools.javac.util.List<Type> supertypes = types.closure(owner.type); for (Type t : supertypes) { if (t.asElement().getQualifiedName().toString().equals("java.util.Map")) { return true; } } return false; }
/** The name of a this$n field * @param type The class referenced by the this$n field */ Name outerThisName(Type type, Symbol owner) { Type t = type.getEnclosingType(); int nestingLevel = 0; while (t.tag == CLASS) { t = t.getEnclosingType(); nestingLevel++; } Name result = names.fromString("this" + target.syntheticNameChar() + nestingLevel); while (owner.kind == TYP && ((ClassSymbol)owner).members().lookup(result).scope != null) result = names.fromString(result.toString() + target.syntheticNameChar()); return result; }
/** Enter type variables of this classtype and all enclosing ones in * `typevars'. */ protected void enterTypevars(Type t) { if (t.getEnclosingType() != null && t.getEnclosingType().hasTag(CLASS)) enterTypevars(t.getEnclosingType()); for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail) typevars.enter(xs.head.tsym); }
/** Check that type is a class or interface type. * @param pos Position to be used for error reporting. * @param t The type to be checked. * @param noBounds True if type bounds are illegal here. */ Type checkClassType(DiagnosticPosition pos, Type t, boolean noBounds) { t = checkClassType(pos, t); if (noBounds && t.isParameterized()) { List<Type> args = t.getTypeArguments(); while (args.nonEmpty()) { if (args.head.hasTag(WILDCARD)) return typeTagError(pos, diags.fragment("type.req.exact"), args.head); args = args.tail; } } return t; }
static ClassAndMethod make(MethodSymbol methodSymbol, @Nullable Types types) { // TODO(b/71812955): consider just wrapping methodSymbol instead of copying everything out. ImmutableList<String> annotations = MoreAnnotations.getDeclarationAndTypeAttributes(methodSymbol) .map(Object::toString) .collect(toImmutableList()); ClassSymbol clazzSymbol = (ClassSymbol) methodSymbol.owner; return new ClassAndMethod( clazzSymbol.getQualifiedName().toString(), methodSymbol.getSimpleName().toString(), annotations, methodSymbol.isStatic(), methodSymbol.getReturnType().isPrimitive(), methodSymbol.getReturnType().getTag() == BOOLEAN, hasGenericResult(methodSymbol), knownNonNullMethod(methodSymbol, clazzSymbol, types)); }
@Override public Type get(VisitorState state) { Type type = typeSupplier.get(state); if (type.getTypeArguments().size() <= n) { return state.getSymtab().objectType; } return type.getTypeArguments().get(n); } };
calledType = calledType.getEnclosingType(); tyargIndex = findTypeArgInList(encloser, typeArgName); if (tyargIndex != -1) { if (calledType.getTypeArguments().isEmpty()) { return RequiredType.create(calledType.getTypeArguments().get(tyargIndex));
public static Collection<? extends CodeTransformer> extractRules( ClassTree tree, Context context) { ClassSymbol sym = ASTHelpers.getSymbol(tree); RefasterRuleBuilderScanner scanner = new RefasterRuleBuilderScanner(context); // visit abstract methods first List<MethodTree> methods = new Ordering<MethodTree>() { @Override public int compare(MethodTree l, MethodTree r) { return Boolean.compare( l.getModifiers().getFlags().contains(Modifier.ABSTRACT), r.getModifiers().getFlags().contains(Modifier.ABSTRACT)); } }.reverse().immutableSortedCopy(Iterables.filter(tree.getMembers(), MethodTree.class)); scanner.visit(methods, null); UTemplater templater = new UTemplater(context); List<UType> types = templater.templateTypes(sym.type.getTypeArguments()); return scanner.createMatchers( Iterables.filter(types, UTypeVar.class), sym.getQualifiedName().toString(), UTemplater.annotationMap(sym)); }
/** The name of a this$n field * @param type The class referenced by the this$n field */ Name outerThisName(Type type, Symbol owner) { Type t = type.getEnclosingType(); int nestingLevel = 0; while (t.hasTag(CLASS)) { t = t.getEnclosingType(); nestingLevel++; } Name result = names.fromString("this" + target.syntheticNameChar() + nestingLevel); while (owner.kind == TYP && ((ClassSymbol)owner).members().lookup(result).scope != null) result = names.fromString(result.toString() + target.syntheticNameChar()); return result; }
private static Type getComparableTypeArgument(ClassTree tree, VisitorState state) { final Type comparable = state .getTypes() .asSuper(ASTHelpers.getType(tree), state.getSymtab().comparableType.asElement()); if (comparable != null && !comparable.getTypeArguments().isEmpty()) { return Iterables.getOnlyElement(comparable.getTypeArguments()); } return null; } }