2 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
3 * Use is subject to license terms.
5 package org
.jetbrains
.plugins
.groovy
.lang
;
7 import com
.intellij
.codeInspection
.LocalInspectionTool
;
8 import com
.intellij
.openapi
.module
.Module
;
9 import com
.intellij
.openapi
.roots
.ContentEntry
;
10 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
11 import com
.intellij
.openapi
.roots
.OrderRootType
;
12 import com
.intellij
.openapi
.roots
.libraries
.Library
;
13 import com
.intellij
.openapi
.vfs
.JarFileSystem
;
14 import com
.intellij
.openapi
.vfs
.VirtualFile
;
15 import com
.intellij
.testFramework
.LightProjectDescriptor
;
16 import com
.intellij
.testFramework
.fixtures
.DefaultLightProjectDescriptor
;
17 import com
.intellij
.testFramework
.fixtures
.LightCodeInsightFixtureTestCase
;
18 import org
.jetbrains
.annotations
.NotNull
;
19 import org
.jetbrains
.plugins
.groovy
.codeInspection
.assignment
.GroovyAssignabilityCheckInspection
;
20 import org
.jetbrains
.plugins
.groovy
.codeInspection
.assignment
.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection
;
21 import org
.jetbrains
.plugins
.groovy
.codeInspection
.control
.GroovyTrivialConditionalInspection
;
22 import org
.jetbrains
.plugins
.groovy
.codeInspection
.control
.GroovyTrivialIfInspection
;
23 import org
.jetbrains
.plugins
.groovy
.codeInspection
.metrics
.GroovyOverlyLongMethodInspection
;
24 import org
.jetbrains
.plugins
.groovy
.codeInspection
.noReturnMethod
.MissingReturnInspection
;
25 import org
.jetbrains
.plugins
.groovy
.codeInspection
.unassignedVariable
.UnassignedVariableAccessInspection
;
26 import org
.jetbrains
.plugins
.groovy
.codeInspection
.untypedUnresolvedAccess
.GroovyUnresolvedAccessInspection
;
27 import org
.jetbrains
.plugins
.groovy
.codeInspection
.untypedUnresolvedAccess
.GroovyUntypedAccessInspection
;
28 import org
.jetbrains
.plugins
.groovy
.codeInspection
.unusedDef
.UnusedDefInspection
;
29 import org
.jetbrains
.plugins
.groovy
.util
.TestUtils
;
31 import java
.io
.IOException
;
36 public class GroovyHighlightingTest
extends LightCodeInsightFixtureTestCase
{
38 protected String
getBasePath() {
39 return TestUtils
.getTestDataPath() + "highlighting/";
44 protected LightProjectDescriptor
getProjectDescriptor() {
45 return new DefaultLightProjectDescriptor() {
47 public void configureModule(Module module
, ModifiableRootModel model
, ContentEntry contentEntry
) {
48 final Library
.ModifiableModel modifiableModel
= model
.getModuleLibraryTable().createLibrary("GROOVY").getModifiableModel();
49 final VirtualFile groovyJar
=
50 JarFileSystem
.getInstance().refreshAndFindFileByPath(TestUtils
.getMockGroovy1_7LibraryName()+"!/");
51 modifiableModel
.addRoot(groovyJar
, OrderRootType
.CLASSES
);
52 modifiableModel
.commit();
57 public void testDuplicateClosurePrivateVariable() throws Throwable
{
61 public void testClosureRedefiningVariable() throws Throwable
{
65 private void doTest(LocalInspectionTool
... tools
) throws Exception
{
66 myFixture
.enableInspections(tools
);
67 myFixture
.testHighlighting(true, false, false, getTestName(false) + ".groovy");
70 public void testCircularInheritance() throws Throwable
{
74 public void testEmptyTupleType() throws Throwable
{
78 public void testMapDeclaration() throws Throwable
{
82 public void testShouldntImplementGroovyObjectMethods() throws Throwable
{
84 myFixture
.addFileToProject("Foo.groovy", "class Foo {}");
85 myFixture
.testHighlighting(false, false, false, getTestName(false) + ".java");
88 public void testJavaClassImplementingGroovyInterface() throws Throwable
{
90 myFixture
.addFileToProject("Foo.groovy", "interface Foo {}");
91 myFixture
.testHighlighting(false, false, false, getTestName(false) + ".java");
94 private void addGroovyObject() throws IOException
{
95 myFixture
.addClass("package groovy.lang;" +
96 "public interface GroovyObject {\n" +
97 " java.lang.Object invokeMethod(java.lang.String s, java.lang.Object o);\n" +
98 " java.lang.Object getProperty(java.lang.String s);\n" +
99 " void setProperty(java.lang.String s, java.lang.Object o);\n" +
100 " groovy.lang.MetaClass getMetaClass();\n" +
101 " void setMetaClass(groovy.lang.MetaClass metaClass);\n" +
105 public void testDuplicateFields() throws Throwable
{
109 public void testNoDuplicationThroughClosureBorder() throws Throwable
{
110 myFixture
.addClass("package groovy.lang; public interface Closure {}");
114 public void testRecursiveMethodTypeInference() throws Throwable
{
118 public void testDontSimplifyString() throws Throwable
{ doTest(new GroovyTrivialIfInspection(), new GroovyTrivialConditionalInspection()); }
120 public void testRawMethodAccess() throws Throwable
{ doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
122 public void testRawFieldAccess() throws Throwable
{ doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
124 public void testRawArrayStyleAccess() throws Throwable
{ doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
126 public void testRawArrayStyleAccessToMap() throws Throwable
{ doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
128 public void testRawArrayStyleAccessToList() throws Throwable
{ doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
130 public void testIncompatibleTypesAssignments() throws Throwable
{ doTest(new GroovyAssignabilityCheckInspection()); }
132 public void testAnonymousClassConstructor() throws Throwable
{doTest();}
133 public void testAnonymousClassAbstractMethod() throws Throwable
{doTest();}
134 public void testAnonymousClassStaticMethod() throws Throwable
{doTest();}
135 public void testAnonymousClassShoudImplementMethods() throws Throwable
{doTest();}
138 public void testDefaultMapConstructorNamedArgs() throws Throwable
{doTest();}
139 public void testDefaultMapConstructorNamedArgsError() throws Throwable
{doTest();}
140 public void testDefaultMapConstructorWhenDefConstructorExists() throws Throwable
{doTest();}
142 public void testUnresolvedLhsAssignment() throws Throwable
{ doTest(new GroovyUnresolvedAccessInspection()); }
144 public void testMissingReturnWithLastLoop() throws Throwable
{ doTest(new MissingReturnInspection()); }
145 public void testMissingReturnWithUnknownCall() throws Throwable
{ doTest(new MissingReturnInspection()); }
146 public void testMissingReturnWithIf() throws Throwable
{ doTest(new MissingReturnInspection()); }
147 public void testMissingReturnWithAssertion() throws Throwable
{ doTest(new MissingReturnInspection()); }
148 public void testMissingReturnThrowException() throws Throwable
{ doTest(new MissingReturnInspection()); }
149 public void testMissingReturnTryCatch() throws Throwable
{ doTest(new MissingReturnInspection()); }
150 public void testMissingReturnLastNull() throws Throwable
{ doTest(new MissingReturnInspection()); }
151 public void testMissingReturnImplicitReturns() throws Throwable
{doTest(new MissingReturnInspection());}
153 public void testUnresolvedMethodCallWithTwoDeclarations() throws Throwable
{
157 public void testUnresolvedAccess() throws Exception
{ doTest(new GroovyUnresolvedAccessInspection()); }
158 public void testUntypedAccess() throws Exception
{ doTest(new GroovyUntypedAccessInspection()); }
160 public void testUnassigned1() throws Exception
{ doTest(new UnassignedVariableAccessInspection()); }
161 public void testUnassigned2() throws Exception
{ doTest(new UnassignedVariableAccessInspection()); }
162 public void testUnassigned3() throws Exception
{ doTest(new UnassignedVariableAccessInspection()); }
163 public void testUnassignedTryFinally() throws Exception
{ doTest(new UnassignedVariableAccessInspection()); }
165 public void testUnusedVariable() throws Exception
{ doTest(new UnusedDefInspection()); }
166 public void testDefinitionUsedInClosure() throws Exception
{ doTest(new UnusedDefInspection()); }
167 public void testDefinitionUsedInClosure2() throws Exception
{ doTest(new UnusedDefInspection()); }
168 public void testDuplicateInnerClass() throws Throwable
{doTest();}
170 public void testThisInStaticContext() throws Throwable
{doTest();}
171 public void testSuperWithNotEnclosingClass() throws Throwable
{doTest();}
172 public void testThisWithWrongQualifier() throws Throwable
{doTest();}
174 public void testModifiersInPackageAndImportStatements() throws Throwable
{
175 myFixture
.copyFileToProject(getTestName(false) + ".groovy", "x/"+getTestName(false)+".groovy");
176 myFixture
.testHighlighting(true, false, false, "x/"+getTestName(false)+".groovy");
179 public void testBreakOutside() throws Exception
{doTest();}
180 public void testUndefinedLabel() throws Exception
{doTest();}
181 public void testUsedLabel() throws Exception
{doTest();}
183 public void testNestedMethods() throws Throwable
{
187 public void testRawOverridedMethod() throws Exception
{doTest();}
189 public void testFQNJavaClassesUsages() throws Exception
{
193 public void testGstringAssignableToString() throws Exception
{doTest();}
194 public void testGstringAssignableToStringInClosureParameter() throws Exception
{doTest();}
195 public void testEverythingAssignableToString() throws Exception
{doTest(new GroovyAssignabilityCheckInspection());}
197 public void testMethodCallWithDefaultParameters() throws Exception
{doTest();}
199 public void testOverlyLongMethodInspection() throws Exception
{
200 doTest(new GroovyOverlyLongMethodInspection());