diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index dc1035ae62d3..3a9857459cdc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -51,7 +51,6 @@ import java.util.*; */ public class GenericsHighlightUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil"); - private static final String GENERICS_ARE_NOT_SUPPORTED = JavaErrorMessages.message("generics.are.not.supported"); private static final QuickFixFactory QUICK_FIX_FACTORY = QuickFixFactory.getInstance(); private GenericsHighlightUtil() {} @@ -102,6 +101,7 @@ public class GenericsHighlightUtil { return null; } + @Nullable public static HighlightInfo checkParameterizedReferenceTypeArguments(PsiElement resolved, final PsiJavaCodeReferenceElement referenceElement, final PsiSubstitutor substitutor) { @@ -110,17 +110,14 @@ public class GenericsHighlightUtil { return checkReferenceTypeArgumentList(typeParameterListOwner, referenceElement.getParameterList(), substitutor, true); } + @Nullable public static HighlightInfo checkReferenceTypeArgumentList(final PsiTypeParameterListOwner typeParameterListOwner, final PsiReferenceParameterList referenceParameterList, final PsiSubstitutor substitutor, boolean registerIntentions) { - if (referenceParameterList != null && !PsiUtil.isLanguageLevel5OrHigher(referenceParameterList)) { - if (referenceParameterList.getTypeParameterElements().length > 0) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, referenceParameterList, GENERICS_ARE_NOT_SUPPORTED); - QuickFixAction.registerQuickFixAction(info, new ShowModulePropertiesFix(referenceParameterList)); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - return info; - } + if (referenceParameterList != null) { + HighlightInfo info = HighlightUtil.checkGenericsFeature(referenceParameterList, referenceParameterList.getTypeParameterElements().length); + if (info != null) return info; } PsiDiamondType.DiamondInferenceResult inferenceResult = null; @@ -914,15 +911,13 @@ public class GenericsHighlightUtil { return valueOfMethod.equals(methodSignature); } + @Nullable public static HighlightInfo checkTypeParametersList(PsiTypeParameterList parameterList) { PsiTypeParameter[] typeParameters = parameterList.getTypeParameters(); if (typeParameters.length == 0) return null; - if (!PsiUtil.isLanguageLevel5OrHigher(parameterList)) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, parameterList, GENERICS_ARE_NOT_SUPPORTED); - QuickFixAction.registerQuickFixAction(info, new ShowModulePropertiesFix(parameterList)); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - return info; - } + HighlightInfo info = HighlightUtil.checkGenericsFeature(parameterList, typeParameters.length); + if (info != null) return info; + final PsiElement parent = parameterList.getParent(); if (parent instanceof PsiClass && ((PsiClass)parent).isEnum()) { return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, @@ -1208,21 +1203,18 @@ public class GenericsHighlightUtil { return null; } + @Nullable public static HighlightInfo checkVarArgParameterIsLast(PsiParameter parameter) { PsiElement declarationScope = parameter.getDeclarationScope(); if (declarationScope instanceof PsiMethod) { PsiParameter[] params = ((PsiMethod)declarationScope).getParameterList().getParameters(); if (parameter.isVarArgs()) { - if (!PsiUtil.getLanguageLevel(parameter).hasEnumKeywordAndAutoboxing()) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, parameter, JavaErrorMessages.message("varargs.prior.15")); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - return info; - } + HighlightInfo info = HighlightUtil.checkVarargFeature(parameter); + if (info != null) return info; if (params[params.length - 1] != parameter) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, parameter, - JavaErrorMessages.message("vararg.not.last.parameter")); - QuickFixAction.registerQuickFixAction(info, new MakeVarargParameterLastFix(parameter), null); + info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, parameter, JavaErrorMessages.message("vararg.not.last.parameter")); + QuickFixAction.registerQuickFixAction(info, new MakeVarargParameterLastFix(parameter)); return info; } } @@ -1230,6 +1222,7 @@ public class GenericsHighlightUtil { return null; } + @Nullable public static List checkEnumConstantModifierList(PsiModifierList modifierList) { List list = null; PsiElement[] children = modifierList.getChildren(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index dc8b8743f524..3a54ada2c167 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -58,6 +58,7 @@ import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.PropertyKey; import java.util.*; @@ -593,6 +594,7 @@ public class HighlightUtil { if (variable instanceof PsiLocalVariable || variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiCatchSection || variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiForeachStatement) { + @SuppressWarnings("unchecked") PsiElement scope = PsiTreeUtil.getParentOfType(variable, PsiFile.class, PsiMethod.class, PsiClassInitializer.class, PsiResourceList.class); VariablesNotProcessor proc = new VariablesNotProcessor(variable, false) { @Override @@ -602,7 +604,9 @@ public class HighlightUtil { }; PsiScopesUtil.treeWalkUp(proc, identifier, scope); if (scope instanceof PsiResourceList && proc.size() == 0) { - scope = PsiTreeUtil.getParentOfType(variable, PsiFile.class, PsiMethod.class, PsiClassInitializer.class); + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) + NavigatablePsiElement parent = PsiTreeUtil.getParentOfType(variable, PsiFile.class, PsiMethod.class, PsiClassInitializer.class); + scope = parent; PsiScopesUtil.treeWalkUp(proc, identifier, scope); } if (proc.size() > 0) { @@ -1403,7 +1407,7 @@ public class HighlightUtil { } @Nullable - static HighlightInfo checkValidArrayAccessExpression(PsiExpression arrayExpression, PsiExpression indexExpression, PsiType type) { + static HighlightInfo checkValidArrayAccessExpression(@Nullable PsiExpression arrayExpression, PsiExpression indexExpression, PsiType type) { PsiType arrayExpressionType = arrayExpression == null ? null : arrayExpression.getType(); if (arrayExpressionType != null && !(arrayExpressionType instanceof PsiArrayType)) { String description = JavaErrorMessages.message("array.type.expected", formatType(arrayExpressionType)); @@ -1744,9 +1748,11 @@ public class HighlightUtil { referencedClass = PsiUtil.resolveClassInType(type); } else if (qualifier instanceof PsiThisExpression || qualifier == null) { - resolved = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) + PsiMethod parent = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); + resolved = parent; expression = qualifier == null ? expression : qualifier; - if (resolved instanceof PsiMethod) { + if (resolved != null) { referencedClass = ((PsiMethod)resolved).getContainingClass(); } } @@ -2452,7 +2458,7 @@ public class HighlightUtil { public static void registerChangeVariableTypeFixes(PsiVariable parameter, PsiType itemType, HighlightInfo highlightInfo) { for (ChangeVariableTypeQuickFixProvider fixProvider : Extensions.getExtensions(ChangeVariableTypeQuickFixProvider.EP_NAME)) { for (IntentionAction action : fixProvider.getFixes(parameter, itemType)) { - QuickFixAction.registerQuickFixAction(highlightInfo, action, null); + QuickFixAction.registerQuickFixAction(highlightInfo, action); } } ChangeParameterClassFix.registerQuickFixAction(parameter, itemType, highlightInfo); @@ -2466,4 +2472,76 @@ public class HighlightUtil { } return null; } + + private static enum Feature { + GENERICS(LanguageLevel.JDK_1_5, "feature.generics"), + ANNOTATIONS(LanguageLevel.JDK_1_5, "feature.annotations"), + STATIC_IMPORTS(LanguageLevel.JDK_1_5, "feature.static.imports"), + FOR_EACH(LanguageLevel.JDK_1_5, "feature.for.each"), + VARARGS(LanguageLevel.JDK_1_5, "feature.varargs"), + DIAMOND_TYPES(LanguageLevel.JDK_1_7, "feature.diamond.types"), + MULTI_CATCH(LanguageLevel.JDK_1_7, "feature.multi.catch"), + TRY_WITH_RESOURCES(LanguageLevel.JDK_1_7, "feature.try.with.resources"); + + private final LanguageLevel level; + private final String key; + + private Feature(final LanguageLevel level, @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) final String key) { + this.level = level; + this.key = key; + } + } + + @Nullable + private static HighlightInfo checkFeature(@Nullable final PsiElement element, @NotNull final Feature feature) { + if (element != null && !PsiUtil.getLanguageLevel(element).isAtLeast(feature.level)) { + final String message = JavaErrorMessages.message("insufficient.language.level", JavaErrorMessages.message(feature.key)); + final HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, element, message); + QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(feature.level)); + QuickFixAction.registerQuickFixAction(info, new ShowModulePropertiesFix(element)); + return info; + } + + return null; + } + + @Nullable + public static HighlightInfo checkGenericsFeature(final PsiElement parameterList, final int listSize) { + return listSize > 0 ? checkFeature(parameterList, Feature.GENERICS) : null; + } + + @Nullable + public static HighlightInfo checkAnnotationFeature(final PsiElement element) { + return checkFeature(element, Feature.ANNOTATIONS); + } + + @Nullable + public static HighlightInfo checkForEachFeature(final PsiForeachStatement statement) { + return checkFeature(statement, Feature.FOR_EACH); + } + + @Nullable + public static HighlightInfo checkStaticImportFeature(final PsiImportStaticStatement statement) { + return checkFeature(statement, Feature.STATIC_IMPORTS); + } + + @Nullable + public static HighlightInfo checkVarargFeature(final PsiParameter parameter) { + return checkFeature(parameter, Feature.VARARGS); + } + + @Nullable + public static HighlightInfo checkDiamondFeature(final PsiTypeElement typeElement) { + return typeElement.getType() instanceof PsiDiamondType ? checkFeature(typeElement.getParent(), Feature.DIAMOND_TYPES) : null; + } + + @Nullable + public static HighlightInfo checkMultiCatchFeature(final PsiParameter parameter) { + return parameter.getType() instanceof PsiDisjunctionType ? checkFeature(parameter, Feature.MULTI_CATCH) : null; + } + + @Nullable + public static HighlightInfo checkTryWithResourcesFeature(final PsiResourceVariable resourceVariable) { + return checkFeature(resourceVariable.getParent(), Feature.TRY_WITH_RESOURCES); + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index d120ae71f2bf..63d74f914fa3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -30,7 +30,6 @@ import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; -import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.controlFlow.ControlFlowUtil; import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; @@ -170,16 +169,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } - @Override public void visitAnnotation(PsiAnnotation annotation) { + @Override + public void visitAnnotation(PsiAnnotation annotation) { super.visitAnnotation(annotation); - if (!PsiUtil.isLanguageLevel5OrHigher(annotation)) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, annotation, JavaErrorMessages.message("annotations.prior.15")); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - myHolder.add(info); - return; - } - - myHolder.add(AnnotationsHighlightUtil.checkApplicability(annotation)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkAnnotationFeature(annotation)); + if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkApplicability(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkAnnotationType(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkMissingAttributes(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkTargetAnnotationDuplicates(annotation)); @@ -187,7 +181,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkForeignInnerClassesUsed(annotation)); } - @Override public void visitAnnotationArrayInitializer(PsiArrayInitializerMemberValue initializer) { + @Override + public void visitAnnotationArrayInitializer(PsiArrayInitializerMemberValue initializer) { PsiMethod method = null; PsiElement parent = initializer.getParent(); if (parent instanceof PsiNameValuePair) { @@ -364,28 +359,24 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } - @Override public void visitField(PsiField field) { + @Override + public void visitField(PsiField field) { super.visitField(field); if (!myHolder.hasErrorResults()) myHolder.add(HighlightControlFlowUtil.checkFinalFieldInitialized(field)); } - @Override public void visitForeachStatement(PsiForeachStatement statement) { - if (!PsiUtil.isLanguageLevel5OrHigher(statement)) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, statement.getFirstChild(), JavaErrorMessages.message("foreach.prior.15")); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - myHolder.add(info); - } + @Override + public void visitForeachStatement(final PsiForeachStatement statement) { + myHolder.add(HighlightUtil.checkForEachFeature(statement)); } - @Override public void visitImportStaticStatement(PsiImportStaticStatement statement) { - if (!PsiUtil.isLanguageLevel5OrHigher(statement)) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, statement.getFirstChild(), JavaErrorMessages.message("static.imports.prior.15")); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - myHolder.add(info); - } + @Override + public void visitImportStaticStatement(final PsiImportStaticStatement statement) { + myHolder.add(HighlightUtil.checkStaticImportFeature(statement)); } - @Override public void visitIdentifier(PsiIdentifier identifier) { + @Override + public void visitIdentifier(final PsiIdentifier identifier) { PsiElement parent = identifier.getParent(); final EditorColorsScheme colorsScheme = myHolder.getColorsScheme(); if (parent instanceof PsiVariable) { @@ -411,10 +402,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } else if (parent instanceof PsiClass) { PsiClass aClass = (PsiClass)parent; - if (aClass.isAnnotationType() && !PsiUtil.isLanguageLevel5OrHigher(aClass)) { - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, identifier, JavaErrorMessages.message("annotations.prior.15")); - QuickFixAction.registerQuickFixAction(info, new IncreaseLanguageLevelFix(LanguageLevel.JDK_1_5)); - myHolder.add(info); + if (aClass.isAnnotationType()) { + myHolder.add(HighlightUtil.checkAnnotationFeature(identifier)); } myHolder.add(HighlightClassUtil.checkClassAlreadyImported(aClass, identifier)); @@ -742,6 +731,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkForeachLoopParameterType((PsiForeachStatement)parent)); } else if (parent instanceof PsiCatchSection) { + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkMultiCatchFeature(parameter)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkCatchParameterIsThrowable(parameter)); if (!myHolder.hasErrorResults()) myHolder.addAll(GenericsHighlightUtil.checkCatchParameterIsClass(parameter)); if (!myHolder.hasErrorResults()) myHolder.addAll(HighlightUtil.checkCatchTypeIsDisjoint(parameter)); @@ -987,11 +977,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitResourceVariable(final PsiResourceVariable resourceVariable) { visitVariable(resourceVariable); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkTryWithResourcesFeature(resourceVariable)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkTryResourceIsAutoCloseable(resourceVariable)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkUnhandledCloserExceptions(resourceVariable)); } - @Override public void visitTypeElement(PsiTypeElement type) { + @Override + public void visitTypeElement(final PsiTypeElement type) { + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkDiamondFeature(type)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIllegalType(type)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkReferenceTypeUsedAsTypeArgument(type)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkWildcardUsage(type)); diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java index 897adbe053a7..1e2cebe67217 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java @@ -671,15 +671,14 @@ public class ExpressionParser { final PsiBuilder.Marker newExpr = (start != null ? start.precede() : builder.mark()); builder.advanceLexer(); - final boolean parseDiamonds = areDiamondsSupported(builder); - myReferenceParser.parseReferenceParameterList(builder, false, parseDiamonds); + myReferenceParser.parseReferenceParameterList(builder, false, true); final PsiBuilder.Marker refOrType; final boolean parseAnnotations = areTypeAnnotationsSupported(builder) && builder.getTokenType() == JavaTokenType.AT; final IElementType tokenType = builder.getTokenType(); if (tokenType == JavaTokenType.IDENTIFIER || parseAnnotations) { - refOrType = myReferenceParser.parseJavaCodeReference(builder, true, true, parseAnnotations, true, parseDiamonds); + refOrType = myReferenceParser.parseJavaCodeReference(builder, true, true, parseAnnotations, true, true); if (refOrType == null) { error(builder, JavaErrorMessages.message("expected.identifier")); newExpr.done(JavaElementType.NEW_EXPRESSION); diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java index f0b086abf5fe..f540b0749b3b 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java @@ -133,17 +133,6 @@ public class JavaParserUtil { builder.putUserDataUnprotected(LANG_LEVEL_KEY, level); } - // todo[r.sh] join all JDK 7 check clauses into single method (IDEA 11) - public static boolean areDiamondsSupported(final PsiBuilder builder) { - return getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_7); - } - public static boolean areMultiCatchSupported(final PsiBuilder builder) { - return getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_7); - } - public static boolean areTryWithResourcesSupported(final PsiBuilder builder) { - return getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_7); - } - public static boolean areTypeAnnotationsSupported(final PsiBuilder builder) { return getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_8); } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/StatementParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/StatementParser.java index 95ad7cfd72a8..95161be3feed 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/StatementParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/StatementParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -622,9 +622,8 @@ public class StatementParser { final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); - boolean hasResourceList = false; - if (areTryWithResourcesSupported(builder) && builder.getTokenType() == JavaTokenType.LPARENTH) { - hasResourceList = true; + final boolean hasResourceList = builder.getTokenType() == JavaTokenType.LPARENTH; + if (hasResourceList) { myDeclarationParser.parseResourceList(builder); } @@ -667,7 +666,7 @@ public class StatementParser { return false; } - final PsiBuilder.Marker param = myDeclarationParser.parseParameter(builder, false, areMultiCatchSupported(builder)); + final PsiBuilder.Marker param = myDeclarationParser.parseParameter(builder, false, true); if (param == null) { error(builder, JavaErrorMessages.message("expected.parameter")); } diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index 3260287f759b..2258f7f8d204 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -41,7 +41,6 @@ annotation.target.PACKAGE=package generics.holder.type=Type generics.holder.method=Method -generics.are.not.supported=Generics are not supported at this language level generics.inferred.type.for.type.parameter.is.not.within.its.bound.extend=Inferred type ''{2}'' for type parameter ''{0}'' is not within its bound; should extend ''{1}'' generics.inferred.type.for.type.parameter.is.not.within.its.bound.implement=Inferred type ''{2}'' for type parameter ''{0}'' is not within its bound; should implement ''{1}'' generics.type.parameter.is.not.within.its.bound.extend=Type parameter ''{0}'' is not within its bound; should extend ''{1}'' @@ -83,7 +82,6 @@ generics.type.arguments.on.raw.type=Type arguments given on a raw type generics.type.arguments.on.raw.method=Type arguments given on a raw method classes.extends.enum=Classes cannot directly extend 'java.lang.Enum' unchecked.overriding.incompatible.return.type=Unchecked overriding: return type requires unchecked conversion. Found ''{0}'', required ''{1}'' -unchecked.overriding=Unchecked overriding local.enum=Enum must not be local interface.expected=Interface expected here @@ -237,10 +235,6 @@ static.member.accessed.via.instance.reference=Static member ''{0}.{1}'' accessed unresolved.label=Undefined label: ''{0}'' deprecated.symbol=''{0}'' is deprecated cannot.resolve.symbol=Cannot resolve symbol ''{0}'' -static.imports.prior.15=Static imports are not supported at this language level -varargs.prior.15=Variable arity methods are not supported at this language level -foreach.prior.15=Foreach loops are not supported at this language level -annotations.prior.15=Annotations are not supported at this language level class.is.already.defined.in.single.static.import=Class ''{0}'' is already defined in a single static import class.is.ambiguous.in.single.static.import=Class ''{0}'' is ambiguous in a single static import field.is.already.defined.in.single.static.import=Field ''{0}'' is already defined in a single static import @@ -322,7 +316,6 @@ expected.resource=Resource definition expected expected.type.parameter=Type parameter expected expected.comma=',' expected expected.comma.or.rparen=',' or ')' expected -unexpected.tokens.beyond.the.end.of.expression=Unexpected token(s) beyond the end of expression expected.colon=':' expected expected.type=Type expected expected.lbracket='[' expected @@ -352,3 +345,13 @@ cannot.resolve.package=Cannot resolve package {0} override.not.allowed.in.interfaces=@Override is not allowed when implementing interface method wildcard.not.expected=Unexpected wildcard bound.not.expected=Unexpected bound + +feature.generics=Generics +feature.annotations=Annotations +feature.static.imports=Static imports +feature.for.each=For-each loops +feature.varargs=Variable arity methods +feature.diamond.types=Diamond types +feature.try.with.resources=Try-with-resources +feature.multi.catch=Multi-catches +insufficient.language.level={0} are not supported at this language level diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java new file mode 100644 index 000000000000..1c108b5f9e0e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java @@ -0,0 +1,36 @@ +/* + * 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. + */ +import java.io.*; +import java.util.*; + +import static java.lang.Math.*; + +@interface Anno { } + +@Anno +class UnsupportedFeatures { + void m(String... args) throws Exception { + for (String s : args) { System.out.println(s); } + + List list = + new ArrayList<>(); + + try { Reader r = new FileReader("/dev/null"); } + catch (FileNotFoundException | IOException e) { e.printStackTrace(); } + + try (Reader r = new FileReader("/dev/null")) { } + } +} diff --git a/java/java-tests/testData/psi/parser-partial/expressions/New15.txt b/java/java-tests/testData/psi/parser-partial/expressions/New15.txt index 80407edd16b7..2a1cea3f68ea 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/New15.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/New15.txt @@ -1,24 +1,21 @@ PsiJavaFile:New15.java - PsiMethodCallExpression:new C.B() - PsiReferenceExpression:new C.B - PsiNewExpression:new C - PsiKeyword:new('new') + PsiNewExpression:new C.B() + PsiKeyword:new('new') + PsiReferenceParameterList + + PsiWhiteSpace(' ') + PsiJavaCodeReferenceElement:C.B + PsiJavaCodeReferenceElement:C + PsiIdentifier:C('C') PsiReferenceParameterList - - PsiWhiteSpace(' ') - PsiJavaCodeReferenceElement:C - PsiIdentifier:C('C') - PsiReferenceParameterList - PsiJavaToken:LT('<') - PsiTypeElement:? - PsiJavaToken:QUEST('?') - PsiJavaToken:GT('>') - PsiErrorElement:'(' or '[' expected - + PsiJavaToken:LT('<') + PsiTypeElement:? + PsiJavaToken:QUEST('?') + PsiJavaToken:GT('>') PsiJavaToken:DOT('.') + PsiIdentifier:B('B') PsiReferenceParameterList - PsiIdentifier:B('B') PsiExpressionList PsiJavaToken:LPARENTH('(') PsiJavaToken:RPARENTH(')') \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 082e532a244e..2524776bddac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -40,6 +40,7 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.xml.XmlAttribute; @@ -161,7 +162,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testQualifiedNew() throws Exception { doTest(false, false); } public void testEnclosingInstance() throws Exception { doTest(false, false); } - public void testStaticViaInstance() throws Exception { doTest(true, false); } // static via instabnce + public void testStaticViaInstance() throws Exception { doTest(true, false); } // static via instance public void testQualifiedThisSuper() throws Exception { doTest(true, false); } //illegal qualified this or super public void testAmbiguousMethodCall() throws Exception { doTest(false, false); } @@ -230,19 +231,13 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { } @Override - public void setSelected(boolean selected) { - - } + public void setSelected(boolean selected) { } @Override - public void readExternal(Element element) { - - } + public void readExternal(Element element) { } @Override - public void writeExternal(Element element) { - - } + public void writeExternal(Element element) { } }; point.registerExtension(extension); @@ -265,9 +260,13 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - PsiFile txt = myFile.getParent().createFile("x.txt"); + PsiDirectory directory = myFile.getParent(); + assertNotNull(myFile.toString(), directory); + PsiFile txt = directory.createFile("x.txt"); + VirtualFile vFile = txt.getVirtualFile(); + assertNotNull(txt.toString(), vFile); try { - VfsUtil.saveText(txt.getVirtualFile(), "XXX"); + VfsUtil.saveText(vFile, "XXX"); } catch (IOException e) { throw new RuntimeException(e); @@ -356,11 +355,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { doHighlighting(); } - public void testClassicRethrow() throws Exception { - doTest(false, false); - } - - public void testRegexp() throws Exception { - doTest(false, false); - } + public void testClassicRethrow() throws Exception { doTest(false, false); } + public void testRegexp() throws Exception { doTest(false, false); } + public void testUnsupportedFeatures() throws Exception { doTest(false, false); } } diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/ExpressionParsingTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/ExpressionParsingTest.java index bbb053005b5f..bb07718dd360 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/ExpressionParsingTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/ExpressionParsingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -15,11 +15,7 @@ */ package com.intellij.lang.java.parser; - -import com.intellij.pom.java.LanguageLevel; - public class ExpressionParsingTest extends JavaParsingTestCase { - public ExpressionParsingTest() { super("parser-full/expressionParsing"); } @@ -75,11 +71,7 @@ public class ExpressionParsingTest extends JavaParsingTestCase { public void testNew12() { doTest(true); } public void testNew13() { doTest(true); } public void testNew14() { doTest(true); } - public void testNew15() { - withLevel(LanguageLevel.JDK_1_7, new Runnable() { @Override public void run() { - doTest(true); - }}); - } + public void testNew15() { doTest(true); } public void testExprList0() { doTest(true); } public void testExprList1() { doTest(true); } diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java index 471190ed3179..f43e356abed7 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java @@ -18,10 +18,8 @@ package com.intellij.lang.java.parser.partial; import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.parser.JavaParsers; import com.intellij.lang.java.parser.JavaParsingTestCase; -import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NonNls; - public class ExpressionParserTest extends JavaParsingTestCase { public ExpressionParserTest() { super("parser-partial/expressions"); @@ -77,11 +75,7 @@ public class ExpressionParserTest extends JavaParsingTestCase { public void testNew13() { doParserTest("new int[1][][2]"); } public void testNew14() { doParserTest("Q.new A()"); } public void testNew15() { doParserTest("new C.B()"); } - public void testNew16() { - withLevel(LanguageLevel.JDK_1_7, - new Runnable() { @Override - public void run() { doParserTest("new C<>()"); } }); - } + public void testNew16() { doParserTest("new C<>()"); } public void testExprList0() { doParserTest("f(1,2)"); } public void testExprList1() { doParserTest("f("); } diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/StatementParserTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/StatementParserTest.java index 76e99441bba0..714e7c1ad456 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/StatementParserTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/StatementParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -18,8 +18,6 @@ package com.intellij.lang.java.parser.partial; import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.parser.JavaParsers; import com.intellij.lang.java.parser.JavaParsingTestCase; -import com.intellij.pom.java.LanguageLevel; - public class StatementParserTest extends JavaParsingTestCase { public StatementParserTest() { @@ -119,10 +117,10 @@ public class StatementParserTest extends JavaParsingTestCase { public void testTryNormal0() { doParserTest("try{}catch(E e){}"); } public void testTryNormal1() { doParserTest("try{}catch(final E e){}finally{}"); } public void testTryNormal2() { doParserTest("try{}finally{}"); } - public void testTryNormal3() { doParserTestJDK7("try{}catch(A|B e){}"); } - public void testTryNormal4() { doParserTestJDK7("try(R r = 0){}"); } - public void testTryNormal5() { doParserTestJDK7("try(R1 r1 = 1; R2 r2 = 2){}"); } - public void testTryNormal6() { doParserTestJDK7("try(R r = 0;){}"); } + public void testTryNormal3() { doParserTest("try{}catch(A|B e){}"); } + public void testTryNormal4() { doParserTest("try(R r = 0){}"); } + public void testTryNormal5() { doParserTest("try(R1 r1 = 1; R2 r2 = 2){}"); } + public void testTryNormal6() { doParserTest("try(R r = 0;){}"); } public void testTryIncomplete0() { doParserTest("try"); } public void testTryIncomplete1() { doParserTest("try{}"); } public void testTryIncomplete2() { doParserTest("try{}catch"); } @@ -131,16 +129,16 @@ public class StatementParserTest extends JavaParsingTestCase { public void testTryIncomplete5() { doParserTest("try{}catch(E e"); } public void testTryIncomplete6() { doParserTest("try{}catch(E e)"); } public void testTryIncomplete7() { doParserTest("try{}finally"); } - public void testTryIncomplete8() { doParserTestJDK7("try{}catch(A|)"); } - public void testTryIncomplete9() { doParserTestJDK7("try{}catch(A|B)"); } - public void testTryIncomplete10() { doParserTestJDK7("try({}"); } - public void testTryIncomplete11() { doParserTestJDK7("try(){}"); } - public void testTryIncomplete12() { doParserTestJDK7("try(;){}"); } - public void testTryIncomplete13() { doParserTestJDK7("try(final ){}"); } - public void testTryIncomplete14() { doParserTestJDK7("try(int){}"); } - public void testTryIncomplete15() { doParserTestJDK7("try(R r){}"); } - public void testTryIncomplete16() { doParserTestJDK7("try(R r =){}"); } - public void testTryIncomplete17() { doParserTestJDK7("try(R r = 0;;){}"); } + public void testTryIncomplete8() { doParserTest("try{}catch(A|)"); } + public void testTryIncomplete9() { doParserTest("try{}catch(A|B)"); } + public void testTryIncomplete10() { doParserTest("try({}"); } + public void testTryIncomplete11() { doParserTest("try(){}"); } + public void testTryIncomplete12() { doParserTest("try(;){}"); } + public void testTryIncomplete13() { doParserTest("try(final ){}"); } + public void testTryIncomplete14() { doParserTest("try(int){}"); } + public void testTryIncomplete15() { doParserTest("try(R r){}"); } + public void testTryIncomplete16() { doParserTest("try(R r =){}"); } + public void testTryIncomplete17() { doParserTest("try(R r = 0;;){}"); } public void testWhileNormal() { doParserTest("while (true) foo();"); } public void testWhileIncomplete0() { doParserTest("while"); } @@ -151,33 +149,22 @@ public class StatementParserTest extends JavaParsingTestCase { public void testWhileIncomplete5() { doParserTest("while() foo();"); } private void doBlockParserTest(final String text) { - doParserTest(text, new MyTestParser1()); + doParserTest(text, new MyBlockTestParser()); } - - private void doParserTest(final String text) { - doParserTest(text, new MyTestParser2()); - } - - private void doParserTestJDK7(final String text) { - withLevel(LanguageLevel.JDK_1_7, new Runnable() { - @Override - public void run() { - doParserTest(text); - } - }); - } - - private static class MyTestParser2 implements TestParser { - @Override - public void parse(final PsiBuilder builder) { - JavaParsers.STATEMENT_PARSER.parseStatements(builder); - } - } - - private static class MyTestParser1 implements TestParser { + private static class MyBlockTestParser implements TestParser { @Override public void parse(final PsiBuilder builder) { JavaParsers.STATEMENT_PARSER.parseCodeBlockDeep(builder, true); } } + + private void doParserTest(final String text) { + doParserTest(text, new MyStatementsTestParser()); + } + private static class MyStatementsTestParser implements TestParser { + @Override + public void parse(final PsiBuilder builder) { + JavaParsers.STATEMENT_PARSER.parseStatements(builder); + } + } } diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/statementParsing/TryParsingTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/statementParsing/TryParsingTest.java index 76fabf2ee387..cb48c248ac30 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/statementParsing/TryParsingTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/statementParsing/TryParsingTest.java @@ -1,8 +1,21 @@ +/* + * 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. + */ package com.intellij.lang.java.parser.statementParsing; import com.intellij.lang.java.parser.JavaParsingTestCase; -import com.intellij.pom.java.LanguageLevel; - public class TryParsingTest extends JavaParsingTestCase { public TryParsingTest() { @@ -12,11 +25,7 @@ public class TryParsingTest extends JavaParsingTestCase { public void testNormal1() { doTest(true); } public void testNormal2() { doTest(true); } public void testNormal3() { doTest(true); } - public void testNormal4() { - withLevel(LanguageLevel.JDK_1_7, new Runnable() { @Override public void run() { - doTest(true); - }}); - } + public void testNormal4() { doTest(true); } public void testIncomplete1() { doTest(true); } public void testIncomplete2() { doTest(true); } @@ -26,9 +35,5 @@ public class TryParsingTest extends JavaParsingTestCase { public void testIncomplete6() { doTest(true); } public void testIncomplete7() { doTest(true); } public void testIncomplete8() { doTest(true); } - public void testIncomplete9() { - withLevel(LanguageLevel.JDK_1_7, new Runnable() { @Override public void run() { - doTest(true); - }}); - } + public void testIncomplete9() { doTest(true); } } \ No newline at end of file