@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)); } }
private boolean isSynthetic(String methodName, String methodSig) { for (Method m : cls.getMethods()) { if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) { return m.isSynthetic(); } } return false; }
private boolean isSynthetic(String methodName, String methodSig) { for (Method m : cls.getMethods()) { if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) { return m.isSynthetic(); } } return false; }
@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)); } }
/** * returns whether this method has an equivalent method that is synthetic, which implies this method is constrained by some Generified interface. We could * compare parameters but that is a bunch of work that probably doesn't make this test any more precise, so just return true if method name and synthetic is * found. * * @param methodName * the method name to look for a synthetic twin of * @param methodSig * the method signature to lookfor a synthetic twin of * @return if a synthetic twin is found */ private boolean methodHasSyntheticTwin(String methodName, String methodSig) { for (Method m : cls.getMethods()) { if (m.isSynthetic() && m.getName().equals(methodName) && !m.getSignature().equals(methodSig)) { return true; } } return false; }
/** * returns whether this method has an equivalent method that is synthetic, which * implies this method is constrained by some Generified interface. We could * compare parameters but that is a bunch of work that probably doesn't make * this test any more precise, so just return true if method name and synthetic * is found. * * @param methodName the method name to look for a synthetic twin of * @param methodSig the method signature to lookfor a synthetic twin of * @return if a synthetic twin is found */ private boolean methodHasSyntheticTwin(String methodName, String methodSig) { for (Method m : cls.getMethods()) { if (m.isSynthetic() && m.getName().equals(methodName) && !m.getSignature().equals(methodSig)) { return true; } } return false; }
/** * overrides the visitor to filter out constructors. * * @param obj * the code to parse */ @Override public void visitCode(Code obj) { if (Values.CONSTRUCTOR.equals(methodName) || Values.STATIC_INITIALIZER.equals(methodName)) { return; } Method m = getMethod(); if (m.isSynthetic()) { return; } if (!interfaceMethods.contains(new QMethod(methodName, m.getSignature()))) { super.visitCode(obj); } }
/** * overrides the visitor to filter out constructors. * * @param obj * the code to parse */ @Override public void visitCode(Code obj) { if (Values.CONSTRUCTOR.equals(methodName) || Values.STATIC_INITIALIZER.equals(methodName)) { return; } Method m = getMethod(); if (m.isSynthetic()) { return; } if (!interfaceMethods.contains(new QMethod(methodName, m.getSignature()))) { super.visitCode(obj); } }
private List<FieldOrMethod> getMembers(JavaClass javaClass, List<JavaClass> interfaces) { Set<String> methodNames = new HashSet<>(); ArrayList<FieldOrMethod> members = new ArrayList<>(); List<Method> allInterfacesMethods = getAllInterfacesMethods(interfaces); List<Method> methods = new ArrayList<>(); methods.addAll(Arrays.asList(javaClass.getMethods())); methods.addAll(allInterfacesMethods); for (Method m : methods) { if ((m.isPublic() || m.isProtected()) && !m.isSynthetic()) { members.add(m); methodNames.add(m.getName()); } } for (Field f : javaClass.getFields()) { if ((f.isPublic() || f.isProtected()) && !f.isSynthetic() && !methodNames.contains(f.getName())) { members.add(f); } } return members; }
/** * looks for methods that contain a catch block and an ATHROW opcode * * @param code * the context object of the current code block * @param method * the context object of the current method * @return if the class throws exceptions */ public boolean prescreen(Code code, Method method) { if (method.isSynthetic()) { return false; } CodeException[] ce = code.getExceptionTable(); if (CollectionUtils.isEmpty(ce)) { return false; } BitSet bytecodeSet = getClassContext().getBytecodeSet(method); return (bytecodeSet != null) && bytecodeSet.get(Constants.ATHROW); }
if (m.isSynthetic()) { BitSet bytecodeSet = ClassContext.getBytecodeSet(cls, m); isSyntheticForParentCall = (bytecodeSet != null) && bytecodeSet.get(Constants.INVOKESPECIAL);
if (m.isSynthetic()) { BitSet bytecodeSet = ClassContext.getBytecodeSet(cls, m); isSyntheticForParentCall = (bytecodeSet != null) && bytecodeSet.get(Const.INVOKESPECIAL);
/** * looks for methods that contain a catch block and an ATHROW opcode * * @param code * the context object of the current code block * @param method * the context object of the current method * @return if the class throws exceptions */ public boolean prescreen(Code code, Method method) { if (method.isSynthetic()) { return false; } CodeException[] ce = code.getExceptionTable(); if (CollectionUtils.isEmpty(ce)) { return false; } BitSet bytecodeSet = getClassContext().getBytecodeSet(method); return (bytecodeSet != null) && bytecodeSet.get(Const.ATHROW); }
/** * overrides the visitor to prescreen the method to look for throws calls and only forward onto bytecode scanning if there * * @param obj * the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { Method method = getMethod(); if (!method.isSynthetic() && prescreen(method)) { stack.resetForMethodEntry(this); super.visitCode(obj); } }
/** * overrides the visitor to prescreen the method to look for throws calls and only forward onto bytecode scanning if there * * @param obj * the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { Method method = getMethod(); if (!method.isSynthetic() && prescreen(method)) { stack.resetForMethodEntry(this); super.visitCode(obj); } }
/** * implements the visitor to reset the opcode stack, Note that the synthetic check is done in both visitMethod and visitCode as visitMethod is not a proper * listener stopping method. We don't want to report issues reported in visitMethod if it is synthetic, but we also don't want it to get into sawOpcode, so * that is why it is done here as well. * * @param obj * the currently parsed code block */ @Override public void visitCode(Code obj) { Method m = getMethod(); if (m.isSynthetic()) { return; } isPublic = m.isPublic(); stack.resetForMethodEntry(this); super.visitCode(obj); }
/** * implements the visitor to reset the opcode stack, Note that the synthetic check is done in both visitMethod and visitCode as visitMethod is not a proper * listener stopping method. We don't want to report issues reported in visitMethod if it is synthetic, but we also don't want it to get into sawOpcode, so * that is why it is done here as well. * * @param obj * the currently parsed code block */ @Override public void visitCode(Code obj) { Method m = getMethod(); if (m.isSynthetic()) { return; } isPublic = m.isPublic(); stack.resetForMethodEntry(this); super.visitCode(obj); }
private void processMethod(Method m, JavaClass clazz, TypeDefinition typeDefinition, boolean isInterface, Set<String> methodsSet) { String name = m.getName(); if (isPrivateGoogleApiMember(name)) return; if (m.isSynthetic() || (!m.isPublic() && !m.isProtected())) { return; } // TODO: Pete: won't generate static initializers as invalid typescript properties if (clazz.isInterface() && name.equals("<clinit>")) { return; } loadBaseMethods(clazz); //loaded in "baseMethodNames" and "baseMethods" String tabs = getTabs(this.indent + 1); cacheMethodBySignature(m); //cached in "mapNameMethod" //generate base method content if (baseMethodNames.contains(name)) { for (Method bm : baseMethods) { if (bm.getName().equals(name)) { String sig = getMethodFullSignature(bm); if (!mapNameMethod.containsKey(sig)) { mapNameMethod.put(sig, bm); methodsSet.add(generateMethodContent(clazz, typeDefinition, isInterface, tabs, bm)); } } } } methodsSet.add(generateMethodContent(clazz, typeDefinition, isInterface, tabs, m)); }
/** * implements the visitor to see if the method has parameters * * @param obj * the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { try { Method m = getMethod(); if (m.isSynthetic()) { return; } if (m.isStatic() || m.isPrivate() || Values.CONSTRUCTOR.equals(m.getName())) { parmSigs = SignatureUtils.getParameterSlotAndSignatures(m.isStatic(), m.getSignature()); if (!parmSigs.isEmpty() && prescreen(m)) { state = State.SAW_NOTHING; bugs = new HashMap<>(); downwardBranchTarget = -1; super.visitCode(obj); for (BugInfo bi : bugs.values()) { bugReporter.reportBug(bi.bug); } } } } finally { bugs = null; } }
/** * implements the visitor to look for non public methods that have an @Transactional annotation applied to it. Spring only scans public methods for special * handling. It also looks to see if the exceptions thrown by the method line up with the declared exceptions handled in the @Transactional annotation. * * @param obj * the currently parse method */ @Override public void visitMethod(Method obj) { if (getMethod().isSynthetic()) { return; } methodTransType = getTransactionalType(obj); if ((methodTransType != TransactionalType.NONE) && !obj.isPublic()) { bugReporter .reportBug(new BugInstance(this, BugType.JPAI_TRANSACTION_ON_NON_PUBLIC_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(cls, obj)); } if ((methodTransType == TransactionalType.WRITE) && (runtimeExceptionClass != null)) { try { Set<JavaClass> annotatedRollBackExceptions = getAnnotatedRollbackExceptions(obj); Set<JavaClass> declaredExceptions = getDeclaredExceptions(obj); reportExceptionMismatch(obj, annotatedRollBackExceptions, declaredExceptions, false, BugType.JPAI_NON_SPECIFIED_TRANSACTION_EXCEPTION_HANDLING); reportExceptionMismatch(obj, declaredExceptions, annotatedRollBackExceptions, true, BugType.JPAI_UNNECESSARY_TRANSACTION_EXCEPTION_HANDLING); } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } } super.visitMethod(obj); }