KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > attributes > SootAttributesJavaHover


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.attributes;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.eclipse.ui.*;
27 import org.eclipse.ui.texteditor.AbstractTextEditor;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29
30
31
32 import org.eclipse.core.resources.*;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IAdaptable;
35 import org.eclipse.core.runtime.IPath;
36 import org.eclipse.jdt.ui.text.java.hover.*;
37 import org.eclipse.jdt.core.*;
38 import ca.mcgill.sable.soot.*;
39
40 public class SootAttributesJavaHover extends AbstractSootAttributesHover implements IJavaEditorTextHover {
41
42     private ArrayList JavaDoc fileNames;
43     
44     public IJavaElement getJavaElement(AbstractTextEditor textEditor) {
45         IEditorInput input= textEditor.getEditorInput();
46         return (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class);
47     
48     }
49     
50
51     protected void computeAttributes() {
52         setAttrsHandler(new SootAttributesHandler());
53         createAttrFileNames();
54         SootAttributeFilesReader safr = new SootAttributeFilesReader();
55         Iterator JavaDoc it = fileNames.iterator();
56         while (it.hasNext()){
57             String JavaDoc fileName = ((IPath)it.next()).toOSString();
58             AttributeDomProcessor adp = safr.readFile(fileName);
59             if (adp != null) {
60                 
61                 getAttrsHandler().setAttrList(adp.getAttributes());
62             }
63         }
64         
65         SootPlugin.getDefault().getManager().addToFileWithAttributes((IFile)getRec(), getAttrsHandler());
66             
67         
68     }
69     private String JavaDoc createAttrFileNames() {
70         fileNames = new ArrayList JavaDoc();
71         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
72         sb.append(SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getLocation().toOSString());
73         sb.append(sep);
74         sb.append("sootOutput");
75         sb.append(sep);
76         sb.append("attributes");
77         sb.append(sep);
78         String JavaDoc dir = sb.toString();
79         IContainer c = (IContainer)SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getFolder("sootOutput"+sep+"attributes"+sep);
80         try {
81         
82             IResource [] files = c.members();
83             for (int i = 0; i < files.length; i++){
84                 Iterator JavaDoc it = getPackFileNames().iterator();
85                 while (it.hasNext()){
86                     
87                     String JavaDoc fileNameToMatch = (String JavaDoc)it.next();
88                     if (files[i].getName().matches(fileNameToMatch+"[$].*") || files[i].getName().matches(fileNameToMatch+"\\."+"xml")){
89                         fileNames.add(files[i].getLocation());
90                     }
91                 }
92             }
93         }
94         catch(CoreException e){
95         }
96         sb.append(getPackFileName());
97         sb.append(".xml");
98     
99         return sb.toString();
100     }
101     
102     protected void addSootAttributeMarkers() {
103         
104         if (getAttrsHandler() == null)return;
105         if (getAttrsHandler().getAttrList() == null) return;
106         Iterator JavaDoc it = getAttrsHandler().getAttrList().iterator();
107         HashMap JavaDoc markerAttr = new HashMap JavaDoc();
108         
109         while (it.hasNext()) {
110             SootAttribute sa = (SootAttribute)it.next();
111             if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) &&
112                 ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue;
113             
114             markerAttr.put(IMarker.LINE_NUMBER, new Integer JavaDoc(sa.getJavaStartLn()));
115         
116             try {
117                 MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker");
118             }
119             catch(CoreException e) {
120                 System.out.println(e.getMessage());
121             }
122         
123         }
124
125     }
126     
127     
128     protected String JavaDoc getAttributes(AbstractTextEditor editor) {
129         JavaAttributesComputer jac = new JavaAttributesComputer();
130         SootAttributesHandler handler = jac.getAttributesHandler(editor);
131
132         if (handler != null){
133         
134             return handler.getJavaAttribute(getLineNum());
135         }
136         else {
137             return null;
138         }
139     }
140     
141
142 }
143
Popular Tags