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;
05:
06: import org.eclipse.jdt.core.dom.ASTNode;
07: import org.eclipse.jdt.ui.text.java.IInvocationContext;
08: import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
09: import org.eclipse.jdt.ui.text.java.IProblemLocation;
10: import org.eclipse.jface.text.IDocument;
11: import org.eclipse.jface.text.contentassist.IContextInformation;
12: import org.eclipse.swt.graphics.Image;
13: import org.eclipse.swt.graphics.Point;
14:
15: public class QuickAssistProcessor implements
16: org.eclipse.jdt.ui.text.java.IQuickAssistProcessor {
17: public IJavaCompletionProposal[] getAssists(
18: IInvocationContext context, IProblemLocation[] locations) {
19: IJavaCompletionProposal[] result = null;
20:
21: if (hasAssists(context)) {
22: result = new IJavaCompletionProposal[] { new DeclaredRootProposal(
23: context) };
24: }
25:
26: return result;
27: }
28:
29: private ASTNode getAncestor(ASTNode node, int type) {
30: ASTNode parent;
31:
32: while ((parent = node.getParent()) != null) {
33: if (parent.getNodeType() == type) {
34: return parent;
35: }
36: node = parent;
37: }
38:
39: return null;
40: }
41:
42: public boolean hasAssists(IInvocationContext context) {
43: ASTNode covered = context.getCoveredNode();
44: ASTNode covering = context.getCoveringNode();
45:
46: if (covered == null)
47: covered = covering;
48:
49: if (covered != null
50: && covered.getNodeType() == ASTNode.SIMPLE_NAME) {
51: return getAncestor(covered, ASTNode.FIELD_DECLARATION) != null;
52: }
53:
54: return false;
55: }
56: }
57:
58: class DeclaredRootProposal implements IJavaCompletionProposal {
59: IInvocationContext m_context;
60:
61: DeclaredRootProposal(IInvocationContext context) {
62: m_context = context;
63: }
64:
65: public int getRelevance() {
66: return 100;
67: }
68:
69: public void apply(IDocument document) {
70: System.out.println(document);
71: }
72:
73: public String getAdditionalProposalInfo() {
74: return null;
75: }
76:
77: public IContextInformation getContextInformation() {
78: return null;
79: }
80:
81: public String getDisplayString() {
82: return "Make a root";
83: }
84:
85: public Image getImage() {
86: return null;
87: }
88:
89: public Point getSelection(IDocument document) {
90: return null;
91: }
92: }
|