11package dataTool ;
22
33import java .util .ArrayList ;
4+ import java .util .HashMap ;
45import java .util .HashSet ;
56
7+ import org .eclipse .core .resources .IFile ;
68import org .eclipse .core .resources .IFolder ;
79import org .eclipse .core .resources .IProject ;
810import org .eclipse .core .resources .IWorkspaceRoot ;
@@ -47,11 +49,19 @@ public class DataCallHierarchy {
4749 private String className ;
4850 private String location ;
4951 private ICompilationUnit cUnit ;
52+ private HashMap <String , ArrayList <DataLink >> results ;
53+
54+ public String goTo = null ;
55+ public int goToOffset ;
5056
5157 public DataCallHierarchy () {
5258
5359 }
5460
61+ public void setGoTo (int offset ) {
62+ goToOffset = offset ;
63+ }
64+
5565 public HashSet <IMethod > getCalls (IMethod m ) {
5666 Finder f = Finder .getInstance ();
5767 if (f instanceof UpFinder ) {
@@ -123,11 +133,17 @@ private IMethod getIMethodFromMethodWrapper(MethodWrapper m) {
123133 * @returns String of next method name
124134 * @throws CoreException
125135 */
126- public ArrayList <DataLink > searchProject (String method ) throws CoreException {
127- ArrayList < DataLink > results = new ArrayList <DataLink >();
136+ public HashMap < String , ArrayList <DataLink > > searchProject (String method ) throws CoreException {
137+ results = new HashMap < String , ArrayList <DataLink > >();
128138 String projectName = EnableNavigationAction .project ;
129139 String path = EnableNavigationAction .path ;
130- String projectPath = path .substring (path .indexOf ("/src/" )+5 ,path .lastIndexOf ("/" )).replace ("/" , "." );
140+ String projectPath ;
141+ if (path .contains ("/src/" )) {
142+ projectPath = path .substring (path .indexOf ("/src/" )+5 ,path .lastIndexOf ("/" )).replace ("/" , "." );
143+ }
144+ else {
145+ projectPath = path ;
146+ }
131147 String projectFile = EnableNavigationAction .file ;
132148 IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
133149 IProject project = root .getProject (projectName );
@@ -139,46 +155,27 @@ public ArrayList<DataLink> searchProject(String method) throws CoreException {
139155 cUnit = frag .getCompilationUnit (projectFile );
140156 IType type = cUnit .getType (projectFile .replace (".java" , "" ));
141157 HashSet <IMethod > calls = null ;
158+ ArrayList <DataLink > links = new ArrayList <DataLink >();
142159 for (IMethod im : type .getMethods ()){
143160 if (im .getElementName ().equals (method )) {
144161 calls = getCalls (im );
145162 for (IMethod mem : calls ) {
146- //results += mem.getElementName() + "\n";
147- results .add (new DataLink (mem .getElementName (), mem .toString ()));
163+ links .add (new DataLink (mem , mem .getElementName (), mem .getPath ().toString ()));
148164 searchMatch = mem .toString ();
149165 }
150166 }
151167 }
168+ results .put (Finder .UP , links );
152169 if (calls == null ) {
153- results .add ( processRootDirectory (method ));
170+ results .put ( Finder . DOWN , processRootDirectory (method ));
154171 }
155172 return results ;
156173 }
157174
158- /**
159- * Function to parse the output from the search function above
160- * @param s: String of search results
161- */
162- private void parseSearchResults (String s ) {
163- System .out .println (s );
164- method = s .substring (s .indexOf (" " )+1 ,s .indexOf ("(" ));
165- parameters = s .substring (s .indexOf ("(" ),s .indexOf (")" )+1 );
166- String temp [] = s .substring (s .indexOf ("[" )).split ("\\ [in " );
167- String tempLoc = "" ;
168- for (int i = 1 ; i < temp .length ; i ++) {
169- String str = temp [i ].trim ().replace ("[Working copy] " ,"" ).replace ("]" ,"" );
170- if (i ==1 ) {
171- className = str ;
172- continue ;
173- }
174- tempLoc = str +"." +tempLoc ;
175- }
176- location = tempLoc .substring (0 ,tempLoc .length ()-1 );
177- }
178-
179- private DataLink processRootDirectory (String method ) throws JavaModelException ,CoreException {
175+ private ArrayList <DataLink > processRootDirectory (String method ) throws JavaModelException ,CoreException {
180176 IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
181177 IProject [] projects = root .getProjects ();
178+ ArrayList <DataLink > links = new ArrayList <DataLink >();
182179
183180 // process each project
184181 for (IProject project : projects ) {
@@ -199,7 +196,7 @@ private DataLink processRootDirectory(String method) throws JavaModelException,C
199196 for (IMethod imethod : methods ) {
200197 if (imethod .getElementName ().equals (method )) {
201198 searchMatch = method .toString ();
202- return new DataLink (imethod .getElementName (), imethod .toString ());
199+ links . add ( new DataLink (imethod , imethod .getElementName (),imethod .getPath (). toString () ));
203200 }
204201 }
205202 }
@@ -209,6 +206,10 @@ private DataLink processRootDirectory(String method) throws JavaModelException,C
209206 }
210207
211208 }
212- return new DataLink (DataLink .INVALID , DataLink .INVALID_DESC );
209+ if (links .isEmpty ())
210+ {
211+ links .add (new DataLink (null , DataLink .INVALID , DataLink .INVALID_DESC ));
212+ }
213+ return links ;
213214 }
214215}
0 commit comments