mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
split highlighting test
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+404
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyConstructorNamedArgumentsInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GroovyResultOfIncrementOrDecrementUsedInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
class GrAssignabilityTest extends GrHighlightingTestBase {
|
||||
InspectionProfileEntry[] getCustomInspections() { [new GroovyAssignabilityCheckInspection()] as InspectionProfileEntry[]}
|
||||
|
||||
public void testIncompatibleTypesAssignments() { doTest(); }
|
||||
|
||||
public void testDefaultMapConstructorNamedArgs() {
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
public void testDefaultMapConstructorNamedArgsError() {
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
public void testDefaultMapConstructorWhenDefConstructorExists() {
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
public void testUnresolvedMethodCallWithTwoDeclarations() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConstructor() {
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
public void testEverythingAssignableToString() {doTest();}
|
||||
|
||||
public void testMethodCallWithDefaultParameters() {doTest();}
|
||||
|
||||
public void testClosureWithDefaultParameters() {doTest();}
|
||||
|
||||
public void testClosureCallMethodWithInapplicableArguments() {doTest();}
|
||||
|
||||
public void testCallIsNotApplicable() {doTest();}
|
||||
|
||||
public void testPathCallIsNotApplicable() {doTest();}
|
||||
|
||||
public void testByteArrayArgument() {doTest();}
|
||||
|
||||
public void testPutValueToEmptyMap() {doTest();}
|
||||
|
||||
public void _testPutIncorrectValueToMap() {doTest();} //incorrect test
|
||||
|
||||
public void testTupleTypeAssignments() {doTest();}
|
||||
|
||||
public void testSignatureIsNotApplicableToList() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInheritConstructorsAnnotation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCollectionAssignments() {doTest(); }
|
||||
|
||||
public void testReturnAssignability() {doTest(); }
|
||||
|
||||
public void testMapNotAcceptedAsStringParameter() {doTest();}
|
||||
|
||||
public void testRawTypeInAssignment() {doTest();}
|
||||
|
||||
public void testMapParamWithNoArgs() {doTest();}
|
||||
|
||||
public void testInheritInterfaceInDelegate() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testThisTypeInStaticContext() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnonymousClassArgList() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTupleConstructorAttributes() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCanonicalConstructorApplicability() {
|
||||
myFixture.addClass("package groovy.transform; public @interface Canonical {}");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStringAssignableToChar() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
public void testCurrying() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnotherCurrying() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testResultOfIncUsed() {
|
||||
doTest(new GroovyResultOfIncrementOrDecrementUsedInspection());
|
||||
}
|
||||
|
||||
public void testNativeMapAssignability() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTwoLevelGrMap() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPassingCollectionSubtractionIntoGenericMethod() {
|
||||
doTest(new GrUnresolvedAccessInspection());
|
||||
}
|
||||
|
||||
public void testImplicitEnumCoercion() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnknownVarInArgList() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCallableProperty() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnumConstantConstructors() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLiteralConstructorUsages() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSpreadArguments() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDiamondTypeInferenceSOE() {
|
||||
testHighlighting(''' Map<Integer, String> a; a[2] = [:] ''', false, false, false)
|
||||
}
|
||||
|
||||
void testThisInStaticMethodOfAnonymousClass() {
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
static abc
|
||||
def foo() {
|
||||
new Runnable() {
|
||||
<error descr="Inner classes cannot have static declarations">static</error> void run() {
|
||||
print abc
|
||||
}
|
||||
}.run()
|
||||
}
|
||||
}''', true, false, false);
|
||||
}
|
||||
|
||||
public void testNonInferrableArgsOfDefParams() {
|
||||
testHighlighting('''\
|
||||
def foo0(def a) { }
|
||||
def bar0(def b) { foo0(b) }
|
||||
|
||||
def foo1(Object a) { }
|
||||
def bar1(def b) { foo1(b) }
|
||||
|
||||
def foo2(String a) { }
|
||||
def bar2(def b) { foo2<weak_warning descr="Cannot infer argument types">(b)</weak_warning> }
|
||||
''')
|
||||
}
|
||||
|
||||
public void testPutAtApplicability() {
|
||||
myFixture.addClass("""\
|
||||
package java.util;
|
||||
public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> {}
|
||||
""")
|
||||
|
||||
testHighlighting('''\
|
||||
LinkedHashMap<File, List<File>> files = [:]
|
||||
files[new File('a')] = [new File('b')]
|
||||
files<warning descr="'putAt' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be applied to '(java.io.File, java.io.File)'">[new File('a')]</warning> = new File('b')
|
||||
''')
|
||||
}
|
||||
|
||||
public void testStringToCharAssignability() {
|
||||
testHighlighting('''\
|
||||
def foo(char c){}
|
||||
|
||||
foo<warning descr="'foo' in '_' cannot be applied to '(java.lang.String)'">('a')</warning>
|
||||
foo('a' as char)
|
||||
foo('a' as Character)
|
||||
|
||||
char c = 'a'
|
||||
''')
|
||||
}
|
||||
|
||||
void testMethodRefs1() {
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
int foo(){2}
|
||||
|
||||
Date foo(int x) {null}
|
||||
}
|
||||
|
||||
def foo = new A().&foo
|
||||
|
||||
int i = foo()
|
||||
int i2 = <warning descr="Cannot assign 'Date' to 'int'">foo(2)</warning>
|
||||
Date d = foo(2)
|
||||
Date d2 = <warning descr="Cannot assign 'Integer' to 'Date'">foo()</warning>
|
||||
''')
|
||||
}
|
||||
|
||||
void testMethodRefs2() {
|
||||
testHighlighting('''\
|
||||
class Bar {
|
||||
def foo(int i, String s2) {s2}
|
||||
def foo(int i, int i2) {i2}
|
||||
}
|
||||
|
||||
def cl = new Bar<error descr="'(' expected">.</error>&foo
|
||||
cl = cl.curry(1)
|
||||
String s = cl("2")
|
||||
int s2 = <warning descr="Cannot assign 'String' to 'int'">cl("2")</warning>
|
||||
int i = cl(3)
|
||||
String i2 = cl(3)
|
||||
''')
|
||||
}
|
||||
|
||||
void testThrowObject() {
|
||||
testHighlighting('''\
|
||||
def foo() {
|
||||
throw new RuntimeException()
|
||||
}
|
||||
def bar () {
|
||||
throw <warning descr="Cannot assign 'Object' to 'Throwable'">new Object()</warning>
|
||||
}
|
||||
|
||||
def test() {
|
||||
throw new Throwable()
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testCategoryWithPrimitiveType() {
|
||||
testHighlighting('''\
|
||||
class Cat {
|
||||
static foo(Integer x) {}
|
||||
}
|
||||
|
||||
use(Cat) {
|
||||
1.with {
|
||||
foo()
|
||||
}
|
||||
|
||||
(1 as int).foo()
|
||||
}
|
||||
|
||||
class Ca {
|
||||
static foo(int x) {}
|
||||
}
|
||||
|
||||
use(Ca) {
|
||||
1.<warning descr="Category method 'foo' cannot be applied to 'java.lang.Integer'">foo</warning>()
|
||||
(1 as int).<warning descr="Category method 'foo' cannot be applied to 'java.lang.Integer'">foo</warning>()
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testCompileStaticWithAssignabilityCheck() {
|
||||
myFixture.addClass('''\
|
||||
package groovy.transform;
|
||||
public @interface CompileStatic {
|
||||
}''')
|
||||
|
||||
testHighlighting('''\
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
class A {
|
||||
|
||||
def foo(String s) {
|
||||
int x = <warning descr="Cannot assign 'Date' to 'int'">new Date()</warning>
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
def bar() {
|
||||
int x = <error descr="Cannot assign 'Date' to 'int'">new Date()</error>
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testClosuresInAnnotations() {
|
||||
testHighlighting('''\
|
||||
@interface Test {
|
||||
Class value()
|
||||
}
|
||||
|
||||
@interface Other {
|
||||
String value()
|
||||
}
|
||||
|
||||
@Test({String}) def foo1(){}
|
||||
@Test({2.class}) def foo2(){}
|
||||
@Test({2}) def foo3(){}
|
||||
@Test({abc}) def foo4(){}
|
||||
@Test(String) def foo5(){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTupleAssignment() {
|
||||
testHighlighting('''\
|
||||
def (String x, int y)
|
||||
(x, <warning descr="Cannot assign 'String' to 'Integer'">y</warning>) = foo()
|
||||
|
||||
print x + y
|
||||
|
||||
List<String> foo() {[]}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTupleDeclaration() {
|
||||
testHighlighting('''\
|
||||
def (int <warning descr="Cannot assign 'String' to 'int'">x</warning>, String y) = foo()
|
||||
|
||||
List<String> foo() {[]}
|
||||
''')
|
||||
}
|
||||
|
||||
void testCastClosureToInterface() {
|
||||
testHighlighting('''\
|
||||
interface Function<D, F> {
|
||||
F fun(D d)
|
||||
}
|
||||
|
||||
def foo(Function<String, String> function) {
|
||||
// print function.fun('abc')
|
||||
}
|
||||
|
||||
|
||||
foo<warning descr="'foo' in '_' cannot be applied to '(Function<java.lang.Double,java.lang.Double>)'">({println it.byteValue()} as Function<Double, Double>)</warning>
|
||||
foo({println it.substring(1)} as Function)
|
||||
foo({println it.substring(1)} as Function<String, String>)
|
||||
foo<warning descr="'foo' in '_' cannot be applied to '(groovy.lang.Closure<java.lang.Void>)'">({println it})</warning>
|
||||
|
||||
''')
|
||||
}
|
||||
|
||||
void testVarargsWithoutTypeName() {
|
||||
testHighlighting('''\
|
||||
def foo(String key, ... params) {
|
||||
|
||||
}
|
||||
|
||||
foo('anc')
|
||||
foo('abc', 1, '')
|
||||
foo<warning descr="'foo' in '_' cannot be applied to '(java.lang.Integer)'">(5)</warning>
|
||||
''')
|
||||
}
|
||||
|
||||
void testIncorrectReturnValue() {
|
||||
testHighlighting('''\
|
||||
private int getObjects() {
|
||||
try {
|
||||
def t = "test";
|
||||
t.substring(0);
|
||||
}
|
||||
finally {
|
||||
//...
|
||||
}
|
||||
|
||||
return <warning descr="Cannot assign 'String' to 'int'">''</warning>;
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
|
||||
void testForInAssignability() {
|
||||
testHighlighting('''\
|
||||
for (int <warning descr="Cannot assign 'String' to 'int'">x</warning> in ['a']){}
|
||||
''')
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.codeInspection.LocalInspectionTool
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
abstract class GrHighlightingTestBase extends LightGroovyTestCase {
|
||||
final String basePath = TestUtils.testDataPath + 'highlighting/'
|
||||
|
||||
InspectionProfileEntry[] getCustomInspections() {[]}
|
||||
|
||||
void doTest(boolean checkWarnings = true, boolean checkInfos = false, boolean checkWeakWarnings = true, InspectionProfileEntry... tools) {
|
||||
myFixture.enableInspections(tools);
|
||||
myFixture.enableInspections(customInspections)
|
||||
myFixture.testHighlighting(checkWarnings, checkInfos, checkWeakWarnings, getTestName(false) + ".groovy");
|
||||
}
|
||||
|
||||
void doRefTest(boolean checkWarnings = true, boolean checkInfos = false, boolean checkWeakWarnings = true, InspectionProfileEntry... tools) {
|
||||
myFixture.enableInspections(new GrUnresolvedAccessInspection())
|
||||
myFixture.enableInspections(tools)
|
||||
myFixture.enableInspections(customInspections)
|
||||
myFixture.testHighlighting(checkWarnings, checkInfos, checkWeakWarnings, getTestName(false) + '.groovy')
|
||||
}
|
||||
|
||||
void testHighlighting(String text, boolean checkWarnings = true, boolean checkInfos = false, boolean checkWeakWarnings = true, Class<? extends LocalInspectionTool>... inspections) {
|
||||
myFixture.configureByText('_.groovy', text)
|
||||
myFixture.enableInspections(inspections)
|
||||
myFixture.enableInspections(customInspections)
|
||||
myFixture.testHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
|
||||
}
|
||||
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyResultOfAssignmentUsedInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.*
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.*
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryReturnInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUntypedAccessInspection
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
class GrInspectionTest extends GrHighlightingTestBase {
|
||||
public void testDontSimplifyString() { doTest(new GroovyTrivialIfInspection(), new GroovyTrivialConditionalInspection()) }
|
||||
|
||||
public void testSingleAllocationInClosure() {doTest(new GroovyResultOfObjectAllocationIgnoredInspection()) }
|
||||
|
||||
public void testUnusedAllocationInClosure() {doTest(new GroovyResultOfObjectAllocationIgnoredInspection()) }
|
||||
|
||||
public void testUsedLabel() {doTest(new GroovyLabeledStatementInspection())}
|
||||
|
||||
public void testOverlyLongMethodInspection() {doTest(new GroovyOverlyLongMethodInspection())}
|
||||
|
||||
public void testInaccessibleConstructorCall() { doTest(new GroovyAccessibilityInspection()) }
|
||||
|
||||
public void testRangeType() { doTest(new GroovyRangeTypeCheckInspection()) }
|
||||
|
||||
public void testResolveMetaClass() { doTest(new GroovyAccessibilityInspection()) }
|
||||
|
||||
public void testResultOfAssignmentUsed() { doTest(new GroovyResultOfAssignmentUsedInspection()) }
|
||||
|
||||
public void testSuppressions() { doTest(new GrUnresolvedAccessInspection(), new GroovyUntypedAccessInspection()) }
|
||||
|
||||
public void testInnerClassConstructorThis() { doTest(true, true, true, new GroovyResultOfAssignmentUsedInspection()) }
|
||||
|
||||
public void testUnnecessaryReturnInSwitch() { doTest(new GroovyUnnecessaryReturnInspection()) }
|
||||
|
||||
public void testMemberShipOperatorCheck() { doTest(new GroovyInArgumentCheckInspection()) }
|
||||
|
||||
void testOctalInspection() { doTest(new GroovyOctalIntegerInspection()) }
|
||||
|
||||
void testClashingGetters() {
|
||||
testHighlighting('''\
|
||||
class Foo {
|
||||
|
||||
boolean <warning descr="getter 'getX' clashes with getter 'isX'">getX</warning>() { true }
|
||||
boolean <warning descr="getter 'isX' clashes with getter 'getX'">isX</warning>() { false }
|
||||
|
||||
boolean getY() {true}
|
||||
|
||||
boolean isZ() {false}
|
||||
|
||||
boolean <warning descr="method getFoo(int x) clashes with getter 'isFoo'">getFoo</warning>(int x = 5){}
|
||||
boolean <warning descr="getter 'isFoo' clashes with method getFoo(int x)">isFoo</warning>(){}
|
||||
}
|
||||
|
||||
def result = new Foo().x''', true, false, false, ClashingGettersInspection)
|
||||
}
|
||||
|
||||
public void testDeprecated() {
|
||||
testHighlighting('''\
|
||||
/**
|
||||
@deprecated
|
||||
*/
|
||||
class X {
|
||||
@Deprecated
|
||||
def foo(){}
|
||||
|
||||
public static void main() {
|
||||
new <warning descr="'X' is deprecated">X</warning>().<warning descr="'foo' is deprecated">foo</warning>()
|
||||
}
|
||||
}''', true, false, false, GrDeprecatedAPIUsageInspection)
|
||||
}
|
||||
|
||||
public void testSuppressedErrorInGroovyDoc() {
|
||||
testHighlighting('''\
|
||||
class Class2 {
|
||||
|
||||
|
||||
/** dependency injection for {@link GrailsFilterInvocationDefinition} */
|
||||
@SuppressWarnings("GroovyDocCheck")
|
||||
static main(args) {}
|
||||
|
||||
/** dependency injection for {@link <error descr="Cannot resolve symbol 'GrailsFilterInvocationDefinition'">GrailsFilterInvocationDefinition</error>} */
|
||||
static main2(args) {}
|
||||
}''', GroovyDocCheckInspection)
|
||||
}
|
||||
|
||||
void testMissingReturnInBinaryOr() {
|
||||
testHighlighting('''\
|
||||
private boolean onWinOrMacOS_() {
|
||||
OperatingSystem.isWindows() || OperatingSystem.isMacOsX()
|
||||
}
|
||||
private boolean onWinOrMacOS() {
|
||||
if (true) {
|
||||
OperatingSystem.isWindows() || OperatingSystem.isMacOsX()
|
||||
}
|
||||
<warning descr="Not all execution paths return a value">}</warning>
|
||||
|
||||
''', MissingReturnInspection)
|
||||
}
|
||||
|
||||
void testReassignedVarInClosureInspection() {
|
||||
addCompileStatic()
|
||||
testHighlighting("""\
|
||||
test() {
|
||||
def var = "abc"
|
||||
def cl = {
|
||||
<warning descr="Local variable var is reassigned in closure with other type">var</warning> = new Date()
|
||||
}
|
||||
cl()
|
||||
var.toUpperCase()
|
||||
}
|
||||
|
||||
test2() {
|
||||
def var = "abc"
|
||||
def cl = {
|
||||
var = 'cde'
|
||||
}
|
||||
cl()
|
||||
var.toUpperCase()
|
||||
}
|
||||
""", GrReassignedInClosureLocalVarInspection)
|
||||
}
|
||||
|
||||
void testPackageDefinition() {
|
||||
myFixture.addFileToProject('cde/bar.groovy', '//empty file')
|
||||
myFixture.addFileToProject('abc/foo.groovy', '''\
|
||||
<warning descr="Package name mismatch. Actual: 'cde', expected: 'abc'">package cde</warning>
|
||||
|
||||
print 2
|
||||
''')
|
||||
myFixture.enableInspections(new GrPackageInspection())
|
||||
myFixture.testHighlighting(true, false, false, 'abc/foo.groovy')
|
||||
}
|
||||
|
||||
void testPackageDefinition2() {
|
||||
myFixture.addFileToProject('abc/foo.groovy', '''\
|
||||
<warning descr="Package name mismatch. Actual: 'cde', expected: 'abc'">package cde</warning>
|
||||
|
||||
print 2
|
||||
''')
|
||||
myFixture.enableInspections(new GrPackageInspection())
|
||||
myFixture.testHighlighting(true, false, false, 'abc/foo.groovy')
|
||||
}
|
||||
|
||||
public void testStaticImportProperty() {
|
||||
myFixture.addFileToProject('Foo.groovy', '''\
|
||||
class Foo {
|
||||
static def foo = 2
|
||||
private static def bar = 3
|
||||
|
||||
private static def baz = 4
|
||||
|
||||
private static def getBaz() {baz}
|
||||
}
|
||||
''')
|
||||
testHighlighting('''\
|
||||
import static Foo.foo
|
||||
import static Foo.<warning descr="Access to 'bar' exceeds its access rights">bar</warning>
|
||||
import static Foo.<warning descr="Access to 'baz' exceeds its access rights">baz</warning>
|
||||
|
||||
print foo+<warning descr="Access to 'bar' exceeds its access rights">bar</warning>+<warning descr="Access to 'baz' exceeds its access rights">baz</warning>
|
||||
''', GroovyAccessibilityInspection)
|
||||
}
|
||||
|
||||
public void testUntypedAccess() { doTest(new GroovyUntypedAccessInspection()) }
|
||||
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import org.jetbrains.plugins.groovy.codeInspection.unassignedVariable.UnassignedVariableAccessInspection
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
class GrUnassignedVariableAccessTest extends GrHighlightingTestBase {
|
||||
@Override
|
||||
InspectionProfileEntry[] getCustomInspections() {
|
||||
[new UnassignedVariableAccessInspection()] as InspectionProfileEntry[]
|
||||
}
|
||||
|
||||
public void testUnassigned1() { doTest() }
|
||||
|
||||
public void testUnassigned2() { doTest() }
|
||||
|
||||
public void testUnassigned3() { doTest() }
|
||||
|
||||
public void testUnassigned4() { doTest() }
|
||||
|
||||
public void testUnassignedTryFinally() { doTest() }
|
||||
|
||||
|
||||
void testVarIsNotInitialized() {
|
||||
testHighlighting('''\
|
||||
def xxx() {
|
||||
def category = null
|
||||
for (def update : updateIds) {
|
||||
def p = update
|
||||
|
||||
if (something) {
|
||||
category = p
|
||||
}
|
||||
|
||||
print p
|
||||
}
|
||||
}
|
||||
|
||||
def bar() {
|
||||
def p
|
||||
print <warning descr="Variable 'p' might not be assigned">p</warning>
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testUnassignedAccessInCheck() {
|
||||
def inspection = new UnassignedVariableAccessInspection()
|
||||
inspection.myIgnoreBooleanExpressions = true
|
||||
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
def foo
|
||||
if (foo) print 'fooo!!!'
|
||||
|
||||
def bar
|
||||
if (bar!=null) print 'foo!!!'
|
||||
|
||||
def baz
|
||||
if (<warning descr="Variable 'baz' might not be assigned">baz</warning> + 2) print "fooooo!"
|
||||
''')
|
||||
myFixture.enableInspections(inspection)
|
||||
myFixture.testHighlighting(true, false, true)
|
||||
}
|
||||
|
||||
public void testVarNotAssigned() { doTest() }
|
||||
|
||||
public void testMultipleVarNotAssigned() { doTest() }
|
||||
|
||||
public void testForLoopWithNestedEndlessLoop() {doTest()}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
class GrUncheckedAssignmentOfRawTypeTest extends GrHighlightingTestBase {
|
||||
@Override
|
||||
InspectionProfileEntry[] getCustomInspections() {
|
||||
[new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()] as InspectionProfileEntry[]
|
||||
}
|
||||
|
||||
public void testRawMethodAccess() { doTest() }
|
||||
|
||||
public void testRawFieldAccess() { doTest() }
|
||||
|
||||
public void testRawArrayStyleAccess() { doTest() }
|
||||
|
||||
public void testRawArrayStyleAccessToMap() { doTest() }
|
||||
|
||||
public void testRawArrayStyleAccessToList() { doTest() }
|
||||
|
||||
public void testRawClosureReturnType() {
|
||||
testHighlighting('''\
|
||||
class A<T> {
|
||||
A(T t) {this.t = t}
|
||||
|
||||
T t
|
||||
def cl = {
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def a = new A(new Date())
|
||||
Date d = <warning descr="Cannot assign 'Object' to 'Date'">a.cl()</warning>
|
||||
''')
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyResultOfAssignmentUsedInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GrUnusedIncDecInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
class GrUnusedDefTest extends GrHighlightingTestBase {
|
||||
@Override
|
||||
InspectionProfileEntry[] getCustomInspections() {
|
||||
return [new UnusedDefInspection(), new GrUnusedIncDecInspection(), new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspection(), new GroovyResultOfAssignmentUsedInspection()] as InspectionProfileEntry[]
|
||||
}
|
||||
|
||||
public void testUnusedVariable() { doTest() }
|
||||
|
||||
public void testDefinitionUsedInClosure() { doTest() }
|
||||
|
||||
public void testDefinitionUsedInClosure2() { doTest() }
|
||||
|
||||
public void testDefinitionUsedInSwitchCase() { doTest() }
|
||||
|
||||
public void testUnusedDefinitionForMethodMissing() { doTest()}
|
||||
|
||||
public void testPrefixIncrementCfa() { doTest() }
|
||||
|
||||
public void testIfIncrementElseReturn() { doTest() }
|
||||
|
||||
public void testSwitchControlFlow() { doTest()}
|
||||
|
||||
public void testUsageInInjection() { doTest() }
|
||||
|
||||
public void testUnusedDefsForArgs() { doTest() }
|
||||
|
||||
public void testUsedDefBeforeTry1() { doTest() }
|
||||
|
||||
public void testUsedDefBeforeTry2() { doTest() }
|
||||
|
||||
public void testUnusedInc() { doTest() }
|
||||
|
||||
public void testUsedInCatch() { doTest() }
|
||||
|
||||
public void testGloballyUnusedSymbols() { doTest() }
|
||||
|
||||
public void testGloballyUnusedInnerMethods() {
|
||||
myFixture.addClass 'package junit.framework public class TestCase {}'
|
||||
doTest()
|
||||
}
|
||||
|
||||
public void testUnusedParameter() { doTest() }
|
||||
|
||||
public void testSuppressUnusedMethod() {
|
||||
testHighlighting('''\
|
||||
class <warning descr="Class Foo is unused">Foo</warning> {
|
||||
@SuppressWarnings("GroovyUnusedDeclaration")
|
||||
static def foo(int x) {
|
||||
print 2
|
||||
}
|
||||
|
||||
static def <warning descr="Method bar is unused">bar</warning>() {}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testUsedVar() {
|
||||
testHighlighting('''\
|
||||
def <warning descr="Method foo is unused">foo</warning>(xxx) {
|
||||
if ((<warning descr="Result of assignment expression used">xxx = 5</warning>) || xxx) {
|
||||
<warning descr="Result of assignment expression used"><warning descr="Assignment is not used">xxx</warning>=4</warning>
|
||||
}
|
||||
}
|
||||
|
||||
def <warning descr="Method foxo is unused">foxo</warning>(doo) {
|
||||
def xxx = 'asdf'
|
||||
if (!doo) {
|
||||
println xxx
|
||||
<warning descr="Result of assignment expression used"><warning descr="Assignment is not used">xxx</warning>=5</warning>
|
||||
}
|
||||
}
|
||||
|
||||
def <warning descr="Method bar is unused">bar</warning>(xxx) {
|
||||
print ((<warning descr="Result of assignment expression used">xxx=5</warning>)?:xxx)
|
||||
}
|
||||
|
||||
def <warning descr="Method a is unused">a</warning>(xxx) {
|
||||
if (2 && (<warning descr="Result of assignment expression used">xxx=5</warning>)) {
|
||||
xxx
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testFallthroughInSwitch() {
|
||||
testHighlighting('''\
|
||||
def <warning descr="Method f is unused">f</warning>(String foo, int mode) {
|
||||
switch (mode) {
|
||||
case 0: foo = foo.reverse()
|
||||
case 1: return foo
|
||||
}
|
||||
}
|
||||
|
||||
def <warning descr="Method f2 is unused">f2</warning>(String foo, int mode) {
|
||||
switch (mode) {
|
||||
case 0: <warning descr="Assignment is not used">foo</warning> = foo.reverse()
|
||||
case 1: return 2
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
}
|
||||
+792
@@ -0,0 +1,792 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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 org.jetbrains.plugins.groovy.lang.highlighting
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.siyeh.ig.junit.JUnitAbstractTestClassNamingConventionInspection
|
||||
import com.siyeh.ig.junit.JUnitTestClassNamingConventionInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GrUnusedIncDecInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyResultOfAssignmentUsedInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.bugs.*
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.confusing.*
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryReturnInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUntypedAccessInspection
|
||||
//import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class GroovyHighlightingTest extends GrHighlightingTestBase {
|
||||
|
||||
public void testDuplicateClosurePrivateVariable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClosureRedefiningVariable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCircularInheritance() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEmptyTupleType() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMapDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testShouldntImplementGroovyObjectMethods() {
|
||||
addGroovyObject();
|
||||
myFixture.addFileToProject("Foo.groovy", "class Foo {}");
|
||||
myFixture.testHighlighting(false, false, false, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testJavaClassImplementingGroovyInterface() {
|
||||
addGroovyObject();
|
||||
myFixture.addFileToProject("Foo.groovy", "interface Foo {}");
|
||||
myFixture.testHighlighting(false, false, false, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testDuplicateFields() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoDuplicationThroughClosureBorder() {
|
||||
myFixture.addClass("package groovy.lang; public interface Closure {}");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRecursiveMethodTypeInference() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSuperClassNotExists() {
|
||||
doRefTest()
|
||||
}
|
||||
|
||||
public void testAnonymousClassConstructor() {doTest();}
|
||||
public void testAnonymousClassAbstractMethod() {doTest();}
|
||||
public void testAnonymousClassStaticMethod() {doTest();}
|
||||
public void testAnonymousClassShoudImplementMethods() {doTest();}
|
||||
public void testAnonymousClassShouldImplementSubstitutedMethod() {doTest();}
|
||||
|
||||
public void testUnresolvedLhsAssignment() { doRefTest() }
|
||||
|
||||
public void testUnresolvedAccess() { doRefTest() }
|
||||
public void testBooleanProperties() { doRefTest() }
|
||||
|
||||
public void testDuplicateInnerClass() {doTest();}
|
||||
|
||||
public void testThisInStaticContext() {doTest();}
|
||||
public void testLocalVariableInStaticContext() {doTest();}
|
||||
|
||||
public void testModifiersInPackageAndImportStatements() {
|
||||
myFixture.copyFileToProject(getTestName(false) + ".groovy", "x/"+getTestName(false)+".groovy");
|
||||
myFixture.testHighlighting(true, false, false, "x/"+getTestName(false)+".groovy");
|
||||
}
|
||||
|
||||
public void testBreakOutside() {doTest();}
|
||||
public void testUndefinedLabel() {doTest();}
|
||||
|
||||
public void testNestedMethods() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRawOverridedMethod() {doTest();}
|
||||
|
||||
public void testFQNJavaClassesUsages() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testGstringAssignableToString() {doTest();}
|
||||
public void testGstringAssignableToStringInClosureParameter() {doTest();}
|
||||
|
||||
public void testEachOverRange() {doTest();}
|
||||
|
||||
public void testEllipsisParam() {
|
||||
myFixture.configureByText('a.groovy', '''\
|
||||
class A {
|
||||
def foo(int... x){}
|
||||
def foo(<error descr="Ellipsis type is not allowed here">int...</error> x, double y) {}
|
||||
}
|
||||
''')
|
||||
myFixture.checkHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
public void testStringAndGStringUpperBound() {doTest();}
|
||||
|
||||
public void testWithMethod() {doTest();}
|
||||
|
||||
public void testArrayLikeAccess() {doTest();}
|
||||
|
||||
public void testSetInitializing() {doTest();}
|
||||
|
||||
public void testEmptyTupleAssignability() {doTest();}
|
||||
|
||||
public void testGrDefFieldsArePrivateInJavaCode() {
|
||||
myFixture.configureByText("X.groovy", "public class X{def x=5}");
|
||||
myFixture.testHighlighting(true, false, false, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testSuperConstructorInvocation() {doTest();}
|
||||
|
||||
public void testDuplicateMapKeys() {doTest();}
|
||||
|
||||
public void testIndexPropertyAccess() {doTest();}
|
||||
|
||||
public void testPropertyAndFieldDeclaration() {doTest();}
|
||||
|
||||
public void testGenericsMethodUsage() {doTest();}
|
||||
|
||||
public void testWildcardInExtendsList() {doTest();}
|
||||
|
||||
public void testOverrideAnnotation() {doTest();}
|
||||
|
||||
public void testClosureCallWithTupleTypeArgument() {doTest();}
|
||||
|
||||
public void testMethodDuplicates() {doTest();}
|
||||
|
||||
public void testAmbiguousCodeBlock() {doTest();}
|
||||
public void testAmbiguousCodeBlockInMethodCall() {doTest();}
|
||||
public void testNotAmbiguousClosableBlock() {doTest();}
|
||||
public void testDuplicateParameterInClosableBlock() {doTest();}
|
||||
|
||||
public void testCyclicInheritance() {doTest();}
|
||||
|
||||
public void testNoDefaultConstructor() {doTest();}
|
||||
|
||||
public void testNumberDuplicatesInMaps() {doTest();}
|
||||
|
||||
public void testBuiltInTypeInstantiation() {doTest();}
|
||||
|
||||
public void testSOEInFieldDeclarations() {doTest();}
|
||||
|
||||
public void testVeryLongDfaWithComplexGenerics() {
|
||||
IdeaTestUtil.assertTiming("", 10000, 1, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTest(new GroovyAssignabilityCheckInspection(), new UnusedDefInspection(), new GrUnusedIncDecInspection());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testWrongAnnotation() {doTest();}
|
||||
|
||||
public void testAmbiguousMethods() {
|
||||
myFixture.copyFileToProject(getTestName(false) + ".java");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testGroovyEnumInJavaFile() {
|
||||
myFixture.copyFileToProject(getTestName(false) + ".groovy");
|
||||
myFixture.testHighlighting(true, false, false, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testSOFInDelegate() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMethodImplementedByDelegate() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void _testTestMarkupStubs() {
|
||||
doRefTest()
|
||||
}
|
||||
|
||||
public void testGdslWildcardTypes() {
|
||||
myFixture.configureByText("a.groovy",
|
||||
"List<? extends String> la = []; la.get(1); " +
|
||||
"List<? super String> lb = []; lb.get(1); " +
|
||||
"List<?> lc = []; lc.get(1); "
|
||||
);
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testDuplicatedNamedArgs() {doTest();}
|
||||
|
||||
public void testConstructorWithAllParametersOptional() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTupleConstructorAttributes() {
|
||||
doTest(new GroovyAssignabilityCheckInspection());
|
||||
}
|
||||
|
||||
public void testDelegatedMethodIsImplemented() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnumImplementsAllGroovyObjectMethods() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void _testBuilderMembersAreNotUnresolved() {
|
||||
doRefTest();
|
||||
}
|
||||
|
||||
public void testRecursiveConstructors() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testImmutableConstructorFromJava() {
|
||||
myFixture.addFileToProject "a.groovy", '''@groovy.transform.Immutable class Foo { int a; String b }'''
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class Bar {{
|
||||
new Foo<error>()</error>;
|
||||
new Foo<error>(2)</error>;
|
||||
new Foo(2, "3");
|
||||
}}'''
|
||||
myFixture.checkHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
public void testTupleConstructorFromJava() {
|
||||
myFixture.addFileToProject "a.groovy", '''@groovy.transform.TupleConstructor class Foo { int a; String b }'''
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class Bar {{
|
||||
new Foo();
|
||||
new Foo(2);
|
||||
new Foo(2, "3");
|
||||
new Foo<error>(2, "3", 9)</error>;
|
||||
}}'''
|
||||
myFixture.checkHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
public void testInheritConstructorsFromJava() {
|
||||
myFixture.addFileToProject "a.groovy", '''
|
||||
class Person {
|
||||
Person(String first, String last) { }
|
||||
Person(String first, String last, String address) { }
|
||||
Person(String first, String last, int zip) { }
|
||||
}
|
||||
|
||||
@groovy.transform.InheritConstructors
|
||||
class PersonAge extends Person {
|
||||
PersonAge(String first, String last, int zip) { }
|
||||
}
|
||||
'''
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class Bar {{
|
||||
new PersonAge("a", "b");
|
||||
new PersonAge("a", "b", "c");
|
||||
new PersonAge("a", "b", 239);
|
||||
new PersonAge<error>(2, "3", 9)</error>;
|
||||
}}'''
|
||||
myFixture.checkHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
void testDefaultInitializersAreNotAllowedInAbstractMethods() {doTest()}
|
||||
void testConstructorTypeArgs(){doTest()}
|
||||
|
||||
void testIncorrectEscaping() {doTest()}
|
||||
void testExtendingOwnInner() {doTest()}
|
||||
|
||||
void testRegexInCommandArg() {doTest()}
|
||||
|
||||
public void testJUnitConvention() {
|
||||
myFixture.addClass("package junit.framework; public class TestCase {}")
|
||||
doTest(new JUnitTestClassNamingConventionInspection(), new JUnitAbstractTestClassNamingConventionInspection())
|
||||
}
|
||||
|
||||
void testDuplicateMethods() {
|
||||
myFixture.configureByText('a.groovy', '''\
|
||||
class A {
|
||||
<error descr="Method with signature foo() is already defined in the class 'A'">def foo()</error>{}
|
||||
<error descr="Method with signature foo() is already defined in the class 'A'">def foo(def a=null)</error>{}
|
||||
}
|
||||
''')
|
||||
myFixture.checkHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
void testPrivateTopLevelClassInJava() {
|
||||
myFixture.addFileToProject('pack/Foo.groovy', 'package pack; private class Foo{}')
|
||||
myFixture.configureByText('Abc.java', '''\
|
||||
import pack.Foo;
|
||||
|
||||
class Abc {
|
||||
void foo() {
|
||||
System.out.print(new <error descr="'pack.Foo' has private access in 'pack'">Foo</error>());
|
||||
}
|
||||
}
|
||||
''')
|
||||
|
||||
myFixture.testHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
void testDelegateToMethodWithItsOwnTypeParams() {
|
||||
myFixture.configureByText('a.groovy', '''\
|
||||
interface I<S> {
|
||||
def <T> void foo(List<T> a);
|
||||
}
|
||||
|
||||
class Foo {
|
||||
@Delegate private I list
|
||||
}
|
||||
|
||||
<error descr="Method 'foo' is not implemented">class Bar implements I</error> {
|
||||
def <T> void foo(List<T> a){}
|
||||
}
|
||||
|
||||
class Baz implements I {
|
||||
def void foo(List a){}
|
||||
}
|
||||
''')
|
||||
|
||||
myFixture.testHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
void testPrimitiveTypeParams() {
|
||||
myFixture.configureByText('a.groovy', '''\
|
||||
List<<error descr="Primitive type parameters are not allowed in type parameter list">int</error>> list = new ArrayList<int><EOLError descr="'(' expected"></EOLError>
|
||||
List<? extends <error descr="Primitive bound types are not allowed">double</error>> l = new ArrayList<double>()
|
||||
List<?> list2
|
||||
''')
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
public void testAliasInParameterType() {
|
||||
myFixture.configureByText('a_.groovy', '''\
|
||||
import java.awt.event.ActionListener
|
||||
import java.awt.event.ActionEvent as AE
|
||||
|
||||
public class CorrectImplementor implements ActionListener {
|
||||
public void actionPerformed (AE e) { //AE is alias to ActionEvent
|
||||
}
|
||||
}
|
||||
|
||||
<error descr="Method 'actionPerformed' is not implemented">public class IncorrectImplementor implements ActionListener</error> {
|
||||
public void actionPerformed (Object e) {
|
||||
}
|
||||
}
|
||||
''')
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
public void testReassignedHighlighting() {
|
||||
myFixture.testHighlighting(true, true, true, getTestName(false) + ".groovy");
|
||||
}
|
||||
|
||||
public void testInstanceOf() {
|
||||
myFixture.configureByText('_a.groovy', '''\
|
||||
class DslPointcut {}
|
||||
|
||||
private def handleImplicitBind(arg) {
|
||||
if (arg instanceof Map && arg.size() == 1 && arg.keySet().iterator().next() instanceof String && arg.values().iterator().next() instanceof DslPointcut) {
|
||||
return DslPointcut.bind(arg)
|
||||
}
|
||||
return arg
|
||||
}''')
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
public void testIncorrectTypeArguments(){
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
class C <T extends String> {}
|
||||
C<<error descr="Type parameter 'java.lang.Double' is not in its bound; should extend 'java.lang.String'">Double</error>> c
|
||||
C<String> c2
|
||||
C<error descr="Wrong number of type arguments: 2; required: 1"><String, Double></error> c3
|
||||
''')
|
||||
myFixture.testHighlighting(true, false, true)
|
||||
}
|
||||
|
||||
void testTryCatch1() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (Exception e){}
|
||||
catch (<warning descr="Exception 'java.io.IOException' has already been caught">IOException</warning> e){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTryCatch2() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (e){}
|
||||
catch (<warning descr="Exception 'java.lang.Throwable' has already been caught">e</warning>){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTryCatch3() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (e){}
|
||||
catch (<warning descr="Exception 'java.io.IOException' has already been caught">IOException</warning> e){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTryCatch4() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (Exception | <warning descr="Unnecessary exception 'java.io.IOException'. 'java.lang.Exception' is already declared">IOException</warning> e){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTryCatch5() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (RuntimeException | IOException e){}
|
||||
catch (<warning descr="Exception 'java.lang.NullPointerException' has already been caught">NullPointerException</warning> e){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTryCatch6() {
|
||||
testHighlighting('''\
|
||||
try {}
|
||||
catch (NullPointerException | IOException e){}
|
||||
catch (ClassNotFoundException | <warning descr="Exception 'java.lang.NullPointerException' has already been caught">NullPointerException</warning> e){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testCompileStatic() {
|
||||
myFixture.addClass('''\
|
||||
package groovy.transform;
|
||||
public @interface CompileStatic {
|
||||
}''')
|
||||
|
||||
testHighlighting('''\
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
class A {
|
||||
|
||||
def foo() {
|
||||
print <warning descr="Cannot resolve symbol 'abc'">abc</warning>
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
def bar() {
|
||||
print <error descr="Cannot resolve symbol 'abc'">abc</error>
|
||||
}
|
||||
}
|
||||
''', true, false, false, GrUnresolvedAccessInspection)
|
||||
}
|
||||
|
||||
void testUnresolvedVarInStaticMethod() {
|
||||
testHighlighting('''\
|
||||
static def foo() {
|
||||
print <error descr="Cannot resolve symbol 'abc'">abc</error>
|
||||
|
||||
def cl = {
|
||||
print <warning descr="Cannot resolve symbol 'cde'">cde</warning>
|
||||
}
|
||||
}
|
||||
''', GrUnresolvedAccessInspection)
|
||||
}
|
||||
|
||||
void testScriptFieldsAreAllowedOnlyInScriptBody() {
|
||||
addGroovyTransformField()
|
||||
testHighlighting('''\
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field
|
||||
def foo
|
||||
|
||||
def foo() {
|
||||
<error descr="Annotation @Field can only be used within a script body">@Field</error>
|
||||
def bar
|
||||
}
|
||||
|
||||
class X {
|
||||
<error descr="Annotation @Field can only be used within a script">@Field</error>
|
||||
def bar
|
||||
|
||||
def b() {
|
||||
<error descr="Annotation @Field can only be used within a script">@Field</error>
|
||||
def x
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testDuplicatedScriptField() {
|
||||
addGroovyTransformField()
|
||||
testHighlighting('''\
|
||||
import groovy.transform.Field
|
||||
|
||||
while(true) {
|
||||
@Field def <error descr="Field 'foo' already defined">foo</error>
|
||||
}
|
||||
|
||||
while(false) {
|
||||
@Field def <error descr="Field 'foo' already defined">foo</error>
|
||||
}
|
||||
|
||||
while(i) {
|
||||
def foo
|
||||
}
|
||||
|
||||
def foo
|
||||
''')
|
||||
}
|
||||
|
||||
void testReturnTypeInStaticallyCompiledMethod() {
|
||||
addCompileStatic();
|
||||
testHighlighting('''\
|
||||
import groovy.transform.CompileStatic
|
||||
@CompileStatic
|
||||
int method(x, y, z) {
|
||||
if (x) {
|
||||
<error descr="Cannot assign 'String' to 'int'">'String'</error>
|
||||
} else if (y) {
|
||||
42
|
||||
}
|
||||
else if (z) {
|
||||
return <error descr="Cannot assign 'String' to 'int'">'abc'</error>
|
||||
}
|
||||
else {
|
||||
return 43
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testReassignedVarInClosure() {
|
||||
addCompileStatic()
|
||||
testHighlighting("""
|
||||
$IMPORT_COMPILE_STATIC
|
||||
|
||||
@CompileStatic
|
||||
test() {
|
||||
def var = "abc"
|
||||
def cl = {
|
||||
var = new Date()
|
||||
}
|
||||
cl()
|
||||
var.<error descr="Cannot resolve symbol 'toUpperCase'">toUpperCase</error>()
|
||||
}
|
||||
""", GrUnresolvedAccessInspection)
|
||||
}
|
||||
|
||||
void testOverrideForVars() {
|
||||
testHighlighting('''\
|
||||
class S {
|
||||
@<error descr="'@Override' not applicable to field">Override</error> def foo;
|
||||
|
||||
def bar() {
|
||||
@<error descr="'@Override' not applicable to local variable">Override</error> def x
|
||||
}
|
||||
}''')
|
||||
}
|
||||
|
||||
void testUnusedImportToList() {
|
||||
myFixture.addClass('''package java.awt; public class Component{}''')
|
||||
testHighlighting('''\
|
||||
import java.awt.Component
|
||||
<warning descr="Unused import">import java.util.List</warning>
|
||||
|
||||
print Component
|
||||
print List
|
||||
''')
|
||||
}
|
||||
|
||||
void testUsedImportToList() {
|
||||
myFixture.addClass('''package java.awt; public class Component{}''')
|
||||
myFixture.addClass('''package java.awt; public class List{}''')
|
||||
myFixture.addClass('''package java.util.concurrent; public class ConcurrentHashMap{}''')
|
||||
testHighlighting('''\
|
||||
import java.awt.*
|
||||
import java.util.List
|
||||
<warning descr="Unused import">import java.util.concurrent.ConcurrentHashMap</warning>
|
||||
|
||||
print Component
|
||||
print List
|
||||
''')
|
||||
}
|
||||
|
||||
void testIncompatibleTypeOfImplicitGetter() {
|
||||
testHighlighting('''\
|
||||
abstract class Base {
|
||||
abstract String getFoo()
|
||||
}
|
||||
|
||||
class Inheritor extends Base {
|
||||
final <error descr="The return type of java.lang.Object getFoo() in Inheritor is incompatible with java.lang.String getFoo() in Base">foo</error> = '3'
|
||||
}''')
|
||||
}
|
||||
|
||||
void testIncompatibleTypeOfInheritedMethod() {
|
||||
testHighlighting('''\
|
||||
abstract class Base {
|
||||
abstract String getFoo()
|
||||
}
|
||||
|
||||
class Inheritor extends Base {
|
||||
def <error descr="The return type of java.lang.Object getFoo() in Inheritor is incompatible with java.lang.String getFoo() in Base">getFoo</error>() {''}
|
||||
}''')
|
||||
}
|
||||
|
||||
void testIncompatibleTypeOfInheritedMethod2() {
|
||||
testHighlighting('''\
|
||||
abstract class Base {
|
||||
abstract String getFoo()
|
||||
}
|
||||
|
||||
class Inheritor extends Base {
|
||||
<error descr="The return type of java.lang.Object getFoo() in Inheritor is incompatible with java.lang.String getFoo() in Base">Object</error> getFoo() {''}
|
||||
}''')
|
||||
}
|
||||
|
||||
void testIncompatibleTypeOfInheritedMethodInAnonymous() {
|
||||
testHighlighting('''\
|
||||
abstract class Base {
|
||||
abstract String getFoo()
|
||||
}
|
||||
|
||||
new Base() {
|
||||
<error descr="The return type of java.lang.Object getFoo() in anonymous class derived from Base is incompatible with java.lang.String getFoo() in Base">Object</error> getFoo() {''}
|
||||
}''')
|
||||
}
|
||||
|
||||
void testAnnotationArgs() {
|
||||
testHighlighting('''\
|
||||
@interface Int {
|
||||
int value()
|
||||
String s() default 'a'
|
||||
}
|
||||
|
||||
@Int(<error descr="Cannot assign 'String' to 'int'">'a'</error>) def foo(){}
|
||||
|
||||
@Int(2) def bar(){}
|
||||
|
||||
@Int(value = 2) def c(){}
|
||||
|
||||
@Int(value = 3, s = <error descr="Cannot assign 'Integer' to 'String'">4</error>) def x(){}
|
||||
|
||||
@Int(value = 3, s = '4') def y(){}
|
||||
''')
|
||||
}
|
||||
|
||||
void testDefaultAttributeValue() {
|
||||
testHighlighting('''\
|
||||
@interface Int {
|
||||
int value1() default 2
|
||||
String value2() default <error descr="Cannot assign 'Integer' to 'String'">2</error>
|
||||
String value3()
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testAnnotationAttributeTypes() {
|
||||
testHighlighting('''\
|
||||
@interface Int {
|
||||
int a()
|
||||
String b()
|
||||
<error descr="Unexpected attribute type: 'PsiType:Date'">Date</error> c()
|
||||
Int d()
|
||||
int[] e()
|
||||
String[] f()
|
||||
boolean[][] g()
|
||||
<error descr="Unexpected attribute type: 'PsiType:Boolean'">Boolean</error>[] h()
|
||||
Int[][][][] i()
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testDefaultAnnotationValue() {
|
||||
testHighlighting('''\
|
||||
@interface A {
|
||||
int a() default 2
|
||||
String b() default <error descr="Cannot assign 'ArrayList<String>' to 'String'">['a']</error>
|
||||
String[][] c() default <error descr="Cannot assign 'String' to 'String[][]'">'f'</error>
|
||||
String[][] d() default [['f']]
|
||||
String[][] e() default [[<error descr="Cannot assign 'ArrayList<String>' to 'String'">['f']</error>]]
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testDelegateWithDeprecated() {
|
||||
testHighlighting('''\
|
||||
interface Foo {
|
||||
@Deprecated
|
||||
void foo()
|
||||
}
|
||||
|
||||
|
||||
<error descr="Method 'foo' is not implemented">class FooImpl implements Foo</error> {
|
||||
@Delegate(deprecated = false) Foo delegate
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testAbstractMethodWithBody() {
|
||||
testHighlighting('''\
|
||||
interface A {
|
||||
def foo()<error descr="Abstract methods must not have body">{}</error>
|
||||
}
|
||||
|
||||
abstract class B {
|
||||
abstract foo()<error descr="Abstract methods must not have body">{}</error>
|
||||
}
|
||||
|
||||
class X {
|
||||
def foo(){}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testTupleVariableDeclarationWithRecursion() {
|
||||
testHighlighting('''def (a, b) = [a, a]''')
|
||||
}
|
||||
|
||||
public void testSwitchInLoopNoSoe() {
|
||||
testHighlighting('''
|
||||
def foo(File f) {
|
||||
while (true) {
|
||||
switch (f.name) {
|
||||
case 'foo': f = new File('bar')
|
||||
}
|
||||
if (f) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}''')
|
||||
|
||||
}
|
||||
|
||||
void testInstanceMethodUsedInStaticClosure() {
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
static staticClosure = {
|
||||
foo()
|
||||
}
|
||||
|
||||
def staticMethod() {
|
||||
foo()
|
||||
}
|
||||
|
||||
def foo() { }
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testStaticOk() {
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
class B {}
|
||||
}
|
||||
|
||||
A.B foo = new <error descr="Cannot reference nonstatic symbol 'A.B' from static context">A.B</error>()
|
||||
''')
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
class A {
|
||||
def r() {
|
||||
def a = 0;
|
||||
{->
|
||||
a.intValue()
|
||||
}.call()
|
||||
}
|
||||
class <warning descr="Class A is unused">A</warning> {
|
||||
def <warning descr="Method r is unused">r</warning>() {
|
||||
def a = 0;
|
||||
{->
|
||||
a.intValue()
|
||||
}.call()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
def deleteOtherColumns(table, columns) {
|
||||
def newTable = []
|
||||
table.each {
|
||||
def index = 0;
|
||||
newTable << it.findAll {columns.contains(index++)}
|
||||
}
|
||||
return newTable
|
||||
}
|
||||
class <warning descr="Class A is unused">A</warning> {
|
||||
def <warning descr="Method r is unused">r</warning>() {
|
||||
def a = 0;
|
||||
{->
|
||||
a.intValue()
|
||||
}.call()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +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.
|
||||
*/
|
||||
def testV(def variable) {
|
||||
def <warning descr="Method testV is unused">testV</warning>(def variable) {
|
||||
def v = "s"
|
||||
def m="10"
|
||||
def <warning descr="Assignment is not used">x</warning>="10"
|
||||
@@ -24,7 +9,7 @@ def testV(def variable) {
|
||||
break
|
||||
case 2:
|
||||
break
|
||||
default:
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong")
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
<warning descr="Assignment is not used">args</warning> = []
|
||||
<warning descr="Result of assignment expression used"><warning descr="Assignment is not used">args</warning> = []</warning>
|
||||
+1
-1
@@ -4,4 +4,4 @@ print (a<warning descr="Unused ++">++</warning>)
|
||||
|
||||
def b = 3
|
||||
b<warning descr="Unused ++">++</warning>
|
||||
<warning descr="Assignment is not used">b</warning> = 3
|
||||
<warning descr="Result of assignment expression used"><warning descr="Assignment is not used">b</warning> = 3</warning>
|
||||
@@ -1,4 +1,4 @@
|
||||
def foo() {
|
||||
def <warning descr="Method foo is unused">foo</warning>() {
|
||||
String foo = 'used';
|
||||
try {
|
||||
thrower()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
def foo() {
|
||||
def <warning descr="Method foo is unused">foo</warning>() {
|
||||
String foo = 'used';
|
||||
try {
|
||||
thrower()
|
||||
|
||||
Reference in New Issue
Block a user