2011/08/05 - Jakarta Cactus has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.cactus.eclipse.quickfix;
22
23 import java.util.ArrayList;
24
25 import org.apache.cactus.eclipse.runner.ui.CactusMessages;
26 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.jdt.core.ICompilationUnit;
29 import org.eclipse.jdt.core.IJavaProject;
30 import org.eclipse.jdt.core.JavaModelException;
31 import org.eclipse.jdt.ui.text.java.IInvocationContext;
32 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
33 import org.eclipse.jdt.ui.text.java.IProblemLocation;
34 import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
35
36
37
38
39
40 public class CactusQuickFixProcessor implements IQuickFixProcessor {
41
42
43
44 private static final int IMPORT_NOT_FOUND = 268435846;
45
46
47
48 private static final int IS_CLASSPATH_CORRECT = 16777218;
49
50
51
52 private static final int DEFAULT_RELEVANCE = 90;
53
54
55
56 public boolean hasCorrections(final ICompilationUnit unit, final int problemId) {
57 if (problemId == IMPORT_NOT_FOUND || problemId == IS_CLASSPATH_CORRECT) {
58 return true;
59 }
60 return false;
61 }
62
63
64
65
66 public IJavaCompletionProposal[] getCorrections(
67 final IInvocationContext context,
68 final IProblemLocation[] locations) throws CoreException {
69 if (locations == null || locations.length == 0) {
70 return null;
71 }
72 final ArrayList resultingCollections = new ArrayList();
73 for (int i=0;i< locations.length;i++) {
74 IProblemLocation problemLocation = (IProblemLocation) locations[i];
75 process(context, problemLocation, resultingCollections);
76 }
77 IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[resultingCollections.size()];
78
79 for(int i=0;i<resultingCollections.size();i++) {
80 proposals[i] = (IJavaCompletionProposal) resultingCollections.get(i);
81 }
82 return proposals;
83 }
84
85
86
87
88 private void process(
89 final IInvocationContext context,
90 final IProblemLocation problem,
91 final ArrayList proposals) {
92 if (problem.getProblemId() == 0) {
93 return;
94 }
95
96 final String source;
97 try {
98 source = context.getCompilationUnit().getSource();
99 }
100 catch (final JavaModelException e) {
101 CactusPlugin.log(e.getMessage());
102 return;
103 }
104 final int offset = problem.getOffset();
105 final int length = problem.getLength();
106
107 final String substring = source.substring(offset, offset + length);
108
109
110
111 IJavaProject theWorkingProject = context.getCompilationUnit().getJavaProject();
112
113 boolean cactusProblem = (problem.getProblemId() == IMPORT_NOT_FOUND && substring.startsWith("org.apache.cactus")) ||
114 (problem.getProblemId() == IS_CLASSPATH_CORRECT && isCactusPrefixesMatch(substring));
115
116 if(cactusProblem) {
117 final String name = CactusMessages.getString("Cactus.quickFix.name");
118 proposals.add(new AddCactusClassesCompletionProposal(name, DEFAULT_RELEVANCE, theWorkingProject));
119 }
120 }
121
122
123
124
125
126 private boolean isCactusPrefixesMatch(String prefix) {
127 return (prefix.startsWith("ServletTestCase") ||
128 prefix.startsWith("JspTestCase") ||
129 prefix.startsWith("EJBTestCase") ||
130 prefix.startsWith("JettyTestSetup"));
131 }
132 }