mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
java: experimental <any T> support
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -21,6 +21,8 @@ import com.intellij.lang.impl.PsiBuilderAdapter;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.lang.java.JavaParserDefinition;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -36,6 +38,7 @@ import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.indexing.IndexingDataKeys;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -119,6 +122,12 @@ public class JavaParserUtil {
|
||||
public static final WhitespacesAndCommentsBinder SPECIAL_PRECEDING_COMMENT_BINDER = new PrecedingWhitespacesAndCommentsBinder(true);
|
||||
public static final WhitespacesAndCommentsBinder TRAILING_COMMENT_BINDER = new TrailingWhitespacesAndCommentsBinder();
|
||||
|
||||
public static final boolean EXPERIMENTAL_FEATURES;
|
||||
static {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
EXPERIMENTAL_FEATURES = SystemProperties.getBooleanProperty("idea.experimental.java.features", app != null && app.isUnitTestMode());
|
||||
}
|
||||
|
||||
private JavaParserUtil() { }
|
||||
|
||||
public static void setLanguageLevel(final PsiBuilder builder, final LanguageLevel level) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.lang.java.parser;
|
||||
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
@@ -343,6 +344,12 @@ public class ReferenceParser {
|
||||
|
||||
myParser.getDeclarationParser().parseAnnotations(builder);
|
||||
|
||||
if (EXPERIMENTAL_FEATURES && "any".equals(builder.getTokenText()) && getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_9)) {
|
||||
PsiBuilder.Marker mark = builder.mark();
|
||||
builder.advanceLexer();
|
||||
mark.done(JavaElementType.DUMMY_ELEMENT);
|
||||
}
|
||||
|
||||
final boolean wild = expect(builder, JavaTokenType.QUEST);
|
||||
if (!wild && !expect(builder, JavaTokenType.IDENTIFIER)) {
|
||||
param.rollbackTo();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
PsiJavaFile:AnyType.java
|
||||
PsiTypeParameterList
|
||||
PsiJavaToken:LT('<')
|
||||
PsiTypeParameter:T
|
||||
PsiElement(DUMMY_ELEMENT)
|
||||
PsiIdentifier:any('any')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiIdentifier:T('T')
|
||||
PsiElement(EXTENDS_BOUND_LIST)
|
||||
<empty list>
|
||||
PsiJavaToken:GT('>')
|
||||
@@ -74,6 +74,10 @@ public abstract class JavaParsingTestCase extends ParsingTestCase {
|
||||
void parse(PsiBuilder builder);
|
||||
}
|
||||
|
||||
protected void setLanguageLevel(@NotNull LanguageLevel languageLevel) {
|
||||
myLanguageLevel = languageLevel;
|
||||
}
|
||||
|
||||
protected void doParserTest(final String text, final TestParser parser) {
|
||||
final String name = getTestName(false);
|
||||
myFile = createPsiFile(name, text, parser);
|
||||
|
||||
+8
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -19,7 +19,7 @@ import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.java.parser.JavaParser;
|
||||
import com.intellij.lang.java.parser.JavaParsingTestCase;
|
||||
import com.intellij.lang.java.parser.ReferenceParser;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
|
||||
public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
public ReferenceParserTest() {
|
||||
@@ -51,6 +51,11 @@ public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
public void testTypeParams7() { doTypeParamsParserTest("<T extends X, Y>"); }
|
||||
public void testTypeParams8() { doTypeParamsParserTest("<?>"); }
|
||||
|
||||
public void testAnyType() {
|
||||
setLanguageLevel(LanguageLevel.JDK_1_9);
|
||||
doTypeParamsParserTest("<any T>");
|
||||
}
|
||||
|
||||
private void doRefParserTest(final String text, final boolean incomplete) {
|
||||
doParserTest(text, new MyTestParser(incomplete));
|
||||
}
|
||||
@@ -73,8 +78,7 @@ public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
private static class MyTestParser2 implements TestParser {
|
||||
@Override
|
||||
public void parse(final PsiBuilder builder) {
|
||||
JavaParser.INSTANCE.getReferenceParser()
|
||||
.parseType(builder, ReferenceParser.ELLIPSIS | ReferenceParser.DIAMONDS | ReferenceParser.DISJUNCTIONS);
|
||||
JavaParser.INSTANCE.getReferenceParser().parseType(builder, ReferenceParser.ELLIPSIS | ReferenceParser.DIAMONDS | ReferenceParser.DISJUNCTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user