/** * 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; } }
public DynamicCodeBody(TypeReference codeName, TypeReference parent, IClassLoader loader, CAstSourcePositionMap.Position sourcePosition, CAstEntity entity, WalkContext context) { super(codeName, parent, loader, sourcePosition); types.put(codeName.getName(), this); this.translationContext = context; this.entity = entity; }
/** * Generates a SSAValue with a NamedKey (or TypeKey if name==null). */ public SSAValue(final int number, final TypeReference type, final MethodReference validIn, final String variableName) { this(number, type, validIn, ((variableName==null)?new TypeKey(type.getName()):new NamedKey(type.getName(), variableName))); }
/** * Returns the Element the type matches exactly the given type. * * @return The Element if found or AndroidComponent.UNKNOWN if not */ public static AndroidComponent explicit(final TypeReference type) { return explicit(type.getName()); }
/** * @return true iff we can treat m as a no-op method */ protected boolean canIgnore(MemberReference m) { TypeReference T = m.getDeclaringClass(); TypeName n = T.getName(); Atom p = n.getPackage(); return (ignoredPackages.contains(p)); }
@Override public IClass getSuperclass() { if (realType.isInterface()) { IClass result = loader.lookupClass(TypeReference.JavaLangObject.getName()); if (result != null) { return result; } else { throw new IllegalStateException("could not find java.lang.Object"); } } else return realType; }
@Override public IClass getSuperclass() { if (realType.isInterface()) { IClass result = loader.lookupClass(TypeReference.JavaLangObject.getName()); if (result != null) { return result; } else { throw new IllegalStateException("could not find java.lang.Object"); } } else return realType; }
/** * @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; }
@SuppressWarnings("unused") private static String typeRefToStr(TypeReference fieldType) throws UTFDataFormatException { Atom className = fieldType.getName().getClassName(); Atom pkgName = fieldType.getName().getPackage(); if ( null == pkgName && null != className ) { return className.toUnicodeString(); } if (null == className ) { } return pkgName.toUnicodeString() + '/' + className.toUnicodeString(); }
@Override public IMethod getMethod(Selector selector) { if (selector.equals(AstMethodReference.fnSelector)) { return functionBody; } else { return loader.lookupClass(superReference.getName()).getMethod(selector); } }
@Override public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) { if (field == null) { throw new IllegalArgumentException("field is null"); } IField resolveAgain = I.getConcreteType().getField(field.getName(), field.getFieldTypeReference().getName()); if (resolveAgain != null) { field = resolveAgain; } return new InstanceFieldKey(I, field); }
/** * @return the IClass that represents the array element type, or null if the element type is a primitive */ public IClass getElementClass() { TypeReference elementType = getReference().getArrayElementType(); if (elementType.isPrimitiveType()) { return null; } return loader.lookupClass(elementType.getName()); }
/** * @return the IClass that represents the innermost array element type, or null if the element type is a primitive */ public IClass getInnermostElementClass() { TypeReference elementType = getReference().getInnermostElementType(); if (elementType.isPrimitiveType()) { return null; } return loader.lookupClass(elementType.getName()); }
@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); } }
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 TypeReference findOrCreateReferenceTo(TypeReference t) { if (t == null) { throw new IllegalArgumentException("t is null"); } TypeName name = t.getName(); if (t.isPrimitiveType()) { return findOrCreate(ClassLoaderReference.Primordial, name.getReferenceTypeForElementType()); } else { return findOrCreate(t.getClassLoader(), name.getReferenceTypeForElementType()); } }
private int registerMultiDimArraysForArrayOfObjectTypes(int dim, int index, ArrayClass aClass) { for (int i = 1; i < dim; i++) { TypeReference jlo = makeArray(TypeReference.JavaLangObject, i); IClass jloClass = null; jloClass = aClass.getClassLoader().lookupClass(jlo.getName()); MutableIntSet set = findOrCreateSparseSetForClass(jloClass); set.add(index); } return dim; }
public static MethodNamePattern patternForReference(MethodReference methodRef) throws UTFDataFormatException { String className = methodRef.getDeclaringClass().getName().toUnicodeString(); String methodName = methodRef.getName().toUnicodeString(); String descriptor = methodRef.getDescriptor().toUnicodeString(); MethodNamePattern pattern = new MethodNamePattern(className, methodName, descriptor); return pattern; } }
@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))); } }