org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadocTag Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.codeassist.complete;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.JavadocSingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.parser.JavadocTagConstants;
public class CompletionOnJavadocTag extends JavadocSingleNameReference implements JavadocTagConstants, CompletionOnJavadoc {
public int completionFlags = JAVADOC;
public final static char[][][] NO_CHAR_CHAR_CHAR = new char[0][][];
private char[][][] possibleTags = NO_CHAR_CHAR_CHAR;
public CompletionOnJavadocTag(char[] source, long pos, int tagStart, int tagEnd, char[][][] possibleTags, boolean orphan) {
super(source, pos, tagStart, tagEnd);
this.possibleTags = possibleTags;
if (orphan) this.completionFlags |= ALL_POSSIBLE_TAGS;
}
@Override
public void addCompletionFlags(int flags) {
this.completionFlags |= flags;
}
@Override
public int getCompletionFlags() {
return this.completionFlags;
}
@Override
public StringBuilder printExpression(int indent, StringBuilder output) {
output.append(" 0) {
output.append("\npossible block tags:"); //$NON-NLS-1$
for (int i=0; i 0) {
output.append("\npossible inline tags:"); //$NON-NLS-1$
for (int i=0; i 0) {
output.append("\npossible snippet tags:"); //$NON-NLS-1$
for (int i=0; i');
}
public void filterPossibleTags(Scope scope) {
if (this.possibleTags == null || this.possibleTags.length == 0 || (this.completionFlags & ALL_POSSIBLE_TAGS) != 0) {
return;
}
int kind = scope.kind;
char[][] specifiedTags = null;
switch (kind) {
case Scope.COMPILATION_UNIT_SCOPE:
// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=255752
// Check for FAKE_TYPE_NAME to allow proposals (@see CompletionParser#consumeCompilationUnit)
CompilationUnitDeclaration compilationUnit = scope.referenceCompilationUnit();
if(compilationUnit != null && compilationUnit.isModuleInfo() ) {
specifiedTags = MODULE_TAGS;
break;
}
if (compilationUnit != null &&
(compilationUnit.types.length > 0 && compilationUnit.types[0].name == CompletionParser.FAKE_TYPE_NAME)) {
specifiedTags = CLASS_TAGS;
} else {
specifiedTags = COMPILATION_UNIT_TAGS;
}
break;
case Scope.CLASS_SCOPE:
specifiedTags = CLASS_TAGS;
break;
case Scope.METHOD_SCOPE:
MethodScope methodScope = (MethodScope) scope;
if (methodScope.referenceMethod() == null) {
if (methodScope.initializedField == null) {
specifiedTags = PACKAGE_TAGS;
} else {
specifiedTags = FIELD_TAGS;
}
} else {
specifiedTags = METHOD_TAGS;
}
break;
default:
return;
}
int kinds = this.possibleTags.length;
for (int k=0; k= ClassFileConstants.JDK1_5) {
TypeDeclaration typeDecl = ((ClassScope)scope).referenceContext;
boolean isRecordWithComponent = typeDecl.isRecord() && typeDecl.nRecordComponents >0 ;
if (((ClassScope)scope).referenceContext.binding.isGenericType() || isRecordWithComponent) {
filteredTags[size++] = possibleTag;
}
}
break;
case Scope.COMPILATION_UNIT_SCOPE:
if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
filteredTags[size++] = possibleTag;
}
break;
default:
filteredTags[size++] = possibleTag;
break;
}
} else {
filteredTags[size++] = possibleTag;
}
break;
}
}
}
if (size