/** * Get simple unqualified type name. * * @param typ Type Reference. * @return String Unqualified type name. */ private static String getSimpleTypeName(TypeReference typ) { final Map<String, String> mapFullTypeName = ImmutableMap.<String, String>builder() .put("B", "byte") .put("C", "char") .put("D", "double") .put("F", "float") .put("I", "int") .put("J", "long") .put("S", "short") .put("Z", "boolean") .build(); if (typ.isArrayType()) return "Array"; String typName = typ.getName().toString(); if (typName.startsWith("L")) { typName = typName.split("<")[0].substring(1); // handle generics typName = typName.substring(typName.lastIndexOf('/') + 1); // get unqualified name typName = typName.substring(typName.lastIndexOf('$') + 1); // handle inner classes } else { typName = mapFullTypeName.get(typName); } return typName; } }
/** * Get astubx style method signature. {FullyQualifiedEnclosingType}: {UnqualifiedMethodReturnType} * {methodName} ([{UnqualifiedArgumentType}*]) * * @param mtd Method reference. * @return String Method signature. */ // TODO: handle generics and inner classes private static String getSignature(IMethod mtd) { String classType = mtd.getDeclaringClass().getName().toString().replaceAll("/", "\\.").substring(1); classType = classType.replaceAll("\\$", "\\."); // handle inner class String returnType = mtd.isInit() ? null : getSimpleTypeName(mtd.getReturnType()); String strArgTypes = ""; int argi = mtd.isStatic() ? 0 : 1; // Skip 'this' parameter for (; argi < mtd.getNumberOfParameters(); argi++) { strArgTypes += getSimpleTypeName(mtd.getParameterType(argi)); if (argi < mtd.getNumberOfParameters() - 1) strArgTypes += ", "; } return classType + ":" + (returnType == null ? "void " : returnType + " ") + mtd.getName().toString() + "(" + strArgTypes + ")"; } /**
/** * Convert a TypeName back to an Atom. */ protected static Atom type2atom(TypeName type) { return Atom.findOrCreateAsciiAtom(type.toString()); }
@Override public String toString() { String methodName = klass.getName().toString(); return "Func(" + methodName.substring(methodName.lastIndexOf('/')+1) + ')'; }
@Override public boolean contains(String klassName) { return t.getName().toString().substring(1).equals(klassName); } }
/** * @param T a type reference * @return a synthetic class name to represent the synthetic form of this type * @throws IllegalArgumentException if T is null */ public static TypeName getName(TypeReference T) { if (T == null) { throw new IllegalArgumentException("T is null"); } String s = "L$" + T.getName().toString().substring(1); return TypeName.string2TypeName(s); }
/** * @return something like: com.foo.bar.createLargeOrder(IILjava/lang/String;Ljava/sql/Date;)Ljava/lang/Integer; */ @Override public String getSignature() { // TODO: check that we're not calling this often. String s = getDeclaringClass().getName().toString().substring(1).replace('/', '.') + '.' + getName() + getDescriptor(); return s; }
/** * @return something like: com.foo.bar.createLargeOrder(IILjava/lang/String;Ljava/sql/Date;)Ljava/lang/Integer; */ @Override public String getSignature() { // TODO: check that we're not calling this often. String s = getDeclaringClass().getName().toString().substring(1).replace('/', '.') + '.' + getName() + getDescriptor(); return s; }
private boolean isExcluded(IClass cls) { if (this.analysisScope.getExclusions() != null && this.analysisScope.getExclusions().contains(cls.getName().toString())) { // XXX FUUUUU logger.info("Hit exclusions with {}", cls); return true; } else { return false; } }
private boolean isExcluded(IClass cls) { if (this.analysisScope.getExclusions() != null && this.analysisScope.getExclusions().contains(cls.getName().toString())) { // XXX FUUUUU logger.info("Hit exclusions with {}", cls); return true; } else { return false; } }
private static boolean isAPIComponent(final IClass cls) { ClassLoaderReference clr = cls.getClassLoader().getReference(); if (! (clr.equals(ClassLoaderReference.Primordial) || clr.equals(ClassLoaderReference.Extension))) { if (cls.getName().toString().startsWith("Landroid/")) { return true; } return false; } else { return true; } }
private static boolean isExcluded(final IClass cls) { final SetOfClasses set = cls.getClassHierarchy().getScope().getExclusions(); if (set == null) { return false; // exclusions null ==> no exclusions ==> no class is excluded } else { final String clsName = cls.getReference().getName().toString().substring(1); return set.contains(clsName); } }
@Override protected boolean sameMethod(CGNode opNode, String definingMethod) { MethodReference reference = opNode.getMethod().getReference(); String selector = reference.getSelector().toString(); String containingClass = reference.getDeclaringClass().getName().toString(); return definingMethod.equals(containingClass + '/' + selector); }
public static LambdaSummaryClass findOrCreate(CGNode caller, SSAInvokeDynamicInstruction inst) { if (! summaries.containsKey(inst.getBootstrap())) { String bootstrapCls = caller.getMethod().getDeclaringClass().getName().toString().replace("/", "$").substring(1); int bootstrapIndex = inst.getBootstrap().getIndexInClassFile(); TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Lwala/lambda" + '$' + bootstrapCls + '$' + bootstrapIndex); LambdaSummaryClass cls = new LambdaSummaryClass(ref, caller.getClassHierarchy(), inst); caller.getClassHierarchy().addClass(cls); summaries.put(inst.getBootstrap(), cls); } return summaries.get(inst.getBootstrap()); }
public static LambdaSummaryClass findOrCreate(CGNode caller, SSAInvokeDynamicInstruction inst) { if (! summaries.containsKey(inst.getBootstrap())) { String bootstrapCls = caller.getMethod().getDeclaringClass().getName().toString().replace("/", "$").substring(1); int bootstrapIndex = inst.getBootstrap().getIndexInClassFile(); TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Lwala/lambda" + '$' + bootstrapCls + '$' + bootstrapIndex); LambdaSummaryClass cls = new LambdaSummaryClass(ref, caller.getClassHierarchy(), inst); caller.getClassHierarchy().addClass(cls); summaries.put(inst.getBootstrap(), cls); } return summaries.get(inst.getBootstrap()); }
protected Predicate<MethodReference> nameFilter(final String name) { return t -> { System.err.println(t + " " + name); return t.getSelector().equals(AstMethodReference.fnSelector) && t.getDeclaringClass().getName().toString().startsWith('L' + name); }; }
@Override protected void declareFunction(CAstEntity N, WalkContext definingContext) { CAstType.Method methodType = (Method) N.getType(); CAstType owningType = methodType.getDeclaringType(); IClass owner = loader.lookupClass(makeType(owningType).getName()); assert owner != null || exclusions.contains(owningType.getName()) : makeType(owningType).getName().toString() + " not found in " + loader; if (owner != null && N.getQualifiers().contains(CAstQualifier.ABSTRACT)) { ((JavaSourceLoaderImpl) loader).defineAbstractFunction(N, owner); } }
@Override protected void declareFunction(CAstEntity N, WalkContext definingContext) { CAstType.Method methodType = (Method) N.getType(); CAstType owningType = methodType.getDeclaringType(); IClass owner = loader.lookupClass(makeType(owningType).getName()); assert owner != null || exclusions.contains(owningType.getName()) : makeType(owningType).getName().toString() + " not found in " + loader; if (owner != null && N.getQualifiers().contains(CAstQualifier.ABSTRACT)) { ((JavaSourceLoaderImpl) loader).defineAbstractFunction(N, owner); } }
@Test public void testExclusions() throws IOException { AnalysisScope scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("GUIExclusions.txt"), ExclusionsTest.class.getClassLoader()); TypeReference buttonRef = TypeReference.findOrCreate(ClassLoaderReference.Application, StringStuff.deployment2CanonicalTypeString("java.awt.Button")); Assert.assertTrue(scope.getExclusions().contains(buttonRef.getName().toString().substring(1))); } }