Java Code Examples for scala.collection.JavaConverters#asJavaIterable()

The following examples show how to use scala.collection.JavaConverters#asJavaIterable() . 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: PartialCallGraph.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Given a call graph and a CHA it creates a list of internal calls. This list indicates source
 * and target methods by their unique within artifact ids existing in the cha.
 * @param cg  {@link ComputedCallGraph}
 * @param cha A Map of {@link ObjectType} and {@link RevisionCallGraph.Type}
 * @return a list of List of Integers that the first element of each int[] is the source method
 *     and the second one is the target method.
 */
private List<List<Integer>> getInternalCalls(final ComputedCallGraph cg,
                                             final Map<ObjectType, OPALType> cha) {
    final Set<List<Integer>> resultSet = new HashSet<>();
    for (final var source : JavaConverters
        .asJavaIterable(cg.callGraph().project().allMethods())) {
        final var targetsMap = cg.callGraph().calls((source));
        if (targetsMap != null && !targetsMap.isEmpty()) {
            for (final var keyValue : JavaConverters.asJavaIterable(targetsMap)) {
                for (final var target : JavaConverters.asJavaIterable(keyValue._2())) {
                    final var call = Arrays.asList(
                        cha.get(source.declaringClassFile().thisType()).getMethods().get(
                            source),
                        cha.get(target.declaringClassFile().thisType()).getMethods().get(target)
                    );
                    resultSet.add(call);
                }
            }
        }
    }
    return new ArrayList<>(resultSet);
}
 
Example 2
Source File: PartialCallGraph.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Given a call graph and a CHA it creates a map of external calls and their call type. This map
 * indicates the source methods by their unique within artifact id existing in the cha, target
 * methods by their {@link FastenURI}, and a map that indicates the call type.
 * @param cg  {@link ComputedCallGraph}
 * @param cha A Map of {@link ObjectType} and {@link RevisionCallGraph.Type}
 * @return A map that each each entry of it is a {@link Pair} of source method's id, and target
 *     method's {@link FastenURI} as key and a map that shows call types as value. call types
 *     map's key is the name of JVM call type and the value is number of invocation by this call
 *     type for this specific edge.
 */
private Map<Pair<Integer, FastenURI>, Map<String, String>> getExternalCalls(
    final ComputedCallGraph cg,
    final Map<ObjectType, OPALType> cha) {
    List<UnresolvedMethodCall> v = new ArrayList<>();

    final var externlCalls = cg.unresolvedMethodCalls();
    final Map<Pair<Integer, FastenURI>, Map<String, String>> result = new HashMap<>();

    for (final var externalCall : JavaConverters.asJavaIterable(externlCalls)) {

        final var call = new MutablePair<>(
            cha.get(externalCall.caller().declaringClassFile().thisType()).getMethods()
                .get(externalCall.caller()),
            getTargetURI(externalCall));
        final var typeOfCall =
            externalCall.caller().instructionsOption().get()[externalCall.pc()].mnemonic();
        putCall(result, call, typeOfCall);
    }

    return result;
}