Java Code Examples for com.strobel.assembler.metadata.TypeDefinition#isPublic()
The following examples show how to use
com.strobel.assembler.metadata.TypeDefinition#isPublic() .
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: LockProblems.java From huntbugs with Apache License 2.0 | 6 votes |
@AstVisitor(nodes = AstNodes.EXPRESSIONS) public void visit(Expression expr, MethodContext mc) { if (expr.getCode() != AstCode.InvokeVirtual) return; MethodReference mr = (MethodReference) expr.getOperand(); String name = mr.getName(); if (!Types.isObject(mr.getDeclaringType()) || (!name.equals("wait") && !name.startsWith("notify"))) return; TypeReference type = ValuesFlow.reduceType(expr.getArguments().get(0)); if (type == null || !type.getInternalName().startsWith("java/util/concurrent/")) return; TypeDefinition target = type.resolve(); if (target == null || !target.isPublic()) return; MethodDefinition replacement = findReplacement(name, target); if(replacement != null) { mc.report("IncorrectConcurrentMethod", 0, expr, TARGET.create(target), Roles.REPLACEMENT_METHOD.create(replacement)); } }
Example 2
Source File: ReturnNull.java From huntbugs with Apache License 2.0 | 6 votes |
@AstVisitor(nodes = AstNodes.EXPRESSIONS) public void visit(Expression expr, NodeChain nc, MethodContext mc, MethodDefinition md, TypeDefinition td) { if (expr.getCode() == AstCode.Return && !expr.getArguments().isEmpty()) { Expression child = Exprs.getChild(expr, 0); if (child.getCode() == AstCode.AConstNull) { MethodDefinition curMethod = nc.getLambdaMethod(); if (curMethod == null) curMethod = md; String warningType = curMethod.getReturnType().isArray() ? "ArrayReturnNull" : TYPE_TO_WARNING .get(curMethod.getReturnType().getInternalName()); if (warningType != null) { int priority = 0; if (!td.isPublic() || md.isPrivate() || md.isPackagePrivate()) priority = 20; else if (md.isProtected() || md != curMethod) priority = 10; // Method which simply contains "return null": probably stub or something if(nc.getParent() == null && nc.isOnlyChild(expr)) priority += 10; mc.report(warningType, priority, expr.getArguments().get(0), RETURN_TYPE.create(md .getReturnType())); } } } }
Example 3
Source File: StaticFieldFromInstanceMethod.java From huntbugs with Apache License 2.0 | 5 votes |
@AstVisitor(nodes=AstNodes.EXPRESSIONS) public void visit(Expression expr, NodeChain nc, MethodContext mc, MethodDefinition md, TypeDefinition td) { if(expr.getCode() == AstCode.PutStatic) { FieldReference fr = (FieldReference) expr.getOperand(); FieldDefinition fd = fr.resolve(); if(fd != null && fd.isSynthetic()) return; int priority = 0; if(md.isPrivate() || td.isPrivate()) priority += 20; else if(!md.isPublic() || !td.isPublic()) priority += 10; else if(md.isConstructor()) priority += 5; if(nc.isSynchronized() || Flags.testAny(md.getFlags(), Flags.SYNCHRONIZED)) priority += 15; if(Exprs.getChild(expr, 0).getCode() == AstCode.AConstNull) priority += 5; String name = fr.getName().toLowerCase(Locale.ENGLISH); if (fr.getFieldType().getSimpleType() == JvmType.Boolean) { priority += 10; if (name.contains("verbose")) priority += 5; } if (name.contains("debug")) priority += 15; if ((md.getName().equals("start") || md.getName().equals("stop")) && md.getErasedSignature().equals( "(Lorg/osgi/framework/BundleContext;)V") && Types.isInstance(td, "org/osgi/framework/BundleActivator")) { priority += 30; } mc.report("StaticFieldFromInstanceMethod", priority, expr); } }
Example 4
Source File: Naming.java From huntbugs with Apache License 2.0 | 5 votes |
@MethodVisitor public void visitMethod(MethodDefinition md, TypeDefinition td, MethodContext mc) { if (badMethodName(md.getName())) { if (Types.isInstance(td, "org/eclipse/osgi/util/NLS")) return; // javacc generated methods if (td.getName().equals("SimpleCharStream") && (md.getName().equals("ReInit") || md.getName().equals("BeginToken") || md.getName().equals("Done") || md.getName().equals("GetSuffix") || md.getName().equals("GetImage"))) return; if (td.getName().endsWith("TokenManager") && md.getName().equals("ReInit")) return; int priority = 0; if (!td.isPublic()) priority += 20; else { if (td.isFinal()) priority += 3; if (md.isProtected()) priority += 3; else if (md.isPackagePrivate()) priority += 6; else if (md.isPrivate()) priority += 10; } mc.report("BadNameOfMethod", priority); } String javaVersion = getFutureKeywordVersion(md.getName()); if (javaVersion != null) { mc.report("BadNameOfMethodFutureKeyword", AccessLevel.of(md).select(0, 10, 20, 30), JAVA_VERSION.create(javaVersion)); } if (!md.isStatic() && md.isPublic()) { MemberInfo mi = getMistakeFix(md); if (mi != null) { mc.report("BadNameOfMethodMistake", md.isDeprecated() ? 20 : 0, Roles.REPLACEMENT_METHOD.create(mi)); } } }
Example 5
Source File: StaticFieldNonThreadSafe.java From huntbugs with Apache License 2.0 | 5 votes |
@FieldVisitor public void visitField(FieldDefinition fd, FieldContext fc, TypeDefinition td) { if((fd.isPublic() || fd.isProtected()) && (td.isPublic() || td.isProtected()) && fd.isStatic() && !fd.isEnumConstant()) { TypeReference fieldType = fd.getFieldType(); if(!isNotThreadSafe(fieldType)) return; fc.report("StaticNotThreadSafeField", AccessLevel.of(fd).select(0, 20, 100, 100), Roles.FIELD_TYPE.create(fieldType)); } }
Example 6
Source File: Mutability.java From huntbugs with Apache License 2.0 | 5 votes |
@Override protected void visitType(TypeDefinition td) { if(!td.isPublic()) return; for(FieldDefinition fd : td.getDeclaredFields()) { if(!fd.isStatic() && !fd.isFinal() && fd.isPublic()) { getOrCreate(td); return; } } }
Example 7
Source File: UnsafeGetResource.java From huntbugs with Apache License 2.0 | 4 votes |
@MethodVisitor public boolean checkMethod(MethodDefinition md, TypeDefinition td) { return td.isPublic() && !td.isFinal() && !md.isStatic(); }
Example 8
Source File: StartInConstructor.java From huntbugs with Apache License 2.0 | 4 votes |
@MethodVisitor public boolean checkMethod(MethodDefinition md, TypeDefinition td) { return td.isPublic() && !td.isFinal() && !md.isPrivate() && !md.isPackagePrivate(); }
Example 9
Source File: ExposeRepresentation.java From huntbugs with Apache License 2.0 | 4 votes |
@ClassVisitor public boolean checkClass(TypeDefinition td) { return td.isPublic(); }