Skip to content

Commit

Permalink
[NETBEANS-4311]: Added support for auto-completion of Java Record
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunava Sinha committed Jul 30, 2020
1 parent 08fb876 commit 84ed378
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 29 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Override
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
record
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
R
R1
Readable
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
R
R1
Readable
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Readable
Record
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Readable
Record
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package test;

public class Test {

public record Records <R extends Number, R1 > ( ) {

public static
}

public static void main(String args )
{
record Record1(@Ov ) {}

record Rec( ) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,36 @@ public static NbTestSuite suite() {
public void testBindingUse() throws Exception {
performTest("GenericMethodInvocation", 1231, "boolean b = argO instanceof String str && st", "BindingUse.pass", SOURCE_LEVEL);
}


public void testBeforeLeftRecordBraces() throws Exception {
performTest("Records", 896, null, "implementsKeyword.pass", SOURCE_LEVEL);
}

public void testBeforeRecParamsLeftParen() throws Exception {
performTest("Records", 892, null, "empty.pass", SOURCE_LEVEL);
}

public void testInsideRecParams() throws Exception {
performTest("Records", 894, "R", "typesRecordLocalMembersAndVars.pass", SOURCE_LEVEL);
}

public void testAfterTypeParamInRecParam() throws Exception {
performTest("Records", 890, null, "extendsKeyword.pass", SOURCE_LEVEL);
}

public void testInsideRecAfterStaticKeyWord() throws Exception {
performTest("Records", 918, "R", "typesRecordStaticMembersAndVars.pass", SOURCE_LEVEL);
}

public void testAnnotationInRecordParam() throws Exception {
performTest("Records", 999, null, "override.pass", SOURCE_LEVEL);
}

public void testRecordKeywordInsideClass() throws Exception {
performTest("Records", 1014, "rec", "record.pass", SOURCE_LEVEL);
}

public void noop() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public static JavaCompletionItem createTypeItem(CompilationInfo info, TypeElemen
case ANNOTATION_TYPE:
return new AnnotationTypeItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList);
default:
throw new IllegalArgumentException("kind=" + elem.getKind());
if(elem.getKind().name().equals(TreeShims.RECORD))
return new RecordItem(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, insideNew, addSimpleName, smartType, autoImportEnclosingType, whiteList);
else throw new IllegalArgumentException("kind=" + elem.getKind());
}
}

Expand Down Expand Up @@ -1313,7 +1315,25 @@ protected ImageIcon getBaseIcon() {
return icon;
}
}

static class RecordItem extends ClassItem {

private static final String RECORD = "org/netbeans/modules/editor/resources/completion/record.png"; // NOI18N
private static ImageIcon icon;

private RecordItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) {
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, false, addSimpleName, smartType, autoImport, whiteList);
}

@Override
protected ImageIcon getBaseIcon() {
if (icon == null) {
icon = ImageUtilities.loadImageIcon(RECORD, false);
}
return icon;
}
}

static class AnnotationTypeItem extends ClassItem {

private static final String ANNOTATION = "org/netbeans/modules/editor/resources/completion/annotation_type.png"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,13 @@ public static Element toRecordComponent(Element el) {
public static boolean isRecordComponent(ElementKind kind) {
return "RECORD_COMPONENT".equals(kind.name());
}

public static ElementKind getRecordKind() {
try {
return ElementKind.valueOf(RECORD); //NOI18N
} catch (IllegalArgumentException ex) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public static WhereUsedPanel create(String name, TreePathHandle e, ElementKind k
case FIELD:
case ENUM_CONSTANT:
default: {
panel = new WhereUsedPanelVariable(parent);
if (kind.name().equals("RECORD")) // NOI18N
panel = new WhereUsedPanelClass(parent);
else
panel = new WhereUsedPanelVariable(parent);
break;
}
}
Expand Down

0 comments on commit 84ed378

Please sign in to comment.