[Soot-list] loading class files with Soot in abc

Patrick LAM plam at sable.mcgill.ca
Sun Feb 5 15:56:43 EST 2006


The attached patch may be useful.  Ondrej: it doesn't appear to be correct
to add 'X' twice to the return value of SourceLocator.getClassesUnder, but
I'm not quite sure about what that method should really do.  We can start
by checking to see if it fixes Oege's problem, though.

pat

On Sun, 5 Feb 2006, Oege de Moor wrote:

>
> thanks, pat!
>
> Unfortunately that doesn't help;
>
> SourceLocator.getClassesUnder(String apath)
>
> still returns a list with multiple copies of the same name X when
> there are X.java and X.class in the same directory. Looking at
> the code, it seems that this method isn't influenced by the
> kind of src_prec option we've set.
>
> On Sun, 5 Feb 2006, Patrick LAM wrote:
>
> > On Sun, 5 Feb 2006, Oege de Moor wrote:
> >
> >> I'm not sure I understand what I should do in abc to take advantage
> >> of your change... can you elaborate a little?
> >
> > Ok, so I committed the only-class option in Soot revision 2285.  In abc,
> > you need to invoke:
> >
> > 	soot.Options.v().set_src_prec(soot.Options.src_prec_only_class);
> >
> > before calling Soot.  Let me know if that's what you need.
> >
> > pat
> >
> >
> >
>
>
-------------- next part --------------
Index: src/soot/SourceLocator.java
===================================================================
--- src/soot/SourceLocator.java	(revision 2284)
+++ src/soot/SourceLocator.java	(working copy)
@@ -106,7 +106,7 @@
     }
 
     public List getClassesUnder(String aPath) {
-        List fileNames = new ArrayList();
+        Set fileSet = new HashSet();
 
 	if (isJar(aPath)) {
 	    List inputExtensions = new ArrayList(2);
@@ -126,7 +126,7 @@
 			if (inputExtensions.contains(entryExtension)) {
 			    entryName = entryName.substring(0, extensionIndex);
 			    entryName = entryName.replace('/', '.');
-			    fileNames.add(entryName);
+			    fileSet.add(entryName);
 			}
 		    }
 		}
@@ -152,28 +152,30 @@
 		    Iterator it = l.iterator();
 		    while (it.hasNext()) {
 			String s = (String) it.next();
-			fileNames.add(files[i].getName() + "." + s);
+			fileSet.add(files[i].getName() + "." + s);
 		    }
 		} else {
 		    String fileName = files[i].getName();
 
 		    if (fileName.endsWith(".class")) {
 			int index = fileName.lastIndexOf(".class");
-			fileNames.add(fileName.substring(0, index));
+			fileSet.add(fileName.substring(0, index));
 		    }
 
 		    if (fileName.endsWith(".jimple")) {
 			int index = fileName.lastIndexOf(".jimple");
-			fileNames.add(fileName.substring(0, index));
+			fileSet.add(fileName.substring(0, index));
 		    }
 
 		    if (fileName.endsWith(".java")) {
 			int index = fileName.lastIndexOf(".java");
-			fileNames.add(fileName.substring(0, index));
+			fileSet.add(fileName.substring(0, index));
 		    }
 		}
 	    }
 	}
+        LinkedList fileNames = new LinkedList(); 
+        fileNames.addAll (fileSet);
         return fileNames;
     }
 


More information about the Soot-list mailing list