Deprecated extension method syntax dropped

This commit is contained in:
Roman Shevchenko
2013-02-27 20:40:44 +01:00
parent f4330beba2
commit 54a7b4dc70
31 changed files with 67 additions and 290 deletions

View File

@@ -1,67 +0,0 @@
/*
* 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.codeInspection.deprecation;
import com.intellij.codeInspection.*;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PsiModifierListImpl;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
// todo[r.sh] drop this after transition period finished
public class DeprecatedDefenderSyntaxInspection extends BaseJavaLocalInspectionTool {
private final LocalQuickFix myQuickFix = new MyQuickFix();
@Nullable
@Override
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
final PsiJavaToken marker = PsiModifierListImpl.findExtensionMethodMarker(method);
return marker == null ? null : new ProblemDescriptor[]{
manager.createProblemDescriptor(marker, getDisplayName(), myQuickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly)
};
}
private static class MyQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
return InspectionsBundle.message("deprecated.defender.syntax.fix");
}
@NotNull
@Override
public String getFamilyName() {
return "";
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement marker = descriptor.getPsiElement();
if (marker != null && PsiUtil.isJavaToken(marker, JavaTokenType.DEFAULT_KEYWORD)) {
final PsiElement parent = marker.getParent();
if (parent instanceof PsiMethod) {
marker.delete();
final PsiMethod method = (PsiMethod)parent;
if (!method.hasModifierProperty(PsiModifier.DEFAULT)) {
PsiUtil.setModifierProperty(method, PsiModifier.DEFAULT, true);
}
}
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -402,29 +402,26 @@ public class DeclarationParser {
return Pair.create(modList, isEmpty);
}
private PsiBuilder.Marker parseMethodFromLeftParenth(final PsiBuilder builder, final PsiBuilder.Marker declaration,
final boolean anno, final boolean constructor) {
private PsiBuilder.Marker parseMethodFromLeftParenth(PsiBuilder builder, PsiBuilder.Marker declaration, boolean anno, boolean constructor) {
parseParameterList(builder);
eatBrackets(builder, constructor, "expected.semicolon");
myParser.getReferenceParser().parseReferenceList(builder, JavaTokenType.THROWS_KEYWORD, JavaElementType.THROWS_LIST, JavaTokenType.COMMA);
final boolean hasDefault = expect(builder, JavaTokenType.DEFAULT_KEYWORD);
if (hasDefault && anno) {
if (anno && expect(builder, JavaTokenType.DEFAULT_KEYWORD)) {
parseAnnotationValue(builder);
}
final IElementType tokenType = builder.getTokenType();
final boolean hasError = tokenType != JavaTokenType.SEMICOLON && tokenType != JavaTokenType.LBRACE;
if (hasError) {
final PsiBuilder.Marker error = builder.mark();
IElementType tokenType = builder.getTokenType();
if (tokenType != JavaTokenType.SEMICOLON && tokenType != JavaTokenType.LBRACE) {
PsiBuilder.Marker error = builder.mark();
// heuristic: going to next line obviously means method signature is over, starting new method (actually, another one completion hack)
final CharSequence text = builder.getOriginalText();
CharSequence text = builder.getOriginalText();
Loop:
while (true) {
for (int i = builder.getCurrentOffset() - 1; i >= 0; i--) {
final char ch = text.charAt(i);
char ch = text.charAt(i);
if (ch == '\n') break Loop;
else if (ch != ' ' && ch != '\t') break;
}
@@ -433,11 +430,10 @@ public class DeclarationParser {
error.error(JavaErrorMessages.message("expected.lbrace.or.semicolon"));
}
if (hasDefault && !anno && !hasError && builder.getTokenType() != JavaTokenType.LBRACE) {
error(builder, JavaErrorMessages.message("expected.lbrace"));
}
if (!expect(builder, JavaTokenType.SEMICOLON) && builder.getTokenType() == JavaTokenType.LBRACE) {
myParser.getStatementParser().parseCodeBlock(builder);
if (!expect(builder, JavaTokenType.SEMICOLON)) {
if (builder.getTokenType() == JavaTokenType.LBRACE) {
myParser.getStatementParser().parseCodeBlock(builder);
}
}
done(declaration, anno ? JavaElementType.ANNOTATION_METHOD : JavaElementType.METHOD);

View File

@@ -18,9 +18,10 @@ package com.intellij.psi.impl.cache;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.lang.LighterASTTokenNode;
import com.intellij.psi.*;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.impl.java.stubs.*;
import com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.PsiFileStub;
@@ -110,12 +111,7 @@ public class RecordUtil {
else if (parent instanceof PsiMethodStub) {
if (grandParent instanceof PsiClassStub && ((PsiClassStub)grandParent).isInterface()) {
packed |= ModifierFlags.PUBLIC_MASK;
if (parent instanceof PsiMethodStubImpl && ((PsiMethodStubImpl)parent).hasExtensionMethodMark()) {
packed |= ModifierFlags.DEFENDER_MASK;
}
else {
packed |= ModifierFlags.ABSTRACT_MASK;
}
packed |= ModifierFlags.ABSTRACT_MASK;
}
}
else if (parent instanceof PsiFieldStub) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -73,7 +73,6 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
boolean isVarArgs = false;
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean isExtension = false;
String defValueText = null;
boolean expectingDef = false;
@@ -103,24 +102,18 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
else if (type == JavaTokenType.DEFAULT_KEYWORD) {
expectingDef = true;
}
else if (expectingDef && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
if (type != JavaElementType.CODE_BLOCK) {
defValueText = LightTreeUtil.toFilteredString(tree, child, null);
}
else {
isExtension = true;
}
else if (expectingDef && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) &&
type != JavaTokenType.SEMICOLON && type != JavaElementType.CODE_BLOCK) {
defValueText = LightTreeUtil.toFilteredString(tree, child, null);
break;
}
}
final TypeInfo typeInfo = isConstructor ? TypeInfo.createConstructorType() : TypeInfo.create(tree, node, parentStub);
final boolean isAnno = (node.getTokenType() == JavaElementType.ANNOTATION_METHOD);
final byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation);
TypeInfo typeInfo = isConstructor ? TypeInfo.createConstructorType() : TypeInfo.create(tree, node, parentStub);
boolean isAnno = (node.getTokenType() == JavaElementType.ANNOTATION_METHOD);
byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation);
final PsiMethodStubImpl stub = new PsiMethodStubImpl(parentStub, StringRef.fromString(name), typeInfo, flags, StringRef.fromString(defValueText));
stub.setExtensionMethodMark(isExtension);
return stub;
return new PsiMethodStubImpl(parentStub, StringRef.fromString(name), typeInfo, flags, StringRef.fromString(defValueText));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -37,8 +37,6 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
private final byte myFlags;
private final StringRef myName;
private StringRef myDefaultValueText;
// todo[r.sh] drop this after transition period finished
private boolean myHasExtMethodMark = false;
private static final int CONSTRUCTOR = 0x01;
private static final int VARARGS = 0x02;
@@ -74,14 +72,6 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
myReturnType = returnType;
}
public void setExtensionMethodMark(boolean hasExtMethodMark) {
myHasExtMethodMark = hasExtMethodMark;
}
public boolean hasExtensionMethodMark() {
return myHasExtMethodMark;
}
@Override
public boolean isConstructor() {
return (myFlags & CONSTRUCTOR) != 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -30,15 +30,12 @@ import com.intellij.psi.impl.source.tree.Factory;
import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.impl.source.tree.java.PsiAnnotationImpl;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
@@ -134,12 +131,9 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
return false;
}
if (type == JavaTokenType.ABSTRACT_KEYWORD) {
return !(getNode().findChildByType(JavaTokenType.DEFAULT_KEYWORD) != null || findExtensionMethodMarker((PsiMethod)parent) != null);
return getNode().findChildByType(JavaTokenType.DEFAULT_KEYWORD) == null;
}
}
if (type == JavaTokenType.DEFAULT_KEYWORD && findExtensionMethodMarker((PsiMethod)parent) != null) {
return true;
}
}
else if (parent instanceof PsiField) {
if (parent instanceof PsiEnumConstant) {
@@ -179,16 +173,6 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
return getNode().findChildByType(type) != null;
}
@Nullable
public static PsiJavaToken findExtensionMethodMarker(@Nullable PsiMethod method) {
// todo[r.sh] drop this after transition period finished
if (method == null) return null;
final PsiCodeBlock body = method.getBody();
if (body == null) return null;
final PsiElement previous = PsiTreeUtil.skipSiblingsBackward(body, PsiComment.class, PsiWhiteSpace.class);
return previous instanceof PsiJavaToken && PsiUtil.isJavaToken(previous, JavaTokenType.DEFAULT_KEYWORD) ? (PsiJavaToken)previous : null;
}
@Override
public boolean hasExplicitModifier(@NotNull String name) {
final CompositeElement tree = (CompositeElement)getNode();
@@ -234,7 +218,6 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
}
else if (parent instanceof PsiMethod && grandParent instanceof PsiClass && ((PsiClass)grandParent).isInterface()) {
if (type == JavaTokenType.PUBLIC_KEYWORD || type == JavaTokenType.ABSTRACT_KEYWORD) return;
if (type == JavaTokenType.DEFAULT_KEYWORD && findExtensionMethodMarker((PsiMethod)parent) != null) return;
}
else if (parent instanceof PsiClass && grandParent instanceof PsiClass && ((PsiClass)grandParent).isInterface()) {
if (type == JavaTokenType.PUBLIC_KEYWORD) return;
@@ -257,13 +240,6 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
if (child != null) {
SourceTreeToPsiMap.treeToPsiNotNull(child).delete();
}
if (type == JavaTokenType.DEFAULT_KEYWORD && parent instanceof PsiMethod) {
final PsiJavaToken marker = findExtensionMethodMarker((PsiMethod)parent);
if (marker != null) {
marker.delete();
}
}
}
}

View File

@@ -44,6 +44,6 @@ class UnsupportedFeatures {
}
interface I {
<error descr="Extension methods are not supported at this language level">void m() default { }</error>
<error descr="Extension methods are not supported at this language level">default void m() { }</error>
}
}

View File

@@ -1,10 +1,11 @@
class Test {
public static final BinaryOperator<Integer> rPlus = (x, y) -> x + y;
interface BinaryOperator<T> extends Combiner<T,T,T> {
public T operate(T left, T right);
@Override
T combine(T t1, T t2) default {
default T combine(T t1, T t2) {
return operate(t1, t2);
}
}
@@ -13,5 +14,3 @@ class Test {
V combine(T t, U u);
}
}

View File

@@ -1,8 +0,0 @@
interface I {
void m1() <error descr="Deprecated extension method syntax">default</error> { }
default void m2() <error descr="Deprecated extension method syntax">default</error> { }
@SuppressWarnings("extensionSyntax")
void m3() default { }
}

View File

@@ -17,11 +17,11 @@
class C {
interface I {
int i = 42;
void m() default { }
default void m() { }
}
interface II extends I {
void m() default {
default void m() {
I.super.m();
<error descr="Unqualified super reference is not allowed in extension method">super.m</error>();
@@ -46,18 +46,18 @@ class C {
}
class D {
<error descr="Extension methods can only be used within an interface">void m()</error> default { }
<error descr="Extension methods can only be used within an interface">default void m()</error> { }
}
interface IllegalMods {
<error descr="Static methods in interfaces should have a body">static void m1()</error>;
<error descr="Illegal combination of modifiers: 'static' and 'default'">static</error> void m2() default { }
void m1()<error descr="'{' or ';' expected"> </error>default<error descr="Identifier or type expected">;</error> <error descr="Not allowed in interface">{ }</error>
<error descr="Static methods in interfaces should have a body">static void m2()</error>;
<error descr="Illegal combination of modifiers: 'static' and 'default'">static</error> <error descr="Illegal combination of modifiers: 'default' and 'static'">default</error> void m3() { }
<error descr="Illegal combination of modifiers: 'abstract' and 'default'">abstract</error> void m4() default { }
<error descr="Illegal combination of modifiers: 'abstract' and 'default'">abstract</error> <error descr="Illegal combination of modifiers: 'default' and 'abstract'">default</error> void m5() { }
<error descr="Illegal combination of modifiers: 'abstract' and 'default'">abstract</error> <error descr="Illegal combination of modifiers: 'default' and 'abstract'">default</error> void m4() { }
<error descr="Extension method should have a body">default void m6()</error>;
<error descr="Extension method should have a body">default void m5()</error>;
<error descr="Modifier 'default' not allowed here">default</error> int i;
<error descr="Modifier 'default' not allowed here">default</error> interface X { }

View File

@@ -1,6 +1,6 @@
import java.util.*;
class MyTest2{
class MyTest2 {
{
Comparator<? super String> comparator = String::compareToIgnoreCase;
}
@@ -16,5 +16,5 @@ interface Foo2<T> {
void bar(T i, T j);
}
interface Bar2 {
public void xxx(Bar2 p) default {}
default void xxx(Bar2 p) { }
}

View File

@@ -7,7 +7,7 @@ class Test {
interface InOut<A> {
A run() throws IOException;
<B> InOut<B> bind(final Eff<A, InOut<B>> f) default {
default <B> InOut<B> bind(final Eff<A, InOut<B>> f) {
return () -> f.f(InOut.this.run()).run();
}
}

View File

@@ -7,7 +7,7 @@ class Test {
interface InOut<A> {
A run() throws IOException;
<B> InOut<B> bind(final Eff<A, InOut<B>> f) default {
default <B> InOut<B> bind(final Eff<A, InOut<B>> f) {
return new In<caret>Out<B>() {
@Override
public B run() throws IOException {

View File

@@ -4,7 +4,7 @@ interface A<T> {
}
interface B<T> extends A<T> {
void m1(T t) default { }
default void m1(T t) { }
}
class MyClass<T> implements B<T> {

View File

@@ -1,5 +1,5 @@
interface A<T> {
void m(T t) default { }
default void m(T t) { }
}
class MyClass<T> implements A<T> {

View File

@@ -4,7 +4,7 @@ interface A<T> {
}
interface B<T> extends A<T> {
void m1(T t) default { }
default void m1(T t) { }
}
class MyClass<T> implements B<T> {

View File

@@ -1,5 +1,5 @@
interface A<T> {
void m(T t) default { }
default void m(T t) { }
}
class MyClass<T> implements A<T> {

View File

@@ -2,10 +2,11 @@ PsiJavaFile:Extension.java
PsiJavaToken:LBRACE('{')
PsiWhiteSpace(' ')
PsiMethod:f
PsiModifierList:
<empty list>
PsiModifierList:default
PsiKeyword:default('default')
PsiTypeParameterList
<empty list>
PsiWhiteSpace(' ')
PsiTypeElement:int
PsiKeyword:int('int')
PsiWhiteSpace(' ')
@@ -22,8 +23,6 @@ PsiJavaFile:Extension.java
PsiReferenceParameterList
<empty list>
PsiWhiteSpace(' ')
PsiKeyword:default('default')
PsiWhiteSpace(' ')
PsiCodeBlock
PsiJavaToken:LBRACE('{')
PsiWhiteSpace(' ')
@@ -36,4 +35,4 @@ PsiJavaFile:Extension.java
PsiWhiteSpace(' ')
PsiJavaToken:RBRACE('}')
PsiWhiteSpace(' ')
PsiJavaToken:RBRACE('}')
PsiJavaToken:RBRACE('}')

View File

@@ -15,9 +15,12 @@ PsiJavaFile:Unclosed8.java
PsiJavaToken:RPARENTH(')')
PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiKeyword:default('default')
PsiErrorElement:'{' or ';' expected
<empty list>
PsiWhiteSpace(' ')
PsiJavaToken:RBRACE('}')
PsiModifierList:default
PsiKeyword:default('default')
PsiErrorElement:Identifier or type expected
<empty list>
PsiWhiteSpace(' ')
PsiJavaToken:RBRACE('}')

View File

@@ -1,25 +0,0 @@
PsiJavaFile:Unclosed9.java
PsiJavaToken:LBRACE('{')
PsiWhiteSpace(' ')
PsiMethod:f
PsiModifierList:
<empty list>
PsiTypeParameterList
<empty list>
PsiTypeElement:void
PsiKeyword:void('void')
PsiWhiteSpace(' ')
PsiIdentifier:f('f')
PsiParameterList:()
PsiJavaToken:LPARENTH('(')
PsiJavaToken:RPARENTH(')')
PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiKeyword:default('default')
PsiErrorElement:'{' expected
<empty list>
PsiWhiteSpace(' ')
PsiJavaToken:SEMICOLON(';')
PsiWhiteSpace(' ')
PsiJavaToken:RBRACE('}')

View File

@@ -2,7 +2,7 @@ interface Base {
}
interface I2 extends Base {
void foo<caret>() default {
default void foo<caret>() {
System.out.println("Hi there.");
}
}

View File

@@ -1,5 +1,5 @@
interface Base {
void foo() default {
default void foo() {
System.out.println("Hi there.");
}
}

View File

@@ -1,5 +1,5 @@
interface Base {
void foo<caret>() default {
default void foo<caret>() {
System.out.println("Hi there.");
}
}

View File

@@ -1,5 +1,5 @@
interface Base {
void foo<caret>() default {
default void foo<caret>() {
System.out.println("Hi there.");
}
}

View File

@@ -2,7 +2,7 @@ interface Base {
}
interface I2 extends Base {
void foo() default {
default void foo() {
System.out.println("Hi there.");
}
}

View File

@@ -16,7 +16,6 @@
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInspection.deprecation.DeprecatedDefenderSyntaxInspection;
import org.jetbrains.annotations.NonNls;
public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCase {
@@ -31,11 +30,6 @@ public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCa
public void testStaticMethodsInFunctionalInterface() { doTest(false, false); }
public void testCyclicSubstitutor() { doTest(false, false); }
public void testExtensionMethodSyntax() {
enableInspectionTools(DeprecatedDefenderSyntaxInspection.class);
doTest(true, false);
}
private void doTest() {
doTest(false, false);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -79,7 +79,7 @@ public class DeclarationParserTest extends JavaParsingTestCase {
public void testMethodNormal2() { doParserTest("{ default public void f() { } }", false, false); }
public void testSemicolons() { doParserTest("{ void f() {}; void g() {}; }", false, false); }
public void testUnclosed0() { doParserTest("{ void f() }", false, false); }
public void testExtension() { doParserTest("{ int f() throws E default { return 42; } }", false, false); }
public void testExtension() { doParserTest("{ default int f() throws E { return 42; } }", false, false); }
public void testUnclosed1() { doParserTest("{ void f( }", false, false); }
public void testUnclosed2() { doParserTest("{ void f()\n void g(); }", false, false); }
public void testUnclosed3() { doParserTest("{ void f(int a }", false, false); }
@@ -88,7 +88,6 @@ public class DeclarationParserTest extends JavaParsingTestCase {
public void testUnclosed6() { doParserTest("{ void f() default ; }", true, false); }
public void testUnclosed7() { doParserTest("{ void f() default {return 42;} }", true, false); }
public void testUnclosed8() { doParserTest("{ void f() default }", false, false); }
public void testUnclosed9() { doParserTest("{ void f() default ; }", false, false); }
public void testConstructorBrackets() { doParserTest("{ A() [] { } }", false, false); }
public void testVarArgBrackets() { doParserTest("{ void foo(int... x[]); }", false, false); }
@@ -104,7 +103,7 @@ public class DeclarationParserTest extends JavaParsingTestCase {
public void testParameterAnnotation() { doParserTest("{ void foo (@Annotation(value=77) int param) {} }", false, false); }
public void testParameterizedMethod() { doParserTest("{ @Nullable <T> T bar() {} }", false, false); }
private void doParserTest(final String text, final boolean isAnnotation, final boolean isEnum) {
private void doParserTest(String text, boolean isAnnotation, boolean isEnum) {
doParserTest(text, new MyTestParser(isAnnotation, isEnum));
}
@@ -118,7 +117,7 @@ public class DeclarationParserTest extends JavaParsingTestCase {
}
@Override
public void parse(final PsiBuilder builder) {
public void parse(PsiBuilder builder) {
JavaParser.INSTANCE.getDeclarationParser().parseClassBodyWithBraces(builder, myAnnotation, myAnEnum);
}
}

View File

@@ -1,56 +0,0 @@
/*
* 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.psi.impl.source.tree.java;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.util.PsiUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
public class PsiModifierListTest extends LightCodeInsightFixtureTestCase {
// todo[r.sh] drop this after transition period finished
public void testDefaultModifier() throws Exception {
final PsiFile file = myFixture.configureByText(JavaFileType.INSTANCE,
"class C {\n" +
" default void m() default {\n" +
" }\n" +
"}");
final PsiMethod method = ((PsiJavaFile)file).getClasses()[0].getMethods()[0];
assertEquals("default void m() default {\n }", method.getText());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
PsiUtil.setModifierProperty(method, PsiModifier.DEFAULT, false);
CodeStyleManager.getInstance(getProject()).reformat(method);
}
});
assertEquals("void m() {\n }", method.getText());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
PsiUtil.setModifierProperty(method, PsiModifier.DEFAULT, true);
}
});
assertEquals("default void m() {\n }", method.getText());
}
}

View File

@@ -670,9 +670,6 @@ inspection.redirect.template=<html><body>Injected element has problem: {0} (in <
nothing.found=Nothing found
special.annotations.list.annotation.pattern=Add Annotations Pattern
deprecated.defender.syntax.description=Deprecated extension method syntax
deprecated.defender.syntax.fix=Convert extension method syntax
inspection.variable.assigned.to.itself.display.name=Variable is assigned to itself
assignment.to.itself.problem.descriptor=Variable ''{0}'' is assigned to itself
assignment.to.declared.variable.problem.descriptor=Variable ''{0}'' is initialized with self assignment

View File

@@ -1,6 +0,0 @@
<html xmlns="http://www.w3.org/1999/html">
<body>
Detects deprecated extension method syntax: <pre>void m() default { }</pre>
Allows to convert it to the correct form: <pre>default void m() { }</pre>
</body>
</html>

View File

@@ -372,7 +372,7 @@
<applicationService serviceInterface="com.intellij.psi.JavaDirectoryService"
serviceImplementation="com.intellij.psi.impl.file.JavaDirectoryServiceImpl"/>
<applicationService serviceInterface="com.intellij.openapi.projectRoots.JavaVersionService"
serviceImplementation="com.intellij.openapi.projectRoots.JavaVersionServiceImpl"/>
@@ -518,9 +518,6 @@
<localInspection language="JAVA" suppressId="deprecation" shortName="Deprecation" displayName="Deprecated API usage" groupName=""
enabledByDefault="true" level="WARNING"
implementationClass="com.intellij.codeInspection.deprecation.DeprecationInspection"/>
<localInspection language="JAVA" suppressId="extensionSyntax" bundle="messages.InspectionsBundle" key="deprecated.defender.syntax.description"
groupName="" enabledByDefault="true" level="ERROR"
implementationClass="com.intellij.codeInspection.deprecation.DeprecatedDefenderSyntaxInspection"/>
<localInspection language="XML" shortName="DeprecatedClassUsageInspection" displayName="Deprecated API usage in XML" groupName="XML"
enabledByDefault="true" level="WARNING" implementationClass="com.intellij.util.xml.DeprecatedClassUsageInspection"/>
<localInspection language="JAVA" shortName="EqualsAndHashcode" bundle="messages.InspectionsBundle" key="inspection.equals.hashcode.display.name"
@@ -859,7 +856,7 @@
<lang.whiteSpaceFormattingStrategy language="JAVA"
implementationClass="com.intellij.psi.formatter.JavadocWhiteSpaceFormattingStrategy"/>
<lang.rearranger language="JAVA" implementationClass="com.intellij.psi.codeStyle.arrangement.JavaRearranger"/>
<lang.documentationProvider language="JAVA" implementationClass="com.intellij.lang.java.JavaDocumentationProvider"/>
<documentationProvider implementation="com.intellij.lang.java.FileDocumentationProvider" order="last"/>
<lang.documentationFixer language="JAVA" implementationClass="com.intellij.codeInsight.documentation.JavaDocCommentFixer"/>