1 11 package org.eclipse.jdt.internal.codeassist.select; 12 13 import java.util.List ; 14 15 import org.eclipse.jdt.core.compiler.InvalidInputException; 16 import org.eclipse.jdt.internal.codeassist.SelectionEngine; 17 import org.eclipse.jdt.internal.compiler.ast.*; 18 import org.eclipse.jdt.internal.compiler.parser.JavadocParser; 19 20 23 public class SelectionJavadocParser extends JavadocParser { 24 25 int selectionStart; 26 int selectionEnd; 27 ASTNode selectedNode; 28 29 public SelectionJavadocParser(SelectionParser sourceParser) { 30 super(sourceParser); 31 this.kind = SELECTION_PARSER | TEXT_PARSE; 32 } 33 34 37 public boolean checkDeprecation(int commentPtr) { 38 this.selectionStart = ((SelectionParser)sourceParser).selectionStart; 39 this.selectionEnd = ((SelectionParser)sourceParser).selectionEnd; 40 this.javadocStart = this.sourceParser.scanner.commentStarts[commentPtr]; 41 this.javadocEnd = this.sourceParser.scanner.commentStops[commentPtr]; 42 if (this.javadocStart <= this.selectionStart && this.selectionEnd <= this.javadocEnd) { 43 if (SelectionEngine.DEBUG) { 44 System.out.println("SELECTION in Javadoc:"); } 46 super.checkDeprecation(commentPtr); 47 } else { 48 this.docComment = null; 49 } 50 return false; 51 } 52 53 56 protected boolean commentParse() { 57 this.docComment = new SelectionJavadoc(this.javadocStart, this.javadocEnd); 58 return super.commentParse(); 59 } 60 61 64 protected Object createArgumentReference(char[] name, int dim, boolean isVarargs, Object typeRef, long[] dimPositions, long argNamePos) throws InvalidInputException { 65 Expression expression = (Expression) super.createArgumentReference(name, dim, isVarargs, typeRef, dimPositions, argNamePos); 67 int start = ((TypeReference)typeRef).sourceStart; 69 int end = ((TypeReference)typeRef).sourceEnd; 70 if (start <= this.selectionStart && this.selectionEnd <= end) { 71 selectedNode = expression; 72 this.abort = true; 73 if (SelectionEngine.DEBUG) { 74 System.out.println(" selected argument="+selectedNode); } 76 } 77 return expression; 78 } 79 80 85 protected Object createFieldReference(Object receiver) throws InvalidInputException { 86 int start = (int) (this.identifierPositionStack[0] >>> 32); 87 int end = (int) this.identifierPositionStack[0]; 88 if (start <= this.selectionStart && this.selectionEnd <= end) { 89 selectedNode = (ASTNode) super.createFieldReference(receiver); 90 this.abort = true; 91 if (SelectionEngine.DEBUG) { 92 System.out.println(" selected field="+selectedNode); } 94 } 95 return null; 96 } 97 98 103 protected Object createMethodReference(Object receiver, List arguments) throws InvalidInputException { 104 int memberPtr = this.identifierLengthStack[0] - 1; int start = (int) (this.identifierPositionStack[memberPtr] >>> 32); 106 int end = (int) this.identifierPositionStack[memberPtr]; 107 if (start <= this.selectionStart && this.selectionEnd <= end) { 108 selectedNode = (ASTNode) super.createMethodReference(receiver, arguments); 109 this.abort = true; 110 if (SelectionEngine.DEBUG) { 111 System.out.println(" selected method="+selectedNode); } 113 } 114 return null; 115 } 116 117 122 protected Object createTypeReference(int primitiveToken) { 123 TypeReference typeRef = (TypeReference) super.createTypeReference(primitiveToken); 125 126 if (typeRef.sourceStart <= this.selectionStart && this.selectionEnd <= typeRef.sourceEnd) { 128 if (typeRef instanceof JavadocQualifiedTypeReference) { 130 JavadocQualifiedTypeReference qualifiedTypeRef = (JavadocQualifiedTypeReference) typeRef; 131 int size = qualifiedTypeRef.tokens.length - 1; 132 for (int i=0; i<size; i++) { 133 int start = (int) (qualifiedTypeRef.sourcePositions[i] >>> 32); 134 int end = (int) qualifiedTypeRef.sourcePositions[i]; 135 if (start <= this.selectionStart && this.selectionEnd <= end) { 136 int pos = i + 1; 137 char[][] tokens = new char[pos][]; 138 int ptr = this.identifierPtr - size; 139 System.arraycopy(this.identifierStack, ptr, tokens, 0, pos); 140 long[] positions = new long[pos]; 141 System.arraycopy(this.identifierPositionStack, ptr, positions, 0, pos); 142 selectedNode = new JavadocQualifiedTypeReference(tokens, positions, this.tagSourceStart, this.tagSourceEnd); 143 this.abort = true; if (SelectionEngine.DEBUG) { 145 System.out.println(" selected partial qualified type="+selectedNode); } 147 return typeRef; 148 } 149 } 150 } 152 selectedNode = typeRef; 154 this.abort = true; if (SelectionEngine.DEBUG) { 156 System.out.println(" selected type="+selectedNode); } 158 } 159 return typeRef; 160 } 161 162 166 protected boolean pushParamName(boolean isTypeParam) { 167 if (super.pushParamName(isTypeParam)) { 168 Expression expression = (Expression) astStack[astPtr--]; 169 if (expression.sourceStart <= this.selectionStart && this.selectionEnd <= expression.sourceEnd) { 171 selectedNode = expression; 172 this.abort = true; if (SelectionEngine.DEBUG) { 174 System.out.println(" selected param="+selectedNode); } 176 } 177 } 178 return false; 179 } 180 181 184 protected void updateDocComment() { 185 if (selectedNode instanceof Expression) { 186 ((SelectionJavadoc) this.docComment).selectedNode = (Expression) selectedNode; 187 } 188 } 189 } 190 | Popular Tags |