mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-121423 Groovy: don't add type arguments to text for reference generating since it can contain lexical errors. Add type arguments to generated reference instead.
This commit is contained in:
+4
-3
@@ -484,10 +484,11 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
@Override
|
||||
protected GrReferenceExpression bindWithQualifiedRef(@NotNull String qName) {
|
||||
GrReferenceExpression qualifiedRef = GroovyPsiElementFactory.getInstance(getProject()).createReferenceExpressionFromText(qName);
|
||||
final GrTypeArgumentList list = getTypeArgumentList();
|
||||
final String typeArgs = (list != null) ? list.getText() : "";
|
||||
final String text = qName + typeArgs;
|
||||
GrReferenceExpression qualifiedRef = GroovyPsiElementFactory.getInstance(getProject()).createReferenceExpressionFromText(text);
|
||||
if (list != null) {
|
||||
qualifiedRef.getNode().addChild(list.copy().getNode());
|
||||
}
|
||||
getNode().getTreeParent().replaceChild(getNode(), qualifiedRef.getNode());
|
||||
return qualifiedRef;
|
||||
}
|
||||
|
||||
+5
-4
@@ -91,10 +91,11 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
|
||||
@Override
|
||||
protected GrCodeReferenceElement bindWithQualifiedRef(@NotNull String qName) {
|
||||
final GrTypeArgumentList list = getTypeArgumentList();
|
||||
final String typeArgs = (list != null) ? list.getText() : "";
|
||||
final String text = qName + typeArgs;
|
||||
final GrCodeReferenceElement qualifiedRef = GroovyPsiElementFactory.getInstance(getProject()).createTypeOrPackageReference(text);
|
||||
final GrCodeReferenceElement qualifiedRef = GroovyPsiElementFactory.getInstance(getProject()).createTypeOrPackageReference(qName);
|
||||
final PsiElement list = getTypeArgumentList();
|
||||
if (list != null) {
|
||||
qualifiedRef.getNode().addChild(list.copy().getNode());
|
||||
}
|
||||
getNode().getTreeParent().replaceChild(getNode(), qualifiedRef.getNode());
|
||||
return qualifiedRef;
|
||||
}
|
||||
|
||||
+24
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
|
||||
package org.jetbrains.plugins.groovy.refactoring.optimizeImports
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -27,20 +25,34 @@ public class GroovyAddImportActionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.addClass 'package foo; public class Log {}'
|
||||
myFixture.addClass 'package bar; public class Log {}'
|
||||
myFixture.addClass 'package bar; public class LogFactory { public static Log log(){} }'
|
||||
myFixture.configureByText 'a.groovy', '''
|
||||
doTest('''\
|
||||
public class Foo {
|
||||
Lo<caret>g l = bar.LogFactory.log();
|
||||
}
|
||||
'''
|
||||
myFixture.enableInspections(new GrUnresolvedAccessInspection())
|
||||
''', '''\
|
||||
import bar.Log
|
||||
|
||||
public class Foo {
|
||||
Lo<caret>g l = bar.LogFactory.log();
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testReferenceWithErrors() {
|
||||
myFixture.addClass 'package foo; public class Abc<X, Y> {}'
|
||||
doTest('''\
|
||||
A<caret>bc<String, > foo = null
|
||||
''', '''\
|
||||
import foo.Abc
|
||||
|
||||
A<caret>bc<String, > foo = null
|
||||
''')
|
||||
}
|
||||
|
||||
private void doTest(String before, String after) {
|
||||
myFixture.configureByText 'a.groovy', before
|
||||
importClass()
|
||||
myFixture.checkResult '''import bar.Log
|
||||
|
||||
public class Foo {
|
||||
Lo<caret>g l = bar.LogFactory.log();
|
||||
}
|
||||
'''
|
||||
myFixture.checkResult after
|
||||
}
|
||||
|
||||
private def importClass() {
|
||||
|
||||
Reference in New Issue
Block a user