com.ibm.wala.classLoader.IMethod Java Examples

The following examples show how to use com.ibm.wala.classLoader.IMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassHierarchyAnalyzer.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Process class.
 *
 * @param klass Class
 */
private void processClass(IClass klass) {
    Map<Selector, List<IMethod>> interfaceMethods = klass.getDirectInterfaces()
            .stream()
            .flatMap(o -> o.getDeclaredMethods().stream())
            .collect(
                    Collectors.groupingBy(IMethod::getSelector)
            );

    for (IMethod declaredMethod : klass.getDeclaredMethods()) {

        List<IMethod> methodInterfaces = interfaceMethods.get(declaredMethod.getSelector());

        processMethod(klass, declaredMethod, methodInterfaces);
    }
}
 
Example #2
Source File: WalaUtils.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public static CGNode getCGNode(IMethod method, CallGraph cg) {
	logger.debug("Retrieve CGNode for " + method.getSignature());

	MethodReference ref = method.getReference();
	if (ref == null) return null;

	Set<CGNode> cgnode = cg.getNodes(ref);
	if (cgnode.isEmpty()) {
		logger.warn("Number of CGNode(s) for " + method.getSignature() + " is " + cgnode.size());
		return null;
	}
	/*else if (cgnode.size() > 1) {
		logger.warn("Number of CGNode(s) for " + methodSignature + " is " + cgnode.size() +  "  refMethod.sig: " + refMethod.getSignature());
	}*/
					
	return cgnode.iterator().next();
}
 
Example #3
Source File: WalaUtils.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public static IMethod getIMethod(IClassHierarchy cha, String signature) {  // TODO: throw exceptions
	String clazzName = Utils.getFullClassName(signature);
	String selector = signature.substring(clazzName.length()+1); 

	try {
		IClass clazz = WalaUtils.lookupClass(cha, clazzName);
		for (IMethod m: clazz.getAllMethods()) { // DeclaredMethods()) -> only impl./overriden methods
			if (m.getSelector().toString().equals(selector)) {
				return m;
			}
		}
	} catch (ClassNotFoundException e) {
		logger.debug("Classname " + clazzName + " could not be looked up!");
	}
	return null;  // TODO: throw exception
}
 
Example #4
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 6 votes vote down vote up
void inferAlternativeAPIs(Map<Version, Set<IMethod>> version2Api) {
    for (Version v: version2ApiDiff.keySet()) {
        ApiDiff diff = version2ApiDiff.get(v);

        if (diff.actualSemver != null && diff.actualSemver.equals(VersionWrapper.SEMVER.MAJOR)) {
            for (IMethod m: diff.removed) {
                Set<IMethod> alternatives = version2Api.get(v).parallelStream()
                   .filter(api -> !diff.removed.contains(api))  // exclude removed apis
                   .filter(api -> isAlternativeApi(m, api))
                   .collect(Collectors.toSet());

                // if we have three or more alternatives (e.g. renamed methods with one argument)
                // the suggestions will probably be wrong -> do not store any alternatives
                if (alternatives.size() <= 2)
                    diff.alternatives.put(m, alternatives);
            }
        }
    }
}
 
Example #5
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 6 votes vote down vote up
void inferActualSemver(Map<Version, Set<IMethod>> version2Api) {
    Iterator<Version> it = version2ApiDiff.keySet().iterator();
    Version v0 = it.next();

    while (it.hasNext()) {
        Version v1 = it.next();
        VersionWrapper.SEMVER sem = compareApis(version2Api.get(v0), version2Api.get(v1));
        version2ApiDiff.get(v1).actualSemver = sem;

        // determine added/removed APIs
        if (!sem.equals(VersionWrapper.SEMVER.PATCH)) {
            Set<IMethod> removed = new HashSet<IMethod>(version2Api.get(v0));
            removed.removeAll(version2Api.get(v1));
            version2ApiDiff.get(v1).removed = removed;

            Set<IMethod> added = new HashSet<IMethod>(version2Api.get(v1));
            added.removeAll(version2Api.get(v0));
            version2ApiDiff.get(v1).added = added;
        }

        logger.debug(Utils.INDENT2 + "Actual SemVer:: " + v0.toString() + " : " + v1.toString() + "  ->  " + sem.name());
        v0 = v1;
    }
}
 
Example #6
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 6 votes vote down vote up
Map<Version, Set<IMethod>> generatePerVersionApiSet(LibApiStats stats) {
    Map<Version, Set<IMethod>> version2Api = new TreeMap<Version, Set<IMethod>>();

    for (Version v: stats.getVersions()) {
        Set<IMethod> apis = new HashSet<IMethod>();

        for (IMethod api: stats.api2Versions.keySet()) {
            if (stats.api2Versions.get(api).contains(v))
                apis.add(api);
        }

        version2Api.put(v, apis);
    }

    return version2Api;
}
 
Example #7
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 6 votes vote down vote up
protected Map<Version, ApiDiff> run(LibApiStats stats) {

        version2ApiDiff = new TreeMap<Version, ApiDiff>();
        Map<Version, Set<IMethod>> version2Api =  generatePerVersionApiSet(stats);

        for (Version v: version2Api.keySet()) {
            version2ApiDiff.put(v, new ApiDiff(v, version2Api.get(v).size()));
        }

        // infer expected/actual semver
        inferExpectedSemver();
        inferActualSemver(version2Api);
        inferAlternativeAPIs(version2Api);

//        if (logger.isDebugEnabled()) {
        logger.info("======================================");
        logger.info("==  Library: " + stats.libName + "  ==");
        logger.info("======================================");
        printStats();
  //      }

        return version2ApiDiff;
    }
 
Example #8
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public Export(ApiDiff diff, boolean verbose) {
    version = diff.v.toString();
    apiCount = diff.apiCount;
    apiAdditionsCount = diff.added.size();
    apiDeletionsCount = diff.removed.size();
    actualSemver = diff.actualSemver == null? "" : diff.actualSemver.name();
    expectedSemver = diff.expectedSemver == null? "" : diff.expectedSemver.name();

    for (IMethod m: diff.alternatives.keySet()) {
        Set<String> apis = diff.alternatives.get(m).stream().map(IMethod::getSignature).collect(Collectors.toSet());
        alternatives.put(m.getSignature(), apis);
    }

    if (verbose) {
        apiAdditions = diff.added.stream().map(IMethod::getSignature).sorted().collect(Collectors.toSet());
        apiDeletions = diff.removed.stream().map(IMethod::getSignature).sorted().collect(Collectors.toSet());
    }
}
 
Example #9
Source File: PublicInterfaceExtractor.java    From LibScout with Apache License 2.0 6 votes vote down vote up
/**
     * Try to programmatically infer the documented public library interface, i.e., the public methods
     * that the app developer is supposed to use.
     * This filter obfuscated names (id-renaming via ProGuard), public method of anonymous inner-classes and
     * public methods in internal packages (based on keywords)
     * @param cha
     * @return
     */
    public static Set<IMethod> getDocumentedPublicInterface(IClassHierarchy cha) {
        Set<IMethod> methods = getPublicInterface(cha);
        int pubApiCount = methods.size();

        methods = methods.stream()
                .filter(m -> !WalaUtils.isAnonymousInnerClass(m.getDeclaringClass()))  // filter pub methods in anonymous inner classes
                .filter(m -> !isSignatureRenamed(m))   // filter obfuscated names
                .filter(m -> !isLibInternalMethod(m))  // is lib internal based on keywords
                .collect(Collectors.toCollection(HashSet::new));

        ArrayList<IMethod> list = new ArrayList<IMethod>(methods);
        list.sort(Comparator.comparing(IMethod::getSignature));


//        list.forEach(m -> logger.debug(Utils.INDENT + "[DocAPI] " + m.getSignature() + (m.getDeclaringClass().isInterface()? "   [IS_IF_METHOD] " : "  ")));
        logger.debug("[getDocumentedPublicInterface] Retrieved " + list.size() + " doc public APIs  (filtered: " + (pubApiCount-list.size()) + " public APIs)");


        // TODO: entrypoint analysis with code?
        // filter other? find lib entry points (calls within the lib?)
        // -> if pub method is never called, likely to be doc api  (or thread->start -> run)

        return methods;
    }
 
Example #10
Source File: PublicInterfaceExtractor.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public static Set<IMethod> getPublicInterface(IClassHierarchy cha) {
    int classCount = 0;   // how many distinct classes have public methods
    HashSet<IMethod> pubMethods = new HashSet<IMethod>();

    for (IClass clazz: cha) {
        if (!WalaUtils.isAppClass(clazz)) continue;

        Collection<? extends IMethod> methods = clazz.getDeclaredMethods();

        // filter anything but public and non-compiler generated methods
        methods = methods.stream()
                .filter(m -> {
                    int code = AccessFlags.getMethodAccessCode(m);
                    return code > 0 && (code & AccessFlags.getPublicOnlyFilter()) == 0x0;
                })  // if predicate is true, keep in list
                .filter(m -> !(m.isBridge() || m.isSynthetic()))   // filter compiler-generated methods
                .collect(Collectors.toCollection(ArrayList::new));

        if (!methods.isEmpty()) classCount++;
        pubMethods.addAll(methods);
    }

    logger.debug("[getPublicInterface] Retrieved " + pubMethods.size() + " public methods from " + classCount + " distinct classes");
    return pubMethods;
}
 
Example #11
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 6 votes vote down vote up
/**
 * 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 getAstubxSignature(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
      + ")";
}
 
Example #12
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 6 votes vote down vote up
private void analyzeReturnValue(
    AnalysisOptions options,
    AnalysisCache cache,
    IMethod mtd,
    DefinitelyDerefedParams analysisDriver,
    String sign) {
  if (!mtd.getReturnType().isPrimitiveType()) {
    if (analysisDriver == null) {
      analysisDriver = getAnalysisDriver(mtd, options, cache);
    }
    if (analysisDriver.analyzeReturnType() == DefinitelyDerefedParams.NullnessHint.NULLABLE) {
      if (sign.isEmpty()) {
        sign = getSignature(mtd);
      }
      nullableReturns.add(sign);
      LOG(DEBUG, "DEBUG", "Inferred Nullable method return: " + sign);
    }
  }
}
 
Example #13
Source File: ClassHierarchyAnalyzer.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Add method to class hierarchy.
 *
 * @param method Method
 */
private void addMethod(IMethod method) {
    Method methodNode = analysisContext.findOrCreate(method.getReference());
    if (methodNode instanceof InternalMethod) {
        if (!partialCallGraph.getClassHierarchy()
                .containsKey(getClassURI(method.getDeclaringClass()))) {
            addClassToCHA(method.getDeclaringClass());
        }
        var methods = partialCallGraph.getClassHierarchy()
                .get(getClassURI(method.getDeclaringClass())).getMethods();

        if (!methods.containsValue(methodNode.toCanonicalSchemalessURI())) {
            methods.put(counter++, methodNode.toCanonicalSchemalessURI());
        }
    }
}
 
Example #14
Source File: WalaCallgraphConstructor.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Given an IMethod, identify whether it's an object constructor&lt;clinit&gt;, class initializer&lt;clinit&gt; or a method, return the ConstructId
 *
 * @param _method
 * @return
 */
private static com.sap.psr.vulas.shared.json.model.ConstructId getCid(IMethod _method) {
    String qname = "";
    com.sap.psr.vulas.shared.json.model.ConstructId cid = null;
    if (_method.isClinit()) {
        qname = _method.getSignature().substring(0, _method.getSignature().indexOf("<") - 1);
        cid = JavaId.toSharedType(JavaId.parseClassQName(qname).getClassInit());
    } else {
        int p_size = _method.getNumberOfParameters();
        StringBuilder params = new StringBuilder("(");
        String type = "";
        if (_method.isInit()) {
            for (int i = 1; i < p_size; i++) {
                type = getRefType(_method.getParameterType(i));
                if (type.contains("$")) {
                    type = type.substring((type.lastIndexOf("$") + 1), type.length());
                }
                params.append(type);
                if (i != p_size - 1) params.append(",");
            }
            params.append(")");
            qname = _method.getSignature().substring(0, _method.getSignature().indexOf("<") - 1) + params;
            cid = JavaId.toSharedType(JavaId.parseConstructorQName(qname));
        } else {
            for (int i = (_method.isStatic() ? 0 : 1); i < p_size; i++) {
                type = getRefType(_method.getParameterType(i));
                if (type.contains("$")) {
                    type = type.substring((type.lastIndexOf("$") + 1), type.length());
                }
                params.append(type);
                if (i != p_size - 1) params.append(",");
            }
            params.append(")");
            qname = _method.getSignature().substring(0, _method.getSignature().indexOf("(")) + params;
            qname = ClassVisitor.removeParameterQualification(qname);
            cid = JavaId.toSharedType(JavaId.parseMethodQName(qname));
        }
    }
    return cid;
}
 
Example #15
Source File: LibApiStats.java    From LibScout with Apache License 2.0 5 votes vote down vote up
void setDocumentedAPIs(String version, Set<IMethod> docAPIs) {
    for (IMethod api: docAPIs) {
        if (!api2Versions.containsKey(api))
            api2Versions.put(api, new TreeSet<Version>());

        api2Versions.get(api).add(VersionWrapper.valueOf(version));
    }
}
 
Example #16
Source File: LibApiStats.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public Export(LibApiStats stats) {
    this.libName = stats.libName;
    this.versions = stats.versions.stream().map(Version::toString).collect(Collectors.toList());

    this.apiDiffs = stats.version2Diff.values().stream().map(LibApiComparator.ApiDiff::export).collect(Collectors.toList());

    if (LibScoutConfig.libDependencyAnalysis)
        this.libDeps = stats.version2Deps.values().stream().map(DependencyAnalysis.LibDependencies::export).collect(Collectors.toList());

    this.api2Versions = new HashMap<>();
    for (IMethod m: stats.api2Versions.keySet()) {
        this.api2Versions.put(m.getSignature(), stats.api2Versions.get(m).stream().map(Version::toString).collect(Collectors.toList()));
    }
}
 
Example #17
Source File: DependencyAnalysis.java    From LibScout with Apache License 2.0 5 votes vote down vote up
protected Map<Version, DependencyAnalysis.LibDependencies> run(LibApiStats stats) {
    Map<Version, LibDependencies> version2Deps = new TreeMap<Version, LibDependencies>();

    for (Version version: stats.getVersions()) {
        logger.info(Utils.INDENT + "- version: " + version);
        Map<IMethod, Set<CallSiteReference>> api2Dependencies = analyzeDependencies(stats.getDocumentedAPIs(version));
        version2Deps.put(version, new LibDependencies(version, api2Dependencies));
    }


    // debug collect all dependencies (APIs) per lib (incl. all versions)
    Set<String> signatures = new TreeSet<String>();
    version2Deps.values().
            forEach(ld -> {
                ld.api2Dependencies.values()
                    .forEach(set -> {
                        set.forEach(csf -> signatures.add(PackageUtils.getPackageName(csf.getDeclaredTarget().getSignature())));
                    })
                ;}
            );

    logger.info(Utils.INDENT + "-> Dependencies of " + stats.libName);
    signatures.forEach(s -> logger.info(Utils.INDENT2 + "- dep: " + s));
    PackageTree pt = PackageTree.make(signatures);
    pt.print(true);
    /// TODO show empty packages + non-empty on depth == 1

    return version2Deps;
}
 
Example #18
Source File: WalaUtils.java    From LibScout with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up a method by name in a class object. If the method is overloaded,
 * the first one found is returned.
 * @param clazz  IClass object
 * @param methodName name of the method to be looked up
 * @return IMethod if method is declared in clazz, null otherwise
 */
public static IMethod getMethodByName(IClass clazz, String methodName) {
	for (IMethod m: clazz.getAllMethods()) { // DeclaredMethods()) -> only impl./overriden methods
		if (m.getSelector().toString().startsWith(methodName)) {
			return m;
		}
	}
	return null;
}
 
Example #19
Source File: WalaUtils.java    From LibScout with Apache License 2.0 5 votes vote down vote up
/**
 * Hierarchical lookup of an {@link IMethod} via {@link IClass} and {@link CallSiteReference}.
 * @param clazz   the {@link IClass} to start with
 * @param csr  the {@link CallSiteReference}
 * @return  a {@link IMethod} object of the resolved method or null
	 */
public static IMethod resolveMethod(IClass clazz, CallSiteReference csr) {
	IMethod targetMethod = null;

	while (targetMethod == null && !WalaUtils.isObjectClass(clazz)) {
		targetMethod = clazz.getMethod(csr.getDeclaredTarget().getSelector());
		if (targetMethod != null)
			break;

		clazz = clazz.getSuperclass();
	}
	return targetMethod;
}
 
Example #20
Source File: LibApiComparator.java    From LibScout with Apache License 2.0 5 votes vote down vote up
protected static VersionWrapper.SEMVER compareApis(Set<IMethod> s0, Set<IMethod> s1) {
    if (s1.containsAll(s0)) {
        if (s0.size() == s1.size())   // exact match
            return VersionWrapper.SEMVER.PATCH;
        else if (s1.size() > s0.size())  // contains complete set of APIs and additions -> backwards-compatible
            return VersionWrapper.SEMVER.MINOR;
    }
    return VersionWrapper.SEMVER.MAJOR;
}
 
Example #21
Source File: ClassHierarchyAnalyzer.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Process method, it's super methods and interfaces.
 *
 * @param klass          Class
 * @param declaredMethod Method
 * @param interfaces     Interfaces implemented by method
 */
private void processMethod(IClass klass, IMethod declaredMethod, List<IMethod> interfaces) {
    if (declaredMethod.isPrivate()) {
        return;
    }
    IClass superKlass = klass.getSuperclass();
    addMethod(declaredMethod);

    IMethod superMethod = superKlass.getMethod(declaredMethod.getSelector());
    if (superMethod != null) {
        addMethod(superMethod);
    }

    if (interfaces != null) {
        for (IMethod interfaceMethod : interfaces) {
            addMethod(interfaceMethod);
        }
    }

    if (superKlass.isAbstract() && superMethod == null && interfaces == null) {

        Map<Selector, List<IMethod>> derivedInterfaces = superKlass.getDirectInterfaces()
                .stream()
                .flatMap(o -> o.getDeclaredMethods().stream())
                .collect(Collectors.groupingBy(IMethod::getSelector));

        List<IMethod> derivedInterfacesMethods =
                derivedInterfaces.get(declaredMethod.getSelector());

        if (derivedInterfacesMethods != null
                && derivedInterfacesMethods.size() > 0) {
            for (IMethod method : derivedInterfacesMethods) {
                addMethod(method);
            }
        }
    }
}
 
Example #22
Source File: WalaUtils.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public static CGNode getCGNode(String methodSignature, CallGraph cg) {
	logger.debug("Retrieve CGNode for " + methodSignature);

	IMethod refMethod = getIMethod(cg.getClassHierarchy(), methodSignature);
	if (refMethod == null) return null;

	return getCGNode(refMethod, cg);
}
 
Example #23
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 5 votes vote down vote up
/**
 * Accounts the bytecode size of analyzed method for statistics.
 *
 * @param mtd Analyzed method.
 */
private void accountCodeBytes(IMethod mtd) {
  // Get method bytecode size
  if (mtd instanceof ShrikeCTMethod) {
    analyzedBytes += ((ShrikeCTMethod) mtd).getBytecodes().length;
  }
}
 
Example #24
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 5 votes vote down vote up
private DefinitelyDerefedParams getAnalysisDriver(
    IMethod mtd, AnalysisOptions options, AnalysisCache cache) {
  IR ir = cache.getIRFactory().makeIR(mtd, Everywhere.EVERYWHERE, options.getSSAOptions());
  ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg = ir.getControlFlowGraph();
  accountCodeBytes(mtd);
  return new DefinitelyDerefedParams(mtd, ir, cfg);
}
 
Example #25
Source File: SignatureMethodNodeComp.java    From LibScout with Apache License 2.0 5 votes vote down vote up
@Override
public MethodNode comp(IMethod m, TreeConfig config) {
    String desc = normalizeAnonymousInnerClassConstructor(m);
    if (desc == null)
        desc = getFuzzyDescriptor(m);

    String signature = config.keepMethodSignatures? m.getSignature() : "";
    return new MethodNode(config.getHasher().putBytes(desc.getBytes()).hash().asBytes(), signature);
}
 
Example #26
Source File: LibraryApiAnalysis.java    From LibScout with Apache License 2.0 5 votes vote down vote up
private void parseLibrarySDKs(boolean skipBeta) {
    for (File libXML : meta2Code.keySet()) {
        try {
            LibraryDescription ld = XMLParser.readLibraryXML(libXML);

            if (ld.version.matches(".*[a-zA-Z-]+.*") && skipBeta) {  // skip alpha/beta/rc ..
                logger.info("Skip lib: " + ld.name + "   version: " + ld.version);
                continue;
            }

            logger.info("- Parse lib: " + ld.name + "   version: " + ld.version);

            // if stats file not existing add new one
            if (!libName2Stats.containsKey(ld.name))
                libName2Stats.put(ld.name, new LibApiStats(ld.name));

            libName2Stats.get(ld.name).addVersion(ld.version);

            // extract public documented API
            IClassHierarchy cha = createClassHierarchy(meta2Code.get(libXML));
            Set<IMethod> docAPIs = PublicInterfaceExtractor.getDocumentedPublicInterface(cha);
            libName2Stats.get(ld.name).setDocumentedAPIs(ld.version, docAPIs);
            logger.info(Utils.INDENT + "- " + docAPIs.size() + " documented public APIs");

        } catch (Exception e) {
            logger.warn(Utils.stacktrace2Str(e));
        }
    }
}
 
Example #27
Source File: PublicInterfaceExtractor.java    From LibScout with Apache License 2.0 5 votes vote down vote up
/**
 * Check if package name includes a subpackage named 'internal'
 * @param m
 * @return
 */
private static boolean isLibInternalMethod(IMethod m) {
    // check a part of the package contains 'internal'
    List<String> pckgFragments = PackageUtils.parsePackage(m.getDeclaringClass());

    for (String frag: pckgFragments) {
        if ("internal".equals(frag)) {
            return true;
        }
    }

    return false;
}
 
Example #28
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 5 votes vote down vote up
private boolean shouldCheckMethod(IMethod mtd) {
  return !mtd.isPrivate()
      && !mtd.isAbstract()
      && !mtd.isNative()
      && !isAllPrimitiveTypes(mtd)
      && !mtd.getDeclaringClass().getClassLoader().getName().toString().equals("Primordial");
}
 
Example #29
Source File: DefinitelyDerefedParams.java    From NullAway with MIT License 5 votes vote down vote up
/**
 * The constructor for the analysis class.
 *
 * @param method The target method of the analysis.
 * @param ir The IR code for the target method.
 * @param cfg The Control Flow Graph of the target method.
 */
DefinitelyDerefedParams(
    IMethod method, IR ir, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg) {
  this.method = method;
  this.ir = ir;
  this.cfg = cfg;
  prunedCFG = null;
}
 
Example #30
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 5 votes vote down vote up
/**
 * Checks if all parameters and return value of a method have primitive types.
 *
 * @param mtd Method.
 * @return boolean True if all parameters and return value are of primitive type, otherwise false.
 */
private static boolean isAllPrimitiveTypes(IMethod mtd) {
  if (!mtd.getReturnType().isPrimitiveType()) return false;
  for (int i = (mtd.isStatic() ? 0 : 1); i < mtd.getNumberOfParameters(); i++) {
    if (!mtd.getParameterType(i).isPrimitiveType()) return false;
  }
  return true;
}