1 11 package org.eclipse.jdt.internal.codeassist.complete; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.ast.JavadocSingleNameReference; 15 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 16 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; 17 import org.eclipse.jdt.internal.compiler.lookup.MethodScope; 18 import org.eclipse.jdt.internal.compiler.lookup.Scope; 19 import org.eclipse.jdt.internal.compiler.parser.JavadocTagConstants; 20 21 public class CompletionOnJavadocTag extends JavadocSingleNameReference implements JavadocTagConstants, CompletionOnJavadoc { 22 public int completionFlags = JAVADOC; 23 public final static char[][][] NO_CHAR_CHAR_CHAR = new char[0][][]; 24 private char[][][] possibleTags = NO_CHAR_CHAR_CHAR; 25 26 public CompletionOnJavadocTag(char[] source, long pos, int tagStart, int tagEnd, char[][][] possibleTags, boolean orphan) { 27 super(source, pos, tagStart, tagEnd); 28 this.possibleTags = possibleTags; 29 if (orphan) this.completionFlags |= ALL_POSSIBLE_TAGS; 30 } 31 32 35 public void addCompletionFlags(int flags) { 36 this.completionFlags |= flags; 37 } 38 39 44 public int getCompletionFlags() { 45 return this.completionFlags; 46 } 47 48 51 public StringBuffer printExpression(int indent, StringBuffer output) { 52 output.append("<CompleteOnJavadocTag:"); output.append('@'); 54 if (this.token != null) super.printExpression(indent, output); 55 char[][] blockTags = this.possibleTags[BLOCK_IDX]; 57 if (blockTags != null) { 58 int length=blockTags.length; 59 if (length > 0) { 60 output.append("\npossible block tags:"); for (int i=0; i<length; i++) { 62 output.append("\n - "); output.append(blockTags[i]); 64 } 65 output.append('\n'); 66 } 67 } 68 char[][] inlineTags = this.possibleTags[INLINE_IDX]; 70 if (inlineTags != null) { 71 int length=inlineTags.length; 72 if (length > 0) { 73 output.append("\npossible inline tags:"); for (int i=0; i<length; i++) { 75 output.append("\n - "); output.append(inlineTags[i]); 77 } 78 output.append('\n'); 79 } 80 } 81 return output.append('>'); 82 } 83 84 public void filterPossibleTags(Scope scope) { 85 if (this.possibleTags == null || this.possibleTags.length == 0 || (this.completionFlags & ALL_POSSIBLE_TAGS) != 0) { 86 return; 87 } 88 int kind = scope.kind; 89 char[][] specifiedTags = null; 90 switch (kind) { 91 case Scope.COMPILATION_UNIT_SCOPE: 92 case Scope.CLASS_SCOPE: 93 specifiedTags = CLASS_TAGS; 94 break; 95 case Scope.METHOD_SCOPE: 96 MethodScope methodScope = (MethodScope) scope; 97 if (methodScope.referenceMethod() == null) { 98 if (methodScope.initializedField == null) { 99 specifiedTags = PACKAGE_TAGS; 100 } else { 101 specifiedTags = FIELD_TAGS; 102 } 103 } else { 104 specifiedTags = METHOD_TAGS; 105 } 106 break; 107 default: 108 return; 109 } 110 int kinds = this.possibleTags.length; 111 for (int k=0; k<kinds; k++) { 112 int length = this.possibleTags[k].length; 113 int specLenth = specifiedTags.length; 114 char[][] filteredTags = new char[length][]; 115 int size = 0; 116 for (int i=0; i<length; i++) { 117 char[] possibleTag = this.possibleTags[k][i]; 118 for (int j=0; j<specLenth; j++) { 119 if (possibleTag[0] == specifiedTags[j][0] && CharOperation.equals(possibleTag, specifiedTags[j])) { 120 if (possibleTag == TAG_PARAM) { 121 switch (scope.kind) { 122 case Scope.CLASS_SCOPE: 123 if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { 124 if (((ClassScope)scope).referenceContext.binding.isGenericType()) { 125 filteredTags[size++] = possibleTag; 126 } 127 } 128 break; 129 case Scope.COMPILATION_UNIT_SCOPE: 130 if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { 131 filteredTags[size++] = possibleTag; 132 } 133 break; 134 default: 135 filteredTags[size++] = possibleTag; 136 break; 137 } 138 } else { 139 filteredTags[size++] = possibleTag; 140 } 141 break; 142 } 143 } 144 } 145 if (size<length) { 146 System.arraycopy(filteredTags, 0, this.possibleTags[k] = new char[size][], 0, size); 147 } 148 } 149 } 150 151 156 public char[][] getPossibleBlockTags() { 157 return this.possibleTags[BLOCK_IDX]; 158 } 159 160 165 public char[][] getPossibleInlineTags() { 166 return this.possibleTags[INLINE_IDX]; 167 } 168 } 169 | Popular Tags |