Replace parser conditionals with language level highlighting

This commit is contained in:
Roman Shevchenko
2012-05-11 21:09:41 +04:00
parent 97eb59356d
commit 7115bb9787
14 changed files with 249 additions and 189 deletions
@@ -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);
@@ -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);
}
@@ -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"));
}
@@ -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