8286206: Missing cases for RECORD
Reviewed-by: vromero, jjg
This commit is contained in:
parent
ee4a6c23ee
commit
062db59eeb
@ -86,6 +86,7 @@ import com.sun.source.util.TreePath;
|
||||
import com.sun.source.util.TreePathScanner;
|
||||
import com.sun.source.util.Trees;
|
||||
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||
import com.sun.tools.javac.util.Assert;
|
||||
import com.sun.tools.javac.util.DefinedBy;
|
||||
import com.sun.tools.javac.util.DefinedBy.Api;
|
||||
import com.sun.tools.javac.util.Pair;
|
||||
@ -672,7 +673,7 @@ public abstract class JavadocHelper implements AutoCloseable {
|
||||
//where:
|
||||
private String elementSignature(Element el) {
|
||||
switch (el.getKind()) {
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: case RECORD:
|
||||
return ((TypeElement) el).getQualifiedName().toString();
|
||||
case FIELD:
|
||||
return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName() + ":" + el.asType();
|
||||
@ -698,8 +699,11 @@ public abstract class JavadocHelper implements AutoCloseable {
|
||||
}
|
||||
header.append(")");
|
||||
return header.toString();
|
||||
default:
|
||||
case PACKAGE, STATIC_INIT, INSTANCE_INIT, TYPE_PARAMETER,
|
||||
OTHER, MODULE, RECORD_COMPONENT, BINDING_VARIABLE:
|
||||
return el.toString();
|
||||
default:
|
||||
throw Assert.error(el.getKind().name());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,7 @@ import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.QualifiedNameable;
|
||||
import javax.lang.model.element.RecordComponentElement;
|
||||
import javax.lang.model.element.TypeParameterElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
@ -512,7 +513,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
IS_VOID.negate() :
|
||||
TRUE;
|
||||
case PARAMETERIZED_TYPE -> FALSE; // TODO: JEP 218: Generics over Primitive Types
|
||||
case TYPE_PARAMETER, CLASS, INTERFACE, ENUM -> FALSE;
|
||||
case TYPE_PARAMETER, CLASS, INTERFACE, ENUM, RECORD -> FALSE;
|
||||
default -> TRUE;
|
||||
};
|
||||
addElements(primitivesOrVoid(at), accept, smartFilter, result);
|
||||
@ -526,7 +527,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
}
|
||||
|
||||
private static final Set<Kind> CLASS_KINDS = EnumSet.of(
|
||||
Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE
|
||||
Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.RECORD
|
||||
);
|
||||
|
||||
private Predicate<Element> smartFilterFromList(AnalyzeTask at, TreePath base, Collection<? extends Tree> types, Tree current) {
|
||||
@ -932,7 +933,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
Scope scope = at.trees().getScope(tp);
|
||||
return el -> {
|
||||
switch (el.getKind()) {
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: case RECORD:
|
||||
return at.trees().isAccessible(scope, (TypeElement) el);
|
||||
case PACKAGE:
|
||||
case EXCEPTION_PARAMETER: case PARAMETER: case LOCAL_VARIABLE: case RESOURCE_VARIABLE:
|
||||
@ -1681,15 +1682,39 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
|
||||
private String elementHeader(AnalyzeTask at, Element el, boolean includeParameterNames, boolean useFQN) {
|
||||
switch (el.getKind()) {
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: {
|
||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE, RECORD: {
|
||||
TypeElement type = (TypeElement)el;
|
||||
String fullname = type.getQualifiedName().toString();
|
||||
Element pkg = at.getElements().getPackageOf(el);
|
||||
String name = pkg == null || useFQN ? fullname :
|
||||
proc.maps.fullClassNameAndPackageToClass(fullname, ((PackageElement)pkg).getQualifiedName().toString());
|
||||
String typeParameters = typeParametersOpt(at, type.getTypeParameters(), includeParameterNames);
|
||||
String recordParameters;
|
||||
|
||||
return name + typeParametersOpt(at, type.getTypeParameters(), includeParameterNames);
|
||||
if (el.getKind() == ElementKind.RECORD) {
|
||||
StringBuilder params = new StringBuilder();
|
||||
String sep = "";
|
||||
|
||||
params.append("(");
|
||||
|
||||
for (RecordComponentElement component : type.getRecordComponents()) {
|
||||
params.append(sep);
|
||||
params.append(component.asType());
|
||||
params.append(" ");
|
||||
params.append(component.getSimpleName());
|
||||
sep = ", ";
|
||||
}
|
||||
|
||||
params.append(")");
|
||||
|
||||
recordParameters = params.toString();
|
||||
} else {
|
||||
recordParameters = "";
|
||||
}
|
||||
|
||||
return name + typeParameters + recordParameters;
|
||||
}
|
||||
|
||||
case TYPE_PARAMETER: {
|
||||
TypeParameterElement tp = (TypeParameterElement)el;
|
||||
String name = tp.getSimpleName().toString();
|
||||
@ -1790,7 +1815,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
@Override
|
||||
public String analyzeType(String code, int cursor) {
|
||||
switch (guessKind(code)) {
|
||||
case IMPORT: case METHOD: case CLASS: case ENUM:
|
||||
case IMPORT: case METHOD: case CLASS: case ENUM: case RECORD:
|
||||
case INTERFACE: case ANNOTATION_TYPE: case VARIABLE:
|
||||
return null;
|
||||
default:
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039
|
||||
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039 8286206
|
||||
* @summary Test Completion and Documentation
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -150,6 +150,7 @@ public class CompletionSuggestionTest extends KullaTesting {
|
||||
assertCompletion("class A implements doubl|");
|
||||
assertCompletion("interface A extends doubl|");
|
||||
assertCompletion("enum A implements doubl|");
|
||||
assertCompletion("record R() implements doubl|");
|
||||
assertCompletion("class A<T extends doubl|");
|
||||
}
|
||||
|
||||
@ -330,11 +331,12 @@ public class CompletionSuggestionTest extends KullaTesting {
|
||||
//JDK-8221759:
|
||||
Compiler compiler = new Compiler();
|
||||
Path testOutDir = Paths.get("WithPrivateField");
|
||||
String input = "package field; public class FieldTest { private static String field; private static String field2; }";
|
||||
String input = "package field; public class FieldTest { private static String field; private static String field2; public record R<E>(String s, E e) {} }";
|
||||
compiler.compile(testOutDir, input);
|
||||
addToClasspath(compiler.getPath(testOutDir));
|
||||
assertSignature("field.FieldTest.field|");
|
||||
assertSignature("field.FieldTest.field2|");
|
||||
assertSignature("field.FieldTest.R|", "field.FieldTest.R<E>(java.lang.String s, E e)");
|
||||
}
|
||||
|
||||
public void testMethodsWithNoArguments() throws Exception {
|
||||
@ -785,4 +787,8 @@ public class CompletionSuggestionTest extends KullaTesting {
|
||||
assertCompletion("for (;;s.conta|", (Boolean) null, "contains(");
|
||||
assertCompletion("for (var v : s.conta|", (Boolean) null, "contains(");
|
||||
}
|
||||
|
||||
public void testRecord() {
|
||||
assertCompletion("record R() implements Ru|", true, "Runnable");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user