01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.correction;
05:
06: import org.eclipse.core.resources.IMarker;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.runtime.CoreException;
09: 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;
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 implements
30: IMarkerResolutionGenerator2 {
31: private static TcPlugin m_plugin = TcPlugin.getDefault();
32:
33: private IJavaElement m_element;
34:
35: private static final String MARKER_ID = "org.terracotta.dso.DeclaringTypeNotInstrumentedMarker";
36:
37: public boolean hasResolutions(IMarker marker) {
38: try {
39: return marker.getType().equals(MARKER_ID);
40: } catch (CoreException ce) {/**/
41: }
42:
43: return false;
44: }
45:
46: private IJavaElement getSelectedElement() {
47: try {
48: ITextEditor editor = ActionUtil.findSelectedTextEditor();
49:
50: if (editor != null) {
51: return JdtUtils.getElementAtOffset(editor);
52: }
53: } catch (CoreException ce) {/**/
54: }
55:
56: return null;
57: }
58:
59: public IMarkerResolution[] getResolutions(IMarker marker) {
60: ArrayList<IMarkerResolution> list = new ArrayList<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(
72: field)) {
73: list.add(new EnsureNotRootResolution(
74: (IField) m_element));
75: } else if (m_plugin.getConfigurationHelper(project)
76: .isTransient(field)) {
77: list.add(new EnsureNotTransientResolution(
78: (IField) m_element));
79: }
80: } else if (m_element.getElementType() == IJavaElement.METHOD) {
81: list.add(new EnsureNotLockedResolution(
82: (IMethod) m_element));
83: }
84: }
85:
86: return list.toArray(new IMarkerResolution[0]);
87: }
88: }
|