mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GrEnumConstant extends PsiEnumConstant
This commit is contained in:
+1
@@ -227,6 +227,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
final PsiMethod caller = RefactoringUtil.getEnclosingMethod(ref);
|
||||
if (toChangeArguments) {
|
||||
final PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(ref);
|
||||
LOG.assertTrue(list != null);
|
||||
boolean toInsertDefaultValue = needDefaultValue(changeInfo, caller);
|
||||
if (toInsertDefaultValue && ref instanceof PsiReferenceExpression) {
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)ref).getQualifierExpression();
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ class JavaChangeSignatureUsageSearcher {
|
||||
if (!isToCatchExceptions) {
|
||||
if (RefactoringUtil.isMethodUsage(element)) {
|
||||
PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(element);
|
||||
if (!method.isVarArgs() && list.getExpressions().length != parameterCount) continue;
|
||||
if (list == null || !method.isVarArgs() && list.getExpressions().length != parameterCount) continue;
|
||||
}
|
||||
}
|
||||
if (RefactoringUtil.isMethodUsage(element)) {
|
||||
|
||||
+4
@@ -46,6 +46,7 @@ import com.intellij.refactoring.util.RefactoringMessageUtil;
|
||||
import com.intellij.ui.RecentsManager;
|
||||
import com.intellij.ui.ReferenceEditorComboWithBrowseButton;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -396,6 +397,9 @@ class IntroduceConstantDialog extends DialogWrapper {
|
||||
errorString = RefactoringBundle.message("no.field.name.specified");
|
||||
} else if (!JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(fieldName)) {
|
||||
errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
|
||||
} else if (!myParentClass.getLanguage().equals(newClass.getLanguage())) {
|
||||
errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
|
||||
myParentClass.getQualifiedName(), newClass.getQualifiedName());
|
||||
}
|
||||
if (errorString != null) {
|
||||
CommonRefactoringUtil.showErrorMessage(
|
||||
|
||||
+2
-1
@@ -60,6 +60,7 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
final PsiElement ref = usage.getElement();
|
||||
PsiCall callExpression = RefactoringUtil.getCallExpressionByMethodReference(ref);
|
||||
PsiExpressionList argList = RefactoringUtil.getArgumentListByMethodReference(ref);
|
||||
if (argList == null) return true;
|
||||
PsiExpression[] oldArgs = argList.getExpressions();
|
||||
|
||||
final PsiExpression anchor;
|
||||
@@ -261,4 +262,4 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
processChangeMethodUsage(data, new ExternalUsageInfo(((PsiMethodCallExpression)superCall.getExpression()).getMethodExpression()), usages);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -618,7 +619,9 @@ public class RefactoringUtil {
|
||||
}
|
||||
|
||||
public static boolean isMethodUsage(PsiElement element) {
|
||||
if (element instanceof PsiEnumConstant) return true;
|
||||
if (element instanceof PsiEnumConstant) {
|
||||
return StdLanguages.JAVA.equals(element.getLanguage());
|
||||
}
|
||||
if (!(element instanceof PsiJavaCodeReferenceElement)) return false;
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiCall) {
|
||||
@@ -630,6 +633,7 @@ public class RefactoringUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiExpressionList getArgumentListByMethodReference(PsiElement ref) {
|
||||
if (ref instanceof PsiEnumConstant) return ((PsiEnumConstant)ref).getArgumentList();
|
||||
PsiElement parent = ref.getParent();
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,7 +29,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.util.GrNamedArgumentsOwner;
|
||||
* @author ilyas
|
||||
* Plain Argumanet list with parentheses. Cannot contain closure arguments, they are placed outside.
|
||||
*/
|
||||
public interface GrArgumentList extends GroovyPsiElement, GrNamedArgumentsOwner {
|
||||
public interface GrArgumentList extends GroovyPsiElement, GrNamedArgumentsOwner, PsiExpressionList {
|
||||
@NotNull GrExpression[] getExpressionArguments();
|
||||
|
||||
@NotNull PsiElement[] getAllArguments();
|
||||
@@ -49,4 +50,4 @@ public interface GrArgumentList extends GroovyPsiElement, GrNamedArgumentsOwner
|
||||
GrExpression removeArgument(int argNumber);
|
||||
|
||||
GrNamedArgument addNamedArgument(GrNamedArgument namedArgument);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -16,22 +16,23 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members;
|
||||
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConstructorCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConstructorCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
|
||||
|
||||
/**
|
||||
* @author: Dmitry.Krasilschikov
|
||||
* @date: 06.04.2007
|
||||
*/
|
||||
public interface GrEnumConstant extends GrField, GrConstructorCall {
|
||||
public interface GrEnumConstant extends GrField, GrConstructorCall, PsiEnumConstant {
|
||||
GrEnumConstant[] EMPTY_ARRAY = new GrEnumConstant[0];
|
||||
|
||||
@Nullable
|
||||
GrTypeDefinitionBody getAnonymousBlock();
|
||||
|
||||
@Override
|
||||
GrArgumentList getArgumentList();
|
||||
}
|
||||
|
||||
+14
@@ -18,6 +18,8 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.arguments;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -222,4 +224,16 @@ public class GrArgumentListImpl extends GroovyPsiElementImpl implements GrArgume
|
||||
}
|
||||
super.deleteChildInternal(child);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiExpression[] getExpressions() {
|
||||
return PsiExpression.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType[] getExpressionTypes() {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
+27
-1
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -110,6 +111,7 @@ public class GrEnumConstantImpl extends GrFieldImpl implements GrEnumConstant, P
|
||||
private GroovyResolveResult[] multiResolveConstructorImpl(boolean allVariants) {
|
||||
PsiType[] argTypes = PsiUtil.getArgumentTypes(getFirstChild(), false);
|
||||
PsiClass clazz = getContainingClass();
|
||||
assert clazz != null;
|
||||
PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType(clazz, PsiSubstitutor.EMPTY);
|
||||
MethodResolverProcessor processor =
|
||||
new MethodResolverProcessor(clazz.getName(), this, true, thisType, argTypes, PsiType.EMPTY_ARRAY, allVariants);
|
||||
@@ -128,13 +130,25 @@ public class GrEnumConstantImpl extends GrFieldImpl implements GrEnumConstant, P
|
||||
return findChildByClass(GrArgumentList.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiEnumConstantInitializer getInitializingClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public GrExpression removeArgument(final int number) {
|
||||
final GrArgumentList list = getArgumentList();
|
||||
return list != null ? list.removeArgument(number) : null;
|
||||
}
|
||||
|
||||
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) throws IncorrectOperationException {
|
||||
return null;
|
||||
GrArgumentList list = getArgumentList();
|
||||
assert list != null;
|
||||
if (list.getText().trim().length() == 0) {
|
||||
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
|
||||
final GrArgumentList newList = factory.createArgumentList();
|
||||
list = (GrArgumentList)list.replace(newList);
|
||||
}
|
||||
return list.addNamedArgument(namedArgument);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,6 +181,13 @@ public class GrEnumConstantImpl extends GrFieldImpl implements GrEnumConstant, P
|
||||
return PsiImplUtil.extractUniqueElement(multiResolveConstructor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult resolveMethodGenerics() {
|
||||
return JavaResolveResult.EMPTY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public GrTypeDefinitionBody getAnonymousBlock() {
|
||||
return findChildByClass(GrTypeDefinitionBody.class);
|
||||
}
|
||||
@@ -224,4 +245,9 @@ public class GrEnumConstantImpl extends GrFieldImpl implements GrEnumConstant, P
|
||||
public boolean isSoft() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiMethod resolveConstructor() {
|
||||
return resolveMethod();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ public class PsiUtil {
|
||||
|
||||
@Nullable
|
||||
public static GrArgumentList getArgumentsList(PsiElement methodRef) {
|
||||
if (methodRef instanceof GrEnumConstant) return ((GrEnumConstant)methodRef).getArgumentList();
|
||||
PsiElement parent = methodRef.getParent();
|
||||
if (parent instanceof GrCall) {
|
||||
return ((GrCall)parent).getArgumentList();
|
||||
|
||||
@@ -309,12 +309,17 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testWrongAnnotation() {doTest();}
|
||||
|
||||
public void testAmbiguousMethods() {
|
||||
myFixture.copyFileToProject(getTestName(false)+".java");
|
||||
myFixture.copyFileToProject(getTestName(false) + ".java");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMapParamWithNoArgs() {doTest(new GroovyAssignabilityCheckInspection());}
|
||||
|
||||
public void testGroovyEnumInJavaFile() {
|
||||
myFixture.copyFileToProject(getTestName(false)+".groovy");
|
||||
myFixture.testHighlighting(true, false, false, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testRangeType() {
|
||||
doTest(new GroovyRangeTypeCheckInspection());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
enum MyEnum {
|
||||
E1, E2, E3
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class MyJavaClass {
|
||||
public static void main(String[] args) {
|
||||
for (MyEnum e : MyEnum.values()) {
|
||||
switch (e) {
|
||||
case E1:
|
||||
System.out.println("E1");
|
||||
break;
|
||||
case <error descr="Cannot resolve symbol 'E4'">E4</error>:
|
||||
System.out.println("fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user