X Tutup
Skip to content

Commit ec14bd5

Browse files
committed
Added Quick Assist Sample and ProblemIdFinder
Change-Id: I46f70f9a4b10577fe737d88171c7eb009672a785 Signed-off-by: Simon Scholz <simon.scholz@vogella.com>
1 parent 8f89fe1 commit ec14bd5

File tree

8 files changed

+160
-0
lines changed

8 files changed

+160
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

com.vogella.jdt.quickfix/.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.vogella.jdt.quickfix</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Quickfix
4+
Bundle-SymbolicName: com.vogella.jdt.quickfix;singleton:=true
5+
Bundle-Version: 1.0.0.qualifier
6+
Bundle-Vendor: VOGELLA
7+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8+
Require-Bundle: org.eclipse.jdt.ui;bundle-version="3.12.0",
9+
org.eclipse.jdt.core;bundle-version="3.12.0",
10+
org.eclipse.core.runtime;bundle-version="3.12.0",
11+
org.eclipse.jface;bundle-version="3.12.0",
12+
org.eclipse.jface.text;bundle-version="3.11.0",
13+
org.eclipse.ui;bundle-version="3.108.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.,\
5+
plugin.xml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension
5+
point="org.eclipse.jdt.ui.quickFixProcessors">
6+
<quickFixProcessor
7+
class="com.vogella.jdt.quickfix.ProblemIdQuickFixProcessor"
8+
id="com.vogella.jdt.quickfix.quickFixProcessor1">
9+
</quickFixProcessor>
10+
</extension>
11+
<extension
12+
point="org.eclipse.jdt.ui.quickAssistProcessors">
13+
<quickAssistProcessor
14+
class="com.vogella.jdt.quickfix.QuickAssistProcessor1"
15+
id="com.vogella.jdt.quickfix.quickAssistProcessor1"
16+
name="Generate Getter And Setter">
17+
</quickAssistProcessor>
18+
</extension>
19+
20+
</plugin>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.vogella.jdt.quickfix;
2+
3+
import org.eclipse.core.runtime.CoreException;
4+
import org.eclipse.jdt.core.ICompilationUnit;
5+
import org.eclipse.jdt.ui.text.java.IInvocationContext;
6+
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
7+
import org.eclipse.jdt.ui.text.java.IProblemLocation;
8+
import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
9+
10+
public class ProblemIdQuickFixProcessor implements IQuickFixProcessor {
11+
12+
@Override
13+
public boolean hasCorrections(ICompilationUnit unit, int problemId) {
14+
15+
System.out.println(problemId);
16+
17+
return false;
18+
}
19+
20+
@Override
21+
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
22+
throws CoreException {
23+
24+
return null;
25+
}
26+
27+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.vogella.jdt.quickfix;
2+
3+
import org.eclipse.core.runtime.CoreException;
4+
import org.eclipse.jdt.core.ICompilationUnit;
5+
import org.eclipse.jdt.core.dom.ASTNode;
6+
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
7+
import org.eclipse.jdt.internal.ui.text.correction.AssistContext;
8+
import org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal;
9+
import org.eclipse.jdt.ui.actions.AddGetterSetterAction;
10+
import org.eclipse.jdt.ui.text.java.IInvocationContext;
11+
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
12+
import org.eclipse.jdt.ui.text.java.IProblemLocation;
13+
import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor;
14+
import org.eclipse.jface.viewers.StyledString;
15+
16+
@SuppressWarnings("restriction")
17+
public class QuickAssistProcessor1 implements IQuickAssistProcessor {
18+
19+
@Override
20+
public boolean hasAssists(IInvocationContext context) throws CoreException {
21+
ASTNode coveredNode = context.getCoveredNode();
22+
23+
return coveredNode.getNodeType() == ASTNode.TYPE_DECLARATION;
24+
}
25+
26+
@Override
27+
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations)
28+
throws CoreException {
29+
return new IJavaCompletionProposal[] { new AbstractJavaCompletionProposal() {
30+
public org.eclipse.jface.viewers.StyledString getStyledDisplayString() {
31+
ICompilationUnit compilationUnit = context.getCompilationUnit();
32+
return new StyledString(
33+
"Generate Getter and setter for " + compilationUnit.findPrimaryType().getElementName());
34+
}
35+
36+
protected int getPatternMatchRule(String pattern, String string) {
37+
// override the match rule since we do not work with a pattern, but just want to open the "Generate Getters and Setters..." dialog
38+
return -1;
39+
};
40+
41+
public void apply(org.eclipse.jface.text.ITextViewer viewer, char trigger, int stateMask, int offset) {
42+
43+
if(context instanceof AssistContext) {
44+
AssistContext assistContext = (AssistContext) context;
45+
AddGetterSetterAction addGetterSetterAction = new AddGetterSetterAction((CompilationUnitEditor)assistContext.getEditor());
46+
47+
addGetterSetterAction.run();
48+
}
49+
50+
}
51+
} };
52+
}
53+
}

0 commit comments

Comments
 (0)
X Tutup