diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java index ea8362ec6f04..b4c3bcf20071 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java @@ -108,11 +108,13 @@ public class GroovyToJavaGenerator { private static final CharSequence PREFIX_SEPARATOR = "/"; private final CompileContext myContext; + private final List myAllToCompile; private final Project myProject; - public GroovyToJavaGenerator(Project project, CompileContext context) { + public GroovyToJavaGenerator(Project project, CompileContext context, List allToCompile) { myProject = project; myContext = context; + myAllToCompile = allToCompile; } public GenerationItem[] getGenerationItems(CompileContext context) { @@ -421,7 +423,7 @@ public class GroovyToJavaGenerator { text.append("}"); } - private static void writeAllMethods(StringBuffer text, List methods, PsiClass aClass) { + private void writeAllMethods(StringBuffer text, List methods, PsiClass aClass) { Set methodSignatures = new HashSet(); for (PsiMethod method : methods) { if (LightMethodBuilder.isLightMethod(method, GrClassImplUtil.SYNTHETIC_METHOD_IMPLEMENTATION)) { @@ -509,7 +511,7 @@ public class GroovyToJavaGenerator { return psiClass != null && GrClassSubstitutor.getSubstitutedClass(psiClass).isInterface(); } - private static void appendTypeParameters(StringBuffer text, PsiTypeParameterListOwner typeParameterListOwner) { + private void appendTypeParameters(StringBuffer text, PsiTypeParameterListOwner typeParameterListOwner) { if (typeParameterListOwner.hasTypeParameters()) { text.append("<"); PsiTypeParameter[] parameters = typeParameterListOwner.getTypeParameters(); @@ -530,7 +532,7 @@ public class GroovyToJavaGenerator { } } - private static void writeEnumConstants(StringBuffer text, GrEnumTypeDefinition enumDefinition) { + private void writeEnumConstants(StringBuffer text, GrEnumTypeDefinition enumDefinition) { text.append("\n "); GrEnumConstant[] enumConstants = enumDefinition.getEnumConstants(); for (int i = 0; i < enumConstants.length; i++) { @@ -556,7 +558,7 @@ public class GroovyToJavaGenerator { text.append(";"); } - private static void writeStubConstructorInvocation(StringBuffer text, PsiMethod constructor, PsiSubstitutor substitutor) { + private void writeStubConstructorInvocation(StringBuffer text, PsiMethod constructor, PsiSubstitutor substitutor) { final PsiParameter[] superParams = constructor.getParameterList().getParameters(); for (int j = 0; j < superParams.length; j++) { if (j > 0) text.append(", "); @@ -575,7 +577,7 @@ public class GroovyToJavaGenerator { } } - private static void writeConstructor(final StringBuffer text, final GrConstructor constructor, boolean isEnum) { + private void writeConstructor(final StringBuffer text, final GrConstructor constructor, boolean isEnum) { text.append("\n"); text.append(" "); if (!isEnum) { @@ -614,7 +616,7 @@ public class GroovyToJavaGenerator { text.append("\n }\n"); } - private static Set collectThrowsTypes(GrConstructor constructor, Set visited) { + private Set collectThrowsTypes(GrConstructor constructor, Set visited) { final GroovyResolveResult resolveResult = resolveChainingConstructor(constructor); if (resolveResult == null) { return Collections.emptySet(); @@ -674,7 +676,7 @@ public class GroovyToJavaGenerator { return result; } - private static void writeVariableDeclarations(StringBuffer text, GrVariableDeclaration variableDeclaration) { + private void writeVariableDeclarations(StringBuffer text, GrVariableDeclaration variableDeclaration) { GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy(); final String type = typeElement == null ? CommonClassNames.JAVA_LANG_OBJECT : getTypeText(typeElement.getType(), typeElement, false); final String initializer = getDefaultValueText(type); @@ -695,7 +697,7 @@ public class GroovyToJavaGenerator { } } - private static void writeMethod(StringBuffer text, PsiMethod method, final PsiParameter[] parameters) { + private void writeMethod(StringBuffer text, PsiMethod method, final PsiParameter[] parameters) { if (method == null) return; String name = method.getName(); if (!JavaPsiFacade.getInstance(method.getProject()).getNameHelper().isIdentifier(name)) @@ -740,7 +742,7 @@ public class GroovyToJavaGenerator { text.append("\n"); } - private static void writeParameterList(StringBuffer text, PsiParameter[] parameters) { + private void writeParameterList(StringBuffer text, PsiParameter[] parameters) { text.append("("); //writes myParameters @@ -806,7 +808,7 @@ public class GroovyToJavaGenerator { } } - private static String getTypeText(@Nullable PsiType type, @Nullable final PsiElement context, boolean allowVarargs) { + private String getTypeText(@Nullable PsiType type, @Nullable final PsiElement context, boolean allowVarargs) { if (type instanceof PsiArrayType) { String componentText = getTypeText(((PsiArrayType)type).getComponentType(), context, false); if (allowVarargs && type instanceof PsiEllipsisType) { @@ -843,7 +845,7 @@ public class GroovyToJavaGenerator { } @Nullable - private static String getClassQualifiedName(PsiClass psiClass, @Nullable PsiElement context) { + private String getClassQualifiedName(PsiClass psiClass, @Nullable PsiElement context) { if (context != null) { psiClass = findAccessibleSuperClass(context, psiClass); } @@ -852,9 +854,11 @@ public class GroovyToJavaGenerator { } if (psiClass instanceof GrTypeDefinition) { - final PsiClass container = psiClass.getContainingClass(); - if (container != null) { - return getClassQualifiedName(container, null) + "$" + psiClass.getName(); + if (!myAllToCompile.contains(psiClass.getContainingFile().getVirtualFile())) { + final PsiClass container = psiClass.getContainingClass(); + if (container != null) { + return getClassQualifiedName(container, null) + "$" + psiClass.getName(); + } } } return psiClass.getQualifiedName(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java index 2571e658fd8e..635e5082657a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java @@ -111,7 +111,7 @@ public class GroovycStubGenerator extends GroovyCompilerBase { if (GroovyCompilerConfiguration.getInstance(myProject).isUseGroovycStubs()) { runGroovycCompiler(compileContext, module, toCompile, true, tempOutput, sink, tests); } else { - final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject, compileContext); + final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject, compileContext, toCompile); for (VirtualFile file : toCompile) { final String outPath = tempOutput.getPath(); final List relPaths = generator.generateItems(file, tempOutput); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java index c89ce67f8bce..5600d29f05ee 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java @@ -16,6 +16,7 @@ import org.jetbrains.plugins.groovy.util.TestUtils; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import java.util.Collections; import java.util.List; /** @@ -131,7 +132,7 @@ public void testArrayType1() throws Throwable { doTest(); } private final String myFileContent; public GroovyToJavaGeneratorTester(String relTestPath, String fileContent, Project project) { - super(project, null); + super(project, null, Collections.emptyList()); myRelTestPath = relTestPath; myFileContent = fileContent; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index f5582f33124b..0ac2c58c78f1 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -372,5 +372,22 @@ class Usage { assertEmpty make() } + public void testDollarGroovyInnerClassUsagesInStubs2() throws Exception { + myFixture.addClass(""" public class JavaClass { } """) + myFixture.addFileToProject("WithInner.groovy", """ +class WithInner { + static class Inner {} +} +""") + + myFixture.addFileToProject("Usage.groovy", """ +class Usage { + def foo(WithInner.Inner i) {} +} +""") + + assertEmpty make() + } + }