@Override public void visit(Method obj) { int flags = obj.getAccessFlags(); if ((flags & doNotConsider) != 0) { return; } String name = obj.getName(); boolean isSynchronized = (flags & Const.ACC_SYNCHRONIZED) != 0; /* * String sig = obj.getSignature(); char firstArg = sig.charAt(1); char * returnValue = sig.charAt(1 + sig.indexOf(')')); boolean firstArgIsRef * = (firstArg == 'L') || (firstArg == '['); boolean returnValueIsRef = * (returnValue == 'L') || (returnValue == '['); * * System.out.println(className + "." + name + " " + firstArgIsRef + " " * + returnValueIsRef + " " + isSynchronized + " " + isNative ); */ if (name.startsWith("get") && !isSynchronized // && returnValueIsRef ) { getMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } else if (name.startsWith("set") && isSynchronized // && firstArgIsRef ) { setMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } } }
@Override public void visitMethod(Method obj) { if (!obj.isPrivate() || obj.isSynthetic()) { return; } super.visitMethod(obj); String methodName = getMethodName(); if (!"writeReplace".equals(methodName) && !"readResolve".equals(methodName) && !"readObject".equals(methodName) && !"readObjectNoData".equals(methodName) && !"writeObject".equals(methodName) && methodName.indexOf("debug") == -1 && methodName.indexOf("Debug") == -1 && methodName.indexOf("trace") == -1 && methodName.indexOf("Trace") == -1 && !Const.CONSTRUCTOR_NAME.equals(methodName) && !Const.STATIC_INITIALIZER_NAME.equals(methodName)) { for(AnnotationEntry a : obj.getAnnotationEntries()) { String typeName = a.getAnnotationType(); if ("Ljavax/annotation/PostConstruct;".equals(typeName) || "Ljavax/annotation/PreDestroy;".equals(typeName)) { return; } } definedPrivateMethods.add(MethodAnnotation.fromVisitedMethod(this)); } }
/** * Add a method annotation for the method which the given visitor is * currently visiting. If the method has source line information, then a * SourceLineAnnotation is added to the method. * * @param visitor * the BetterVisitor * @return this object */ @Nonnull public BugInstance addMethod(PreorderVisitor visitor) { MethodAnnotation methodAnnotation = MethodAnnotation.fromVisitedMethod(visitor); addMethod(methodAnnotation); addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(visitor)); return this; }
private void suppressWarning(int parameter, String pattern) { String className = getDottedClassName(); ClassAnnotation clazz = new ClassAnnotation(className); suppressionMatcher.addSuppressor(new ParameterWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this), parameter)); }
@Override public void visit(Method obj) { if (obj.isAbstract() || BCELUtil.isSynthetic(obj)) { return; } if (!obj.isPublic()) { return; } if (!"clone".equals(getMethodName())) { return; } if (!getMethodSig().startsWith("()")) { return; } hasCloneMethod = true; cloneIsDeprecated = getXMethod().isDeprecated(); cloneMethodAnnotation = MethodAnnotation.fromVisitedMethod(this); cloneOnlyThrowsException = PruneUnconditionalExceptionThrowerEdges.doesMethodUnconditionallyThrowException(XFactory .createXMethod(this)); // ExceptionTable tbl = obj.getExceptionTable(); // throwsExceptions = tbl != null && tbl.getNumberOfExceptions() > 0; }
private void suppressWarning(String pattern) { String className = getDottedClassName(); ClassAnnotation clazz = new ClassAnnotation(className); if (className.endsWith(".package-info")) { suppressionMatcher.addPackageSuppressor(new PackageWarningSuppressor(pattern, getPackageName().replace('/', '.'))); } else if (visitingMethod()) { suppressionMatcher .addSuppressor(new MethodWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this))); } else if (visitingField()) { suppressionMatcher.addSuppressor(new FieldWarningSuppressor(pattern, clazz, FieldAnnotation.fromVisitedField(this))); } else { suppressionMatcher.addSuppressor(new ClassWarningSuppressor(pattern, clazz)); } }
hashCodeIsAbstract = true; hashCodeMethod = MethodAnnotation.fromVisitedMethod(this); if (m.matches()) { if (sigIsObject) { equalsMethod = MethodAnnotation.fromVisitedMethod(this); hasEqualsObject = true; if (obj.isAbstract()) { hasEqualsSelf = true; if (equalsMethod == null) { equalsMethod = MethodAnnotation.fromVisitedMethod(this); if (findSuperImplementor == null) { hasEqualsOther = true; equalsOtherMethod = MethodAnnotation.fromVisitedMethod(this); equalsOtherClass = DescriptorFactory.createClassDescriptor(arg); MethodAnnotation tmp = MethodAnnotation.fromVisitedMethod(this); if (BCELUtil.isSynthetic(obj)) { hasCompareToBridgeMethod = true;
} else if (mapAndKeyLoaded && "get".equals(getNameConstantOperand()) && "(Ljava/lang/Object;)Ljava/lang/Object;".equals(getSigConstantOperand())) { MethodAnnotation ma = MethodAnnotation.fromVisitedMethod(this); bugAccumulator.accumulateBug(mapVariable .annotate(new BugInstance(this, "WMI_WRONG_MAP_ITERATOR", NORMAL_PRIORITY).addClass(this).addMethod(ma)),
List<BugAnnotation> annotation = new ArrayList<>(); annotation.add(ClassAnnotation.fromClassDescriptor(getClassDescriptor())); annotation.add(MethodAnnotation.fromVisitedMethod(this)); annotation.add(SourceLineAnnotation.fromVisitedInstruction(this)); anonymousClassAnnotation.put(getClassDescriptorOperand().getDottedClassName(), annotation);
@Override public void visit(Method obj) { int flags = obj.getAccessFlags(); if ((flags & doNotConsider) != 0) { return; } String name = obj.getName(); boolean isSynchronized = (flags & ACC_SYNCHRONIZED) != 0; /* * String sig = obj.getSignature(); char firstArg = sig.charAt(1); char * returnValue = sig.charAt(1 + sig.indexOf(')')); boolean firstArgIsRef * = (firstArg == 'L') || (firstArg == '['); boolean returnValueIsRef = * (returnValue == 'L') || (returnValue == '['); * * System.out.println(className + "." + name + " " + firstArgIsRef + " " * + returnValueIsRef + " " + isSynchronized + " " + isNative ); */ if (name.startsWith("get") && !isSynchronized // && returnValueIsRef ) { getMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } else if (name.startsWith("set") && isSynchronized // && firstArgIsRef ) { setMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } } }
@Override public void visitMethod(Method obj) { if (!obj.isPrivate() || obj.isSynthetic()) { return; } super.visitMethod(obj); String methodName = getMethodName(); if (!"writeReplace".equals(methodName) && !"readResolve".equals(methodName) && !"readObject".equals(methodName) && !"readObjectNoData".equals(methodName) && !"writeObject".equals(methodName) && methodName.indexOf("debug") == -1 && methodName.indexOf("Debug") == -1 && methodName.indexOf("trace") == -1 && methodName.indexOf("Trace") == -1 && !"<init>".equals(methodName) && !"<clinit>".equals(methodName)) { for(AnnotationEntry a : obj.getAnnotationEntries()) { String typeName = a.getAnnotationType(); if ("Ljavax/annotation/PostConstruct;".equals(typeName) || "Ljavax/annotation/PreDestroy;".equals(typeName)) { return; } } definedPrivateMethods.add(MethodAnnotation.fromVisitedMethod(this)); } }
/** * Add a method annotation for the method which the given visitor is * currently visiting. If the method has source line information, then a * SourceLineAnnotation is added to the method. * * @param visitor * the BetterVisitor * @return this object */ @Nonnull public BugInstance addMethod(PreorderVisitor visitor) { MethodAnnotation methodAnnotation = MethodAnnotation.fromVisitedMethod(visitor); addMethod(methodAnnotation); addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(visitor)); return this; }
private void suppressWarning(int parameter, String pattern) { String className = getDottedClassName(); ClassAnnotation clazz = new ClassAnnotation(className); suppressionMatcher.addSuppressor(new ParameterWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this), parameter)); }
@Override public void visit(Method obj) { if (obj.isAbstract() || BCELUtil.isSynthetic(obj)) { return; } if (!obj.isPublic()) { return; } if (!"clone".equals(getMethodName())) { return; } if (!getMethodSig().startsWith("()")) { return; } hasCloneMethod = true; cloneIsDeprecated = getXMethod().isDeprecated(); cloneMethodAnnotation = MethodAnnotation.fromVisitedMethod(this); cloneOnlyThrowsException = PruneUnconditionalExceptionThrowerEdges.doesMethodUnconditionallyThrowException(XFactory .createXMethod(this)); // ExceptionTable tbl = obj.getExceptionTable(); // throwsExceptions = tbl != null && tbl.getNumberOfExceptions() > 0; }
hashCodeIsAbstract = true; hashCodeMethod = MethodAnnotation.fromVisitedMethod(this); if (m.matches()) { if (sigIsObject) { equalsMethod = MethodAnnotation.fromVisitedMethod(this); hasEqualsObject = true; if (obj.isAbstract()) { hasEqualsSelf = true; if (equalsMethod == null) { equalsMethod = MethodAnnotation.fromVisitedMethod(this); if (findSuperImplementor == null) { hasEqualsOther = true; equalsOtherMethod = MethodAnnotation.fromVisitedMethod(this); equalsOtherClass = DescriptorFactory.createClassDescriptor(arg); MethodAnnotation tmp = MethodAnnotation.fromVisitedMethod(this); if (BCELUtil.isSynthetic(obj)) { hasCompareToBridgeMethod = true;
private void suppressWarning(String pattern) { String className = getDottedClassName(); ClassAnnotation clazz = new ClassAnnotation(className); if (className.endsWith(".package-info")) { suppressionMatcher.addPackageSuppressor(new PackageWarningSuppressor(pattern, getPackageName().replace('/', '.'))); } else if (visitingMethod()) { suppressionMatcher .addSuppressor(new MethodWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this))); } else if (visitingField()) { suppressionMatcher.addSuppressor(new FieldWarningSuppressor(pattern, clazz, FieldAnnotation.fromVisitedField(this))); } else { suppressionMatcher.addSuppressor(new ClassWarningSuppressor(pattern, clazz)); } }
} else if (mapAndKeyLoaded && "get".equals(getNameConstantOperand()) && "(Ljava/lang/Object;)Ljava/lang/Object;".equals(getSigConstantOperand())) { MethodAnnotation ma = MethodAnnotation.fromVisitedMethod(this); bugAccumulator.accumulateBug(mapVariable .annotate(new BugInstance(this, "WMI_WRONG_MAP_ITERATOR", NORMAL_PRIORITY).addClass(this).addMethod(ma)),