Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge delivery to master after 12.6-rc1 #3268

Merged
merged 12 commits into from Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4664,7 +4664,7 @@ private void addKeywordsForClassBody(Env env) {
&& env.getController().getTreeUtilities().getPathElementOfKind(Tree.Kind.INTERFACE, env.getPath()) != null) {
results.add(itemFactory.createKeywordItem(DEFAULT_KEYWORD, SPACE, anchorOffset, false));
}
if (isRecordSupported(env)) {
if (isRecordSupported(env) && Utilities.startsWith(RECORD_KEYWORD, prefix)) {
results.add(itemFactory.createKeywordItem(RECORD_KEYWORD, SPACE, anchorOffset, false));
}
addPrimitiveTypeKeywords(env);
Expand All @@ -4682,7 +4682,7 @@ private void addKeywordsForBlock(Env env) {
results.add(itemFactory.createKeywordItem(kw, SPACE, anchorOffset, false));
}
}
if (isRecordSupported(env)) {
if (isRecordSupported(env) && Utilities.startsWith(RECORD_KEYWORD, prefix)) {
results.add(itemFactory.createKeywordItem(RECORD_KEYWORD, SPACE, anchorOffset, false));
}
if (Utilities.startsWith(RETURN_KEYWORD, prefix)) {
Expand Down
Expand Up @@ -33,7 +33,7 @@
*/
public class JavaCompletionTask114FeaturesTest extends CompletionTestBase {

private static String SOURCE_LEVEL = "14"; //NOI18N
private static final String SOURCE_LEVEL = "14"; //NOI18N

public JavaCompletionTask114FeaturesTest(String testName) {
super(testName);
Expand Down Expand Up @@ -78,9 +78,21 @@ public void testAnnotationInRecordParam() throws Exception {
performTest("Records", 999, null, "override.pass", SOURCE_LEVEL);
}

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

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

public void testRecordKeywordInsideMethodIfPrefixDoesntMatch() throws Exception {
performTest("Records", 1014, "someprefix", "empty.pass", SOURCE_LEVEL);
}

public void testRecordKeywordInsideClassIfPrefixDoesntMatch() throws Exception {
performTest("Records", 844, "someprefix", "empty.pass", SOURCE_LEVEL);
}

public void testVariableNameSuggestion() throws Exception {
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview");
Expand Down
Expand Up @@ -28,22 +28,23 @@
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.editor.hints.Severity;
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
import org.netbeans.spi.java.hints.Hint;
import org.netbeans.spi.java.hints.HintContext;
import org.netbeans.spi.java.hints.JavaFix;
import org.netbeans.spi.java.hints.TriggerTreeKind;
import org.openide.util.NbBundle.Messages;

@Hint(displayName = "#DN_ConvertTextBlockToString", description = "#DESC_ConvertTextBlockToString", category = "general", minSourceVersion = "13")
@Hint(displayName = "#DN_ConvertTextBlockToString", description = "#DESC_ConvertTextBlockToString", category = "rules15", severity = Severity.HINT)
@Messages({
"DN_ConvertTextBlockToString=Convert Text block to String",
"DESC_ConvertTextBlockToString=Text Block may not be supported in older versions of java older then 13"
"DESC_ConvertTextBlockToString=Converts java 15 Text Blocks back to regular Strings."
})
public class ConvertTextBlockToString {

@TriggerTreeKind(Tree.Kind.STRING_LITERAL)
@Messages("ERR_ConvertTextBlockToString=Text block may not be supported")//NOI18N
@Messages("ERR_ConvertTextBlockToString=Text block can be converted to String")//NOI18N
public static ErrorDescription computeWarning(HintContext ctx) {
TokenSequence<?> ts = ctx.getInfo().getTokenHierarchy().tokenSequence();
if (ts == null) {
Expand Down Expand Up @@ -89,8 +90,8 @@ protected String getText() {
protected void performRewrite(TransformationContext ctx) {
ExpressionTree ext = ctx.getWorkingCopy().getTreeMaker().Literal(orignalStringArr[orignalStringArr.length - 1]);
if (orignalStringArr.length > 1) {
ext = ctx.getWorkingCopy().getTreeMaker().Binary(Tree.Kind.PLUS, buildTree(orignalStringArr, orignalStringArr.length - 2, ctx), (ExpressionTree) ext);
if (orignalStringArr[orignalStringArr.length - 1].equals("")) {
ext = ctx.getWorkingCopy().getTreeMaker().Binary(Tree.Kind.PLUS, buildTree(orignalStringArr, orignalStringArr.length - 2, ctx), ext);
if (orignalStringArr[orignalStringArr.length - 1].isEmpty()) {
ext = (((BinaryTree) ext).getLeftOperand());
}
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ public void newLineAtEnd() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -85,7 +85,7 @@ public void simpleTest() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -121,7 +121,7 @@ public void multipleNewLine() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -156,7 +156,7 @@ public void newLineAfter() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -197,7 +197,7 @@ public void manyLineTextBlock() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -228,7 +228,7 @@ public void twoLineTextBlock() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -260,7 +260,7 @@ public void twoNewLines() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -290,7 +290,7 @@ public void slashConvert() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -321,7 +321,7 @@ public void escapeCharTextBlock() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -356,7 +356,7 @@ public void escapeCharTextBlock2() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("3:18-3:21:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package helloworld;\n"
Expand Down Expand Up @@ -387,7 +387,7 @@ public void textBlockAsParameter1() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("4:27-4:30:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("4:27-4:30:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand Down Expand Up @@ -419,7 +419,7 @@ public void textBlockAsParameter2() throws Exception {
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertTextBlockToString.class)
.findWarning("2:27-2:30:verifier:" + Bundle.ERR_ConvertTextBlockToString())
.findWarning("2:27-2:30:hint:" + Bundle.ERR_ConvertTextBlockToString())
.applyFix()
.assertCompilable()
.assertOutput("class myClass{\n"
Expand Down
21 changes: 21 additions & 0 deletions java/java.lsp.server/vscode/src/extension.ts
Expand Up @@ -42,6 +42,7 @@ import * as launcher from './nbcode';
import {NbTestAdapter} from './testAdapter';
import { asRanges, StatusMessageRequest, ShowStatusMessageParams, QuickPickRequest, InputBoxRequest, TestProgressNotification, DebugConnector,
TextEditorDecorationCreateRequest, TextEditorDecorationSetNotification, TextEditorDecorationDisposeNotification,
SetTextEditorDecorationParams
} from './protocol';
import * as launchConfigurations from './launchConfigurations';

Expand Down Expand Up @@ -603,6 +604,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
}
});
let decorations = new Map<string, TextEditorDecorationType>();
let decorationParamsByUri = new Map<vscode.Uri, SetTextEditorDecorationParams>();
c.onRequest(TextEditorDecorationCreateRequest.type, param => {
let decorationType = vscode.window.createTextEditorDecorationType(param);
decorations.set(decorationType.key, decorationType);
Expand All @@ -616,13 +618,32 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
);
if (editorsWithUri.length > 0) {
editorsWithUri[0].setDecorations(decorationType, asRanges(param.ranges));
decorationParamsByUri.set(editorsWithUri[0].document.uri, param);
}
}
});
let disposableListener = vscode.window.onDidChangeVisibleTextEditors(editors => {
editors.forEach(editor => {
let decorationParams = decorationParamsByUri.get(editor.document.uri);
if (decorationParams) {
let decorationType = decorations.get(decorationParams.key);
if (decorationType) {
editor.setDecorations(decorationType, asRanges(decorationParams.ranges));
}
}
});
});
context.subscriptions.push(disposableListener);
c.onNotification(TextEditorDecorationDisposeNotification.type, param => {
let decorationType = decorations.get(param);
if (decorationType) {
decorations.delete(param);
decorationType.dispose();
decorationParamsByUri.forEach((value, key, map) => {
if (value.key == param) {
map.delete(key);
}
});
}
});
handleLog(log, 'Language Client: Ready');
Expand Down
Expand Up @@ -43,7 +43,7 @@ javac.classpath=\
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.5
javac.source=1.6
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
Expand Down
Expand Up @@ -42,7 +42,7 @@ javac.classpath=\
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.5
javac.source=1.6
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
Expand Down
2 changes: 1 addition & 1 deletion nbi/infra/build/.common/common.properties
Expand Up @@ -100,7 +100,7 @@ nb.target.build=jar
# global script
# * ${nb.custom.tasks.cls} - points the netbeans project's build script to the
# location of the built custom tasks
nb.platform.home=-Dplatforms.JDK_1.5.home=${java.home}/..
nb.platform.home=-Dplatforms.JDK_1.5.home=${java.home}
nb.platform.home.macos=-Dplatforms.JDK_1.5.home=${java.home}
nb.ignore.native=-Dignore.native=true
nb.no.dependencies=-Dno.dependencies=true
Expand Down