public boolean isNested() { return isInnerClass() || isLocalClass(); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { if (type == null) { return false; } return type.isLocalClass() || type.isAnonymous(); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { if (type == null) { return false; } return type.isLocalClass() || type.isAnonymous(); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { if (type == null) { return false; } return type.isLocalClass() || type.isAnonymous(); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { return type != null && (type.isLocalClass() || type.isAnonymous()); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { return type != null && (type.isLocalClass() || type.isAnonymous()); }
private static boolean isLocalOrAnonymous(final TypeDefinition type) { return type != null && (type.isLocalClass() || type.isAnonymous()); }
public boolean isNested() { return isInnerClass() || isLocalClass(); }
public boolean isNested() { return isInnerClass() || isLocalClass(); }
private static TypeReference findLocalType(final TypeReference type) { if (type != null) { final TypeDefinition resolvedType = type.resolve(); if (resolvedType != null && resolvedType.isLocalClass()) { return resolvedType; } final TypeReference declaringType = type.getDeclaringType(); if (declaringType != null) { return findLocalType(declaringType); } } return null; }
private static TypeReference findLocalType(final TypeReference type) { if (type != null) { final TypeDefinition resolvedType = type.resolve(); if (resolvedType != null && resolvedType.isLocalClass()) { return resolvedType; } final TypeReference declaringType = type.getDeclaringType(); if (declaringType != null) { return findLocalType(declaringType); } } return null; }
private static TypeReference findLocalType(final TypeReference type) { if (type != null) { final TypeDefinition resolvedType = type.resolve(); if (resolvedType != null && resolvedType.isLocalClass()) { return resolvedType; } final TypeReference declaringType = type.getDeclaringType(); if (declaringType != null) { return findLocalType(declaringType); } } return null; }
private void addTypeMembers(final TypeDeclaration astType, final TypeDefinition type) { for (final FieldDefinition field : type.getDeclaredFields()) { astType.addChild(createField(field), Roles.TYPE_MEMBER); } for (final MethodDefinition method : type.getDeclaredMethods()) { if (method.isConstructor()) { astType.addChild(createConstructor(method), Roles.TYPE_MEMBER); } else { astType.addChild(createMethod(method), Roles.TYPE_MEMBER); } } final List<TypeDefinition> nestedTypes = new ArrayList<>(); for (final TypeDefinition nestedType : type.getDeclaredTypes()) { final TypeReference declaringType = nestedType.getDeclaringType(); if (!nestedType.isLocalClass() && type.isEquivalentTo(declaringType)) { if (nestedType.isAnonymous()) { _typeDeclarations.put(type.getInternalName(), new SoftReference<>(astType)); } else { nestedTypes.add(nestedType); } } } sortNestedTypes(nestedTypes); for (final TypeDefinition nestedType : nestedTypes) { astType.addChild(createTypeNoCache(nestedType), Roles.TYPE_MEMBER); } }
private void addTypeMembers(final TypeDeclaration astType, final TypeDefinition type) { for (final FieldDefinition field : type.getDeclaredFields()) { astType.addChild(createField(field), Roles.TYPE_MEMBER); } for (final MethodDefinition method : type.getDeclaredMethods()) { if (method.isConstructor()) { astType.addChild(createConstructor(method), Roles.TYPE_MEMBER); } else { astType.addChild(createMethod(method), Roles.TYPE_MEMBER); } } final List<TypeDefinition> nestedTypes = new ArrayList<>(); for (final TypeDefinition nestedType : type.getDeclaredTypes()) { final TypeReference declaringType = nestedType.getDeclaringType(); if (!nestedType.isLocalClass() && type.isEquivalentTo(declaringType)) { if (nestedType.isAnonymous()) { _typeDeclarations.put(type.getInternalName(), new SoftReference<>(astType)); } else { nestedTypes.add(nestedType); } } } sortNestedTypes(nestedTypes); for (final TypeDefinition nestedType : nestedTypes) { astType.addChild(createTypeNoCache(nestedType), Roles.TYPE_MEMBER); } }
private boolean isContextWithinTypeInstance(final TypeReference type) { final MethodReference method = context.getCurrentMethod(); if (method != null) { final MethodDefinition resolvedMethod = method.resolve(); if (resolvedMethod != null && resolvedMethod.isStatic()) { return false; } } final TypeReference scope = context.getCurrentType(); for (TypeReference current = scope; current != null; current = current.getDeclaringType()) { if (MetadataResolver.areEquivalent(current, type)) { return true; } final TypeDefinition resolved = current.resolve(); if (resolved != null && resolved.isLocalClass()) { final MethodReference declaringMethod = resolved.getDeclaringMethod(); if (declaringMethod != null) { final MethodDefinition resolvedDeclaringMethod = declaringMethod.resolve(); if (resolvedDeclaringMethod != null && resolvedDeclaringMethod.isStatic()) { break; } } } } return false; }
private boolean isContextWithinTypeInstance(final TypeReference type) { final MethodReference method = context.getCurrentMethod(); if (method != null) { final MethodDefinition resolvedMethod = method.resolve(); if (resolvedMethod != null && resolvedMethod.isStatic()) { return false; } } final TypeReference scope = context.getCurrentType(); for (TypeReference current = scope; current != null; current = current.getDeclaringType()) { if (MetadataResolver.areEquivalent(current, type)) { return true; } final TypeDefinition resolved = current.resolve(); if (resolved != null && resolved.isLocalClass()) { final MethodReference declaringMethod = resolved.getDeclaringMethod(); if (declaringMethod != null) { final MethodDefinition resolvedDeclaringMethod = declaringMethod.resolve(); if (resolvedDeclaringMethod != null && resolvedDeclaringMethod.isStatic()) { break; } } } } return false; }
if (resolved != null && resolved.isLocalClass()) { final MethodReference declaringMethod = resolved.getDeclaringMethod();
if (resolved != null && resolved.isLocalClass()) { final MethodReference declaringMethod = resolved.getDeclaringMethod();
@ClassVisitor public void visitClass(TypeDefinition td, ClassContext cc) { isSerializable = Types.isInstance(td, "java/io/Serializable"); if(Types.isInstance(td, "java/util/Comparator") && !td.isAnonymous() && !td.isLocalClass() && !isSerializable) { int priority = 0; for(FieldDefinition fd : td.getDeclaredFields()) { TypeReference fieldType = fd.getFieldType(); while(fieldType.isArray()) fieldType = fieldType.getElementType(); if(fieldType.isPrimitive()) continue; if(Types.isInstance(fieldType, "java/io/Serializable")) { priority+=10; if(priority > 20) break; } } cc.report("ComparatorIsNotSerializable", priority, SHOULD_IMPLEMENT.create("java/io/Serializable")); } }
@AstVisitor(nodes=AstNodes.EXPRESSIONS, methodName="<clinit>") public void visit(Expression expr, NodeChain nc, MethodContext mc, TypeDefinition td) { if(expr.getOperand() instanceof MemberReference) { MemberReference mr = (MemberReference) expr.getOperand(); TypeReference tr = mr.getDeclaringType(); TypeDefinition subType = tr == null ? null : tr.resolve(); if (subType != null && (subType.isAnonymous() || subType.isLocalClass())) { subType = subType.getBaseType().resolve(); } if (subType != null && !td.isEquivalentTo(subType) && Types.isInstance(subType, td) && nc .getLambdaMethod() == null) { mc.report("InitializerRefersSubclass", td.isNonPublic() || subType.isNonPublic() ? 5 : 0, expr, Roles.SUBCLASS.create(subType)); } } } }