[java] adds language level 10

This commit is contained in:
Roman Shevchenko
2018-01-24 15:43:12 +03:00
parent 9da271bf6d
commit ab283f3cec
20 changed files with 49 additions and 171 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon.impl
import com.intellij.codeHighlighting.TextEditorHighlightingPass
@@ -37,7 +23,7 @@ class JavaSoftKeywordHighlightingPassFactory(project: Project, registrar: TextEd
override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass? {
val visit = file is PsiJavaFile &&
(file.name == PsiJavaModule.MODULE_INFO_FILE && file.languageLevel.isAtLeast(LanguageLevel.JDK_1_9) ||
file.languageLevel.isAtLeast(LanguageLevel.JDK_X))
file.languageLevel.isAtLeast(LanguageLevel.JDK_10))
return if (visit) JavaSoftKeywordHighlightingPass(file as PsiJavaFile, editor.document) else null
}
}
@@ -415,7 +415,7 @@ public class HighlightUtil extends HighlightUtilBase {
}
static HighlightInfo checkLegalVarReference(PsiJavaCodeReferenceElement ref, @NotNull PsiClass resolved) {
if (PsiKeyword.VAR.equals(resolved.getName()) && PsiUtil.getLanguageLevel(ref).isAtLeast(LanguageLevel.JDK_X)) {
if (PsiKeyword.VAR.equals(resolved.getName()) && PsiUtil.getLanguageLevel(ref).isAtLeast(LanguageLevel.JDK_10)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip("Illegal reference to restricted type 'var'")
.range(ObjectUtils.notNull(ref.getReferenceNameElement(), ref))
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeHighlighting.Pass;
@@ -651,7 +651,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!(parent instanceof PsiAnonymousClass) && aClass.getNameIdentifier() == identifier) {
myHolder.add(HighlightNamesUtil.highlightClassName(aClass, identifier, colorsScheme));
}
if (!myHolder.hasErrorResults() && myLanguageLevel.isAtLeast(LanguageLevel.JDK_X)) {
if (!myHolder.hasErrorResults() && myLanguageLevel.isAtLeast(LanguageLevel.JDK_10)) {
myHolder.add(HighlightClassUtil.checkVarClassConflict(aClass, identifier));
}
if (!myHolder.hasErrorResults() && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection;
import com.intellij.openapi.project.Project;
@@ -13,7 +13,7 @@ public class RedundantExplicitVariableTypeInspection extends AbstractBaseJavaLoc
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_X)) {
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_10)) {
return PsiElementVisitor.EMPTY_VISITOR;
}
return new JavaElementVisitor() {
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection;
import com.intellij.openapi.project.Project;
@@ -15,7 +15,7 @@ public class VariableTypeCanBeExplicitInspection extends AbstractBaseJavaLocalIn
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_X)) {
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_10)) {
return PsiElementVisitor.EMPTY_VISITOR;
}
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(holder.getProject());
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.compiler;
import com.intellij.codeInsight.daemon.JavaErrorMessages;
@@ -177,14 +163,17 @@ public class JavacQuirksInspectionVisitor extends JavaElementVisitor {
public void visitIdentifier(PsiIdentifier identifier) {
super.visitIdentifier(identifier);
if ("_".equals(identifier.getText()) &&
mySdkVersion != null && mySdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8) &&
mySdkVersion != null &&
mySdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8) &&
myLanguageLevel.isLessThan(LanguageLevel.JDK_1_9)) {
final String message = JavaErrorMessages.message("underscore.identifier.warn");
String message = JavaErrorMessages.message("underscore.identifier.warn");
myHolder.registerProblem(identifier, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
else if (identifier.getParent() instanceof PsiClass && "var".equals(identifier.getText()) &&
myLanguageLevel.isLessThan(LanguageLevel.JDK_X)) {
myHolder.registerProblem(identifier, "Usage of 'var' as class name might not be supported in releases after java 9");
if ("var".equals(identifier.getText()) &&
identifier.getParent() instanceof PsiClass &&
myLanguageLevel.isLessThan(LanguageLevel.JDK_10)) {
String message = JavaErrorMessages.message("var.identifier.warn");
myHolder.registerProblem(identifier, message);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions;
@@ -56,22 +42,21 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
builder.addKind("Enum", PlatformIcons.ENUM_ICON, JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME);
builder.addKind("Annotation", PlatformIcons.ANNOTATION_TYPE_ICON, JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME);
}
for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) {
final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler();
if (handler.handlesTemplate(template) && JavaCreateFromTemplateHandler.canCreate(directory)) {
builder.addKind(template.getName(), JavaFileType.INSTANCE.getIcon(), template.getName());
}
}
builder.setValidator(new InputValidatorEx() {
@Override
public String getErrorText(String inputString) {
if (inputString.length() > 0 && !PsiNameHelper.getInstance(project).isQualifiedName(inputString)) {
return "This is not a valid Java qualified name";
}
if (level.isAtLeast(LanguageLevel.JDK_X) && PsiKeyword.VAR.equals(StringUtil.getShortName(inputString))) {
if (level.isAtLeast(LanguageLevel.JDK_10) && PsiKeyword.VAR.equals(StringUtil.getShortName(inputString))) {
return "var cannot be used for type declarations";
}
return null;
@@ -25,9 +25,9 @@ public enum JavaSdkVersion {
JDK_1_7(LanguageLevel.JDK_1_7),
JDK_1_8(LanguageLevel.JDK_1_8),
JDK_1_9(LanguageLevel.JDK_1_9),
JDK_10(LanguageLevel.JDK_1_9);
JDK_10(LanguageLevel.JDK_10);
private static final JavaSdkVersion MAX_JDK = JDK_1_9;
private static final JavaSdkVersion MAX_JDK = JDK_10;
private final LanguageLevel myMaxLanguageLevel;
@@ -28,6 +28,7 @@ public enum LanguageLevel {
JDK_1_7(JavaCoreBundle.message("jdk.1.7.language.level.description")),
JDK_1_8(JavaCoreBundle.message("jdk.1.8.language.level.description")),
JDK_1_9(JavaCoreBundle.message("jdk.1.9.language.level.description")),
JDK_10(JavaCoreBundle.message("jdk.10.language.level.description")),
JDK_X(JavaCoreBundle.message("jdk.X.language.level.description"));
public static final LanguageLevel HIGHEST = JDK_1_9;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.pom.java.LanguageLevel;
@@ -40,7 +26,7 @@ public class PsiPolyExpressionUtil {
public static boolean isPolyExpression(final PsiExpression expression) {
if (expression instanceof PsiFunctionalExpression) {
return true;
}
}
else if (expression instanceof PsiParenthesizedExpression) {
return isPolyExpression(((PsiParenthesizedExpression)expression).getExpression());
}
@@ -129,9 +115,9 @@ public class PsiPolyExpressionUtil {
private static boolean isInAssignmentOrInvocationContext(PsiExpression expr) {
final PsiElement context = PsiUtil.skipParenthesizedExprUp(expr.getParent());
return context instanceof PsiExpressionList ||
context instanceof PsiArrayInitializerExpression ||
context instanceof PsiConditionalExpression && (expr instanceof PsiCallExpression || isPolyExpression((PsiExpression)context)) ||
return context instanceof PsiExpressionList ||
context instanceof PsiArrayInitializerExpression ||
context instanceof PsiConditionalExpression && (expr instanceof PsiCallExpression || isPolyExpression((PsiExpression)context)) ||
isAssignmentContext(expr, context);
}
@@ -144,7 +130,7 @@ public class PsiPolyExpressionUtil {
}
private static boolean isVarContext(PsiVariable variable) {
if (PsiUtil.getLanguageLevel(variable).isAtLeast(LanguageLevel.JDK_X)) {
if (PsiUtil.getLanguageLevel(variable).isAtLeast(LanguageLevel.JDK_10)) {
PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement != null && typeElement.isInferredType()) {
return true;
@@ -152,7 +138,7 @@ public class PsiPolyExpressionUtil {
}
return false;
}
public static boolean isExpressionOfPrimitiveType(@Nullable PsiExpression arg) {
if (arg != null && !isPolyExpression(arg)) {
final PsiType type = arg.getType();
@@ -8,5 +8,5 @@ jdk.1.6.language.level.description=6 - @Override in interfaces
jdk.1.7.language.level.description=7 - Diamonds, ARM, multi-catch etc.
jdk.1.8.language.level.description=8 - Lambdas, type annotations etc.
jdk.1.9.language.level.description=9 - Modules, private methods in interfaces etc.
jdk.10.language.level.description=10 - Local variable type inference
jdk.X.language.level.description=X - Experimental features
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.java.lexer;
import com.intellij.lexer.LexerBase;
@@ -51,7 +37,7 @@ public class JavaLexer extends LexerBase {
public static boolean isSoftKeyword(CharSequence id, @NotNull LanguageLevel level) {
return id != null &&
(level.isAtLeast(LanguageLevel.JDK_1_9) && JAVA9_KEYWORDS.contains(id) ||
level.isAtLeast(LanguageLevel.JDK_X) && VAR.contentEquals(id));
level.isAtLeast(LanguageLevel.JDK_10) && VAR.contentEquals(id));
}
private final _JavaLexer myFlexLexer;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.java.parser;
import com.intellij.codeInsight.daemon.JavaErrorMessages;
@@ -105,7 +91,7 @@ public class ReferenceParser {
if (tokenType == JavaTokenType.IDENTIFIER &&
isSet(flags, VAR_TYPE) &&
PsiKeyword.VAR.equals(builder.getTokenText()) &&
getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_X)) {
getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_10)) {
builder.remapCurrentToken(tokenType = JavaTokenType.VAR_KEYWORD);
}
else if (tokenType == JavaTokenType.VAR_KEYWORD && !isSet(flags, VAR_TYPE)) {
@@ -401,6 +401,7 @@ declaration.not.allowed=Declaration not allowed here
underscore.identifier.warn=Use of '_' as an identifier might not be supported in releases after Java 8
underscore.identifier.error=As of Java 9, '_' is a keyword, and may not be used as an identifier
underscore.lambda.identifier=Use of '_' as a lambda parameter name is not allowed
var.identifier.warn=Usage of 'var' as class name might not be supported in releases after Java 9
module.no.package=A module file should not have 'package' statement
module.file.wrong.name=Module declaration should be in a file named 'module-info.java'
@@ -1 +1 @@
class <warning descr="Usage of 'var' as class name might not be supported in releases after java 9">var</warning> {}
class <warning descr="Usage of 'var' as class name might not be supported in releases after Java 9">var</warning> {}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -28,8 +14,8 @@ public class LightAdvLVTIHighlightingTest extends LightDaemonAnalyzerTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
setLanguageLevel(LanguageLevel.JDK_X);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_9, getModule(), getTestRootDisposable());
setLanguageLevel(LanguageLevel.JDK_10);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_10, getModule(), getTestRootDisposable());
}
private void doTest() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
@@ -35,7 +21,7 @@ public class RedundantExplicitVariableTypeInspectionTest extends LightQuickFixPa
@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_X;
return LanguageLevel.JDK_10;
}
@Override
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
@@ -35,7 +21,7 @@ public class VariableTypeCanBeExplicitInspectionTest extends LightQuickFixParame
@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_X;
return LanguageLevel.JDK_10;
}
@Override
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.io.java.impl
import com.intellij.openapi.util.text.StringUtil
@@ -65,7 +65,7 @@ private fun LanguageLevel.toAsmCode() = when (this) {
LanguageLevel.JDK_1_7 -> Opcodes.V1_7
LanguageLevel.JDK_1_8 -> Opcodes.V1_8
LanguageLevel.JDK_1_9 -> Opcodes.V9
LanguageLevel.JDK_X -> throw UnsupportedOperationException("Java 10 isn't supported yet")
else -> throw UnsupportedOperationException("${this} isn't supported yet")
}
private fun AccessModifier.toAsmCode() = when (this) {
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* @author nik
*/
public enum LanguageLevel {
JDK_1_3, JDK_1_4, JDK_1_5, JDK_1_6, JDK_1_7, JDK_1_8, JDK_1_9, JDK_X;
JDK_1_3, JDK_1_4, JDK_1_5, JDK_1_6, JDK_1_7, JDK_1_8, JDK_1_9, JDK_10, JDK_X;
@NotNull
public JavaVersion toJavaVersion() {