Java Code Examples for com.strobel.assembler.metadata.TypeDefinition#getExplicitInterfaces()
The following examples show how to use
com.strobel.assembler.metadata.TypeDefinition#getExplicitInterfaces() .
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: Naming.java From huntbugs with Apache License 2.0 | 6 votes |
@ClassVisitor public void visitClass(TypeDefinition td, ClassContext cc) { if (td.isAnonymous() || td.isSynthetic()) return; String name = td.getSimpleName(); if (Character.isLetter(name.charAt(0)) && !Character.isUpperCase(name.charAt(0)) && name.indexOf('_') == -1) { cc.report("BadNameOfClass", td.isPublic() ? 0 : 15); } if (name.endsWith("Exception") && !Types.isInstance(td, "java/lang/Throwable")) { cc.report("BadNameOfClassException", td.isPublic() ? 0 : 15); } TypeReference superClass = td.getBaseType(); if (superClass != null && superClass.getSimpleName().equals(name)) { cc.report("BadNameOfClassSameAsSuperclass", td.isPublic() ? 0 : 15, Roles.SUPERCLASS.create(superClass)); } for (TypeReference iface : td.getExplicitInterfaces()) { if (iface.getSimpleName().equals(name)) { cc.report("BadNameOfClassSameAsInterface", td.isPublic() ? 0 : 15, Roles.INTERFACE.create(iface)); } } }
Example 2
Source File: Types.java From huntbugs with Apache License 2.0 | 6 votes |
public static boolean isInstance(TypeReference type, String wantedType) { if (type == null || type.isPrimitive()) return false; if (wantedType.equals("java/lang/Object")) return true; if (type.getInternalName().equals(wantedType)) return true; if (type.isArray()) { if(!wantedType.startsWith("[")) return false; return isInstance(type.getElementType(), wantedType.substring(1)); } TypeDefinition td = type.resolve(); if (td == null) return false; for (TypeReference iface : td.getExplicitInterfaces()) { if (isInstance(iface, wantedType)) return true; } TypeReference bt = td.getBaseType(); if (bt == null) return false; return isInstance(bt, wantedType); }
Example 3
Source File: RedundantInterfaces.java From huntbugs with Apache License 2.0 | 5 votes |
@ClassVisitor public void visit(TypeDefinition td, ClassContext cc) { TypeDefinition baseType = td.getBaseType().resolve(); if(baseType == null || Types.isObject(baseType)) return; for(TypeReference tr : td.getExplicitInterfaces()) { if(tr.getInternalName().equals("java/io/Serializable")) { continue; } if(Types.isInstance(baseType, tr)) { cc.report("RedundantInterface", td.isPublic() ? 0 : 10, Roles.INTERFACE.create(tr)); } } }
Example 4
Source File: Hierarchy.java From huntbugs with Apache License 2.0 | 5 votes |
@Override protected void visitType(TypeDefinition td) { TypeHierarchy th = getOrCreate(td); th.flags = td.getFlags(); link(th, td.getBaseType()); for (TypeReference id : td.getExplicitInterfaces()) link(th, id); }
Example 5
Source File: Types.java From huntbugs with Apache License 2.0 | 5 votes |
/** * @param type type to check * @return true if all superclasses and superinterfaces could be loaded */ public static boolean hasCompleteHierarchy(TypeDefinition type) { if(type == null) return false; if(type.isArray()) return hasCompleteHierarchy(type.getElementType().resolve()); TypeReference base = type.getBaseType(); if(base != null && !hasCompleteHierarchy(base.resolve())) return false; for(TypeReference tr : type.getExplicitInterfaces()) { if(!hasCompleteHierarchy(tr.resolve())) return false; } return true; }