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