/** * Returns true if the given type symbol corresponds to a functional type (in * the TypeScript way). */ public boolean isFunctionalType(TypeSymbol type) { String name = type.getQualifiedName().toString(); return name.startsWith("java.util.function.") // || name.equals(Runnable.class.getName()) // || name.startsWith(JSweetConfig.FUNCTION_CLASSES_PACKAGE + ".") // || (type.isInterface() && (hasAnnotationType(type, FunctionalInterface.class.getName()) || hasAnonymousFunction(type))); }
/** * Returns true if the given type symbol corresponds to a core functional type. */ public boolean isCoreFunctionalType(TypeSymbol type) { String name = type.getQualifiedName().toString(); return name.startsWith("java.util.function.") // || name.equals(Runnable.class.getName()) // || name.startsWith(JSweetConfig.FUNCTION_CLASSES_PACKAGE + ".") // || (type.isInterface() && hasAnonymousFunction(type)); }
} else { if (expression instanceof JCLambda) { if (assignedType.tsym.isInterface() && !context.isFunctionalType(assignedType.tsym)) { JCLambda lambda = (JCLambda) expression; MethodSymbol method = (MethodSymbol) assignedType.tsym.getEnclosedElements().get(0);
if (!origin.isInterface() || (origin.flags() & ANNOTATION) != 0) {
env1 = env1.outer; if (allowDefaultMethods && c.isInterface() && name == names._super && !isStatic(env) && types.isDirectSuperInterface(c, env.enclClass.sym)) {
if (!origin.isInterface() || (origin.flags() & ANNOTATION) != 0) {
env1 = env1.outer; if (c.isInterface() && name == names._super && !isStatic(env) && types.isDirectSuperInterface(c, env.enclClass.sym)) {
/** Check if the method declares or inherits an implementation of .equals() */ public static boolean implementsEquals(Type type, VisitorState state) { Name equalsName = state.getName("equals"); Symbol objectEquals = getOnlyMember(state, state.getSymtab().objectType, "equals"); for (Type sup : state.getTypes().closure(type)) { if (sup.tsym.isInterface()) { continue; } if (ASTHelpers.isSameType(sup, state.getSymtab().objectType, state)) { return false; } Scope scope = sup.tsym.members(); if (scope == null) { continue; } for (Symbol sym : scope.getSymbolsByName(equalsName)) { if (sym.overrides(objectEquals, type.tsym, state.getTypes(), /* checkResult= */ false)) { return true; } } } return false; } }
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { MethodSymbol res = types.implementation(this, origin, checkResult, implFilter); if (res != null) return res; // if origin is derived from a raw type, we might have missed // an implementation because we do not know enough about instantiations. // in this case continue with the supertype as origin. if (types.isDerivedRaw(origin.type) && !origin.isInterface()) return implementation(types.supertype(origin.type).tsym, types, checkResult); else return null; }
public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { Filter<Symbol> filter = new MethodFilter(ms, site); List<MethodSymbol> candidates = List.nil(); for (Symbol s : membersClosure(site, false).getElements(filter)) { if (!site.tsym.isInterface() && !s.owner.isInterface()) { return List.of((MethodSymbol)s); } else if (!candidates.contains(s)) { candidates = candidates.prepend((MethodSymbol)s); } } return prune(candidates); }
/** * Make a compound type from non-empty list of types * * @param bounds the types from which the compound type is formed * @param supertype is objectType if all bounds are interfaces, * null otherwise. */ public Type makeCompoundType(List<Type> bounds) { return makeCompoundType(bounds, bounds.head.tsym.isInterface()); } public Type makeCompoundType(List<Type> bounds, boolean allInterfaces) {
private boolean sideEffectFreeConstructor(TypeSymbol classType, VisitorState state) { if (classType.isInterface()) { return true; } for (String typeName : TYPE_WHITELIST) { if (ASTHelpers.isSameType(classType.type, state.getTypeFromString(typeName), state)) { return true; } } return false; } }
public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { Filter<Symbol> filter = new MethodFilter(ms, site); List<MethodSymbol> candidates = List.nil(); for (Symbol s : membersClosure(site, false).getElements(filter)) { if (!site.tsym.isInterface() && !s.owner.isInterface()) { return List.of((MethodSymbol)s); } else if (!candidates.contains(s)) { candidates = candidates.prepend((MethodSymbol)s); } } return prune(candidates); }
/** * Make an intersection type from non-empty list of types. The list should be ordered according to * {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion. * Hence, this version of makeIntersectionType may not be called during a classfile read. * * @param bounds the types from which the intersection type is formed */ public IntersectionClassType makeIntersectionType(List<Type> bounds) { return makeIntersectionType(bounds, bounds.head.tsym.isInterface()); }
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { MethodSymbol res = types.implementation(this, origin, checkResult, implFilter); if (res != null) return res; // if origin is derived from a raw type, we might have missed // an implementation because we do not know enough about instantiations. // in this case continue with the supertype as origin. if (types.isDerivedRaw(origin.type) && !origin.isInterface()) return implementation(types.supertype(origin.type).tsym, types, checkResult); else return null; }
/** * Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly, * as follows: if all all bounds are interface types, the computed supertype is Object,otherwise * the supertype is simply left null (in this case, the supertype is assumed to be the head of * the bound list passed as second argument). Note that this check might cause a symbol completion. * Hence, this version of setBounds may not be called during a classfile read. * * @param t a type variable * @param bounds the bounds, must be nonempty */ public void setBounds(TypeVar t, List<Type> bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); }
/** * Set the bounds field of the given type variable to reflect a * (possibly multiple) list of bounds. * @param t a type variable * @param bounds the bounds, must be nonempty * @param supertype is objectType if all bounds are interfaces, * null otherwise. */ public void setBounds(TypeVar t, List<Type> bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); }
if (cast.expr.type.tsym.isInterface() || cast.type.tsym.isInterface() || cast.clazz.type.getKind() == TypeKind.TYPEVAR) { print("<any>");
/** Check if the method declares or inherits an implementation of .equals() */ public static boolean implementsEquals(Type type, VisitorState state) { Name equalsName = state.getName("equals"); Symbol objectEquals = getOnlyMember(state, state.getSymtab().objectType, "equals"); for (Type sup : state.getTypes().closure(type)) { if (sup.tsym.isInterface()) { continue; } if (ASTHelpers.isSameType(sup, state.getSymtab().objectType, state)) { return false; } Scope scope = sup.tsym.members(); if (scope == null) { continue; } for (Symbol sym : scope.getSymbolsByName(equalsName)) { if (sym.overrides(objectEquals, type.tsym, state.getTypes(), /* checkResult= */ false)) { return true; } } } return false; } }
private boolean sideEffectFreeConstructor(TypeSymbol classType, VisitorState state) { if (classType.isInterface()) { return true; } for (String typeName : TYPE_WHITELIST) { if (ASTHelpers.isSameType(classType.type, state.getTypeFromString(typeName), state)) { return true; } } return false; } }