private static boolean hasExisting( String methname, String methsig, CtBehavior ccms[] ) throws NotFoundException { for( CtBehavior cm : ccms ) if( cm.getName ().equals(methname) && cm.getSignature().equals(methsig ) ) return true; return false; }
public String getDescriptor() { return ctBehavior.getSignature(); } }
private static boolean usesAnonymous(CtBehavior ctBehavior) { return ctBehavior.getSignature().matches(".*(\\$\\d+;).*"); }
public static String getMethodSuffixFromParameterTypes(CtBehavior from) { String ret = ""; String descriptor = Descriptor.toString(from.getSignature()); String[] names = descriptor.substring(1, descriptor.length()-1) .split(","); for (String name : names) { if (name.isEmpty()) { continue; } String[] name_parts = name.split("\\."); ret += "__" + name.replaceAll("\\.", "_"); //ret += "_" + name_parts[name_parts.length-1]; } return ret; }
private boolean compareThrows(CtBehavior refMethod, CtBehavior implMethod, String className) throws NotFoundException { List refNames = new Vector(); CtClass[] refExceptions = refMethod.getExceptionTypes(); for (int i = 0; i < refExceptions.length; i++) { refNames.add(refExceptions[i].getName()); } boolean ch = false; List implNames = new Vector(); CtClass[] implExceptions = implMethod.getExceptionTypes(); for (int i = 0; i < implExceptions.length; i++) { implNames.add(implExceptions[i].getName()); String exceptionName = implExceptions[i].getName(); ch |= assertTrue(className + " " + refMethod.getName() + refMethod.getSignature() + " should not throw " + exceptionName, refNames.contains(exceptionName)); } if (!config.allowThrowsLess) { for (int i = 0; i < refExceptions.length; i++) { String exceptionName = refExceptions[i].getName(); ch |= assertTrue(className + " " + refMethod.getName() + refMethod.getSignature() + " should throw " + exceptionName, implNames.contains(exceptionName)); } } return ch; }
@Override public boolean matches(CtBehavior ctBehavior) { boolean classMatches = true; boolean methodMatches = true; boolean parameterMatches = true; CtClass declaringClass = ctBehavior.getDeclaringClass(); String name = declaringClass.getName(); if (!classPattern.matcher(name).matches()) { classMatches = false; } String methodName = ctBehavior.getName(); if (!methodPattern.matcher(methodName).matches()) { methodMatches = false; } SignatureParser signatureParser = new SignatureParser(); signatureParser.parse(ctBehavior.getSignature()); List<String> parameters = signatureParser.getParameters(); if (parameters.size() != parameterPatterns.size()) { parameterMatches = false; } else { for (int i = 0; i < parameters.size(); i++) { Pattern pattern = parameterPatterns.get(i); if (!pattern.matcher(parameters.get(i)).matches()) { parameterMatches = false; } } } return (classMatches && methodMatches && parameterMatches); }
@Override public boolean matches(CtBehavior ctBehavior) { boolean classMatches = true; boolean methodMatches = true; boolean parameterMatches = true; CtClass declaringClass = ctBehavior.getDeclaringClass(); String name = declaringClass.getName(); if (!classPattern.matcher(name).matches()) { classMatches = false; } String methodName = ctBehavior.getName(); if (!methodPattern.matcher(methodName).matches()) { methodMatches = false; } SignatureParser signatureParser = new SignatureParser(); signatureParser.parse(ctBehavior.getSignature()); List<String> parameters = signatureParser.getParameters(); if (parameters.size() != parameterPatterns.size()) { parameterMatches = false; } else { for (int i = 0; i < parameters.size(); i++) { Pattern pattern = parameterPatterns.get(i); if (!pattern.matcher(parameters.get(i)).matches()) { parameterMatches = false; } } } return (classMatches && methodMatches && parameterMatches); }
/** * Constructs the parameter strings for a behaviour's signature in the same way * as TypeInfo does * * @param behaviour * @return the parameter strings */ private String[] getParameterTypeStringsForSignature(CtBehavior behavior) { String desc = behavior.getSignature(); String[] args = new String[Descriptor.numOfParameters(desc)]; int n = 0; int i = 1; do { i = getParameterTypeString(desc, i, args, n++); } while (i > 0 && n < args.length); return args; }
private void parseMethodReferences(CtClass classFile) throws ClassParseException { for (CtBehavior behavior : classFile.getDeclaredMethods()) { AccessModifier methodAccess = translateAccess(behavior.getModifiers()); List<String> paramsAndReturn = ClassNameTranslator.signatureToClassNames(behavior.getSignature()); for (Iterator<String> i = paramsAndReturn.iterator(); i.hasNext();) { String refTo = i.next(); ClassInfo safeClassInfo = getSafeClassInfo(refTo); ReferenceType referenceType; if (i.hasNext()) { referenceType = ReferenceType.METHOD_PARAM; } else { referenceType = ReferenceType.METHOD_RETURNS; } addReference(new Reference(this, safeClassInfo, referenceType, behavior.getName(), methodAccess)); } if (behavior.getMethodInfo().getExceptionsAttribute() != null) { String[] exceptionNames = behavior.getMethodInfo().getExceptionsAttribute().getExceptions(); for (String exceptionName : exceptionNames) { addReference(new Reference(this, getSafeClassInfo(exceptionName, behavior.getSignature()), ReferenceType.METHOD_THROWS, behavior.getName(), methodAccess)); } } } }