KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > correction > NotInstrumentedResolutionGenerator


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.correction;
5
6 import org.eclipse.core.resources.IMarker;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.runtime.CoreException;
9 import org.eclipse.jdt.core.IField;
10 import org.eclipse.jdt.core.IJavaElement;
11 import org.eclipse.jdt.core.IJavaProject;
12 import org.eclipse.jdt.core.IMethod;
13 import org.eclipse.ui.IMarkerResolution;
14 import org.eclipse.ui.IMarkerResolutionGenerator2;
15 import org.eclipse.ui.texteditor.ITextEditor;
16
17 import org.terracotta.dso.JdtUtils;
18 import org.terracotta.dso.TcPlugin;
19 import org.terracotta.dso.actions.ActionUtil;
20
21 import java.util.ArrayList JavaDoc;
22
23 /**
24  * Example marker resolution. We may have the need to offer up
25  * suggestions to the user about how to deal with problems they've
26  * injected into their code or config.
27  */

28
29 public class NotInstrumentedResolutionGenerator
30   implements IMarkerResolutionGenerator2
31 {
32   private static TcPlugin m_plugin = TcPlugin.getDefault();
33   
34   private IJavaElement m_element;
35
36   private static final String JavaDoc MARKER_ID =
37     "org.terracotta.dso.DeclaringTypeNotInstrumentedMarker";
38   
39   public boolean hasResolutions(IMarker marker) {
40     try {
41       return marker.getType().equals(MARKER_ID);
42     } catch(CoreException ce) {/**/}
43     
44     return false;
45   }
46
47   private IJavaElement getSelectedElement() {
48     try {
49       ITextEditor editor = ActionUtil.findSelectedTextEditor();
50       
51       if(editor != null) {
52         return JdtUtils.getElementAtOffset(editor);
53       }
54     } catch(CoreException ce) {/**/}
55     
56     return null;
57   }
58   
59   public IMarkerResolution[] getResolutions(IMarker marker) {
60     ArrayList JavaDoc<IMarkerResolution> list = new ArrayList JavaDoc<IMarkerResolution>();
61     
62     if((m_element = getSelectedElement()) != null) {
63       IJavaProject javaProject = m_element.getJavaProject();
64       IProject project = javaProject.getProject();
65       
66       list.add(new InstrumentDeclaringTypeResolution(m_element));
67       
68       if(m_element.getElementType() == IJavaElement.FIELD) {
69         IField field = (IField)m_element;
70         
71         if(m_plugin.getConfigurationHelper(project).isRoot(field)) {
72           list.add(new EnsureNotRootResolution((IField)m_element));
73         }
74         else if(m_plugin.getConfigurationHelper(project).isTransient(field)) {
75           list.add(new EnsureNotTransientResolution((IField)m_element));
76         }
77       }
78       else if(m_element.getElementType() == IJavaElement.METHOD) {
79         list.add(new EnsureNotLockedResolution((IMethod)m_element));
80       }
81     }
82     
83     return list.toArray(new IMarkerResolution[0]) ;
84   }
85 }
86
87
Popular Tags