private static List<String> getClasspathMatches(String[] strPathsOrJars) { final String javaClassPath = System.getProperty("java.class.path"); // $NON-NLS-1$ StringTokenizer stPaths = new StringTokenizer(javaClassPath, System.getProperty("path.separator")); // $NON-NLS-1$ if (log.isDebugEnabled()) { log.debug("Classpath = " + javaClassPath); for (int i = 0; i < strPathsOrJars.length; i++) { log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]); } } // find all jar files or paths that end with strPathOrJar ArrayList<String> listPaths = new ArrayList<String>(); String strPath = null; while (stPaths.hasMoreTokens()) { strPath = fixPathEntry(stPaths.nextToken()); if (strPathsOrJars == null) { log.debug("Adding: " + strPath); listPaths.add(strPath); } else { boolean found = false; for (int i = 0; i < strPathsOrJars.length; i++) { if (strPath.endsWith(strPathsOrJars[i])) { found = true; log.debug("Adding " + strPath + " found at " + i); listPaths.add(strPath); break;// no need to look further } } if (!found) { log.debug("Did not find: " + strPath); } } } return listPaths; }
/** * Find classes in the provided path(s)/jar(s) that extend the class(es). * @param searchPathsOrJars - pathnames or jarfiles to search for classes * @param classNames - required parent class(es) or annotations * @param innerClasses - should we include inner classes? * @param contains - classname should contain this string * @param notContains - classname should not contain this string * @param annotations - true if classnames are annotations * * @return List containing discovered classes */ public static List<String> findClassesThatExtend(String[] searchPathsOrJars, final Class<?>[] classNames, final boolean innerClasses, String contains, String notContains, boolean annotations) throws IOException { if (log.isDebugEnabled()) { log.debug("searchPathsOrJars : " + Arrays.toString(searchPathsOrJars)); log.debug("superclass : " + Arrays.toString(classNames)); log.debug("innerClasses : " + innerClasses + " annotations: " + annotations); log.debug("contains: " + contains + " notContains: " + notContains); } // Find all jars in the search path String[] strPathsOrJars = addJarsInPath(searchPathsOrJars); for (int k = 0; k < strPathsOrJars.length; k++) { strPathsOrJars[k] = fixPathEntry(strPathsOrJars[k]); } // Now eliminate any classpath entries that do not "match" the search List<String> listPaths = getClasspathMatches(strPathsOrJars); if (log.isDebugEnabled()) { for (String path : listPaths) { log.debug("listPaths : " + path); } } @SuppressWarnings("unchecked") // Should only be called with classes that extend annotations final Class<? extends Annotation>[] annoclassNames = (Class<? extends Annotation>[]) classNames; Set<String> listClasses = annotations ? new AnnoFilterTreeSet(annoclassNames, innerClasses) : new FilterTreeSet(classNames, innerClasses, contains, notContains); // first get all the classes findClassesInPaths(listPaths, listClasses); if (log.isDebugEnabled()) { log.debug("listClasses.size()="+listClasses.size()); for (String clazz : listClasses) { log.debug("listClasses : " + clazz); } } // // Now keep only the required classes // Set subClassList = findAllSubclasses(superClasses, listClasses, innerClasses); // if (log.isDebugEnabled()) { // log.debug("subClassList.size()="+subClassList.size()); // Iterator tIter = subClassList.iterator(); // while (tIter.hasNext()) { // log.debug("subClassList : " + tIter.next()); // } // } return new ArrayList<String>(listClasses);//subClassList); }
Clone fragments detected by clone detection tool
File path: /apache-jmeter-2.11/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java File path: /apache-jmeter-2.11/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java
Method name: List getClasspathMatches(String[]) Method name: List findClassesThatExtend(String[], Class[], boolean, String, String, boolean)
Number of AST nodes: 2 Number of AST nodes: 2
1
private static List<String> getClasspathMatches(String[] strPathsOrJars) {
1
/**
2
        final String javaClassPath = System.getProperty("java.class.path"); // $NON-NLS-1$
2
     * Find classes in the provided path(s)/jar(s) that extend the class(es).
3
        StringTokenizer stPaths =
3
     * @param searchPathsOrJars - pathnames or jarfiles to search for classes
4
            new StringTokenizer(javaClassPath,
4
     * @param classNames - required parent class(es) or annotations
5
                System.getProperty("path.separator")); // $NON-NLS-1$
5
     * @param innerClasses - should we include inner classes?
6
        if (log.isDebugEnabled()) {
6
     * @param contains - classname should contain this string
7
            log.debug("Classpath = " + javaClassPath);
7
     * @param notContains - classname should not contain this string
8
            for (int i = 0; i < strPathsOrJars.length; i++) {
8
     * @param annotations - true if classnames are annotations
9
                log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
9
     *
10
            }
10
     * @return List containing discovered classes
11
        }
11
     */
12
12
    public static List<String> findClassesThatExtend(String[] searchPathsOrJars,
13
        // find all jar files or paths that end with strPathOrJar
13
                final Class<?>[] classNames, final boolean innerClasses,
14
        ArrayList<String> listPaths = new ArrayList<String>();
14
                String contains, String notContains, boolean annotations)
15
        String strPath = null;
15
                throws IOException  {
16
        while (stPaths.hasMoreTokens()) {
16
        if (log.isDebugEnabled()) {
17
            strPath = fixPathEntry(stPaths.nextToken());
17
            log.debug("searchPathsOrJars : " + Arrays.toString(searchPathsOrJars));
18
            if (strPathsOrJars == null) {
18
            log.debug("superclass : " + Arrays.toString(classNames));
19
                log.debug("Adding: " + strPath);
19
            log.debug("innerClasses : " + innerClasses + " annotations: " + annotations);
20
                listPaths.add(strPath);
20
            log.debug("contains: " + contains + " notContains: " + notContains);
21
            } else {
21
        }
22
                boolean found = false;
22
23
                for (int i = 0; i < strPathsOrJars.length; i++) {
23
        // Find all jars in the search path
24
                    if (strPath.endsWith(strPathsOrJars[i])) {
24
        String[] strPathsOrJars = addJarsInPath(searchPathsOrJars);
25
                        found = true;
25
        for (int k = 0; k < strPathsOrJars.length; k++) {
26
                        log.debug("Adding " + strPath + " found at " + i);
26
            strPathsOrJars[k] = fixPathEntry(strPathsOrJars[k]);
27
                        listPaths.add(strPath);
27
        }
28
                        break;// no need to look further
28
29
                    }
29
        // Now eliminate any classpath entries that do not "match" the search
30
                }
30
        List<String> listPaths = getClasspathMatches(strPathsOrJars);
31
                if (!found) {
31
        if (log.isDebugEnabled()) {
32
                    log.debug("Did not find: " + strPath);
32
            for (String path : listPaths) {
33
                }
33
                log.debug("listPaths : " + path);
34
            }
34
            }
35
        }
35
        }
36
        return listPaths;
36
37
    }
37
        @SuppressWarnings("unchecked") // Should only be called with classes that extend annotations
38
        final Class<? extends Annotation>[] annoclassNames = (Class<? extends Annotation>[]) classNames;
39
        Set<String> listClasses =
40
            annotations ?
41
                new AnnoFilterTreeSet(annoclassNames, innerClasses)
42
                :
43
                new FilterTreeSet(classNames, innerClasses, contains, notContains);
44
        // first get all the classes
45
        findClassesInPaths(listPaths, listClasses);
46
        if (log.isDebugEnabled()) {
47
            log.debug("listClasses.size()="+listClasses.size());
48
            for (String clazz : listClasses) {
49
                log.debug("listClasses : " + clazz);
50
            }
51
        }
52
53
//        // Now keep only the required classes
54
//        Set subClassList = findAllSubclasses(superClasses, listClasses, innerClasses);
55
//        if (log.isDebugEnabled()) {
56
//            log.debug("subClassList.size()="+subClassList.size());
57
//            Iterator tIter = subClassList.iterator();
58
//            while (tIter.hasNext()) {
59
//                log.debug("subClassList : " + tIter.next());
60
//            }
61
//        }
62
63
        return new ArrayList<String>(listClasses);//subClassList);
64
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements1
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.750
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    5
    for (int i = 0; i < strPathsOrJars.length; i++)
    5
    for (int i = 0; i < strPathsOrJars.length; i++)
    11
    for (String path : listPaths)
    Differences
    Expression1Expression2Difference
    java.lang.String[]java.util.ListVARIABLE_TYPE_MISMATCH
    java.lang.String[]java.util.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable strPathsOrJars does not match with type java.util.List<java.lang.String> of variable listPaths
    • Make classes java.lang.String[] and java.util.List extend a common superclass
    Type java.lang.String[] of variable strPathsOrJars does not match with type java.util.List<java.lang.String> of variable listPaths
    • Make classes java.lang.String[] and java.util.List extend a common superclass
    11
    for (String path : listPaths)
    6
    log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
    6
    log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
    Preondition Violations
    Unmatched statement log.debug("strPathsOrJars[" + i + "] : "+ strPathsOrJars[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                    
                                                                              
    12
    log.debug("listPaths : " + path);
    Preondition Violations
    Unmatched statement log.debug("listPaths : " + path); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    log.debug("listPaths : " + path);
    Precondition Violations (5)
    Row Violation
    1Type java.lang.String[] of variable strPathsOrJars does not match with type java.util.List<java.lang.String> of variable listPaths
    2Type java.lang.String[] of variable strPathsOrJars does not match with type java.util.List<java.lang.String> of variable listPaths
    3Unmatched statement log.debug("strPathsOrJars[" + i + "] : "+ strPathsOrJars[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement log.debug("listPaths : " + path); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Clone fragment #1 returns variable i with type int , while Clone fragment #2 returns variable path with type java.lang.String