mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] get rid of GrMultiSignature and visitors, use GrSignature and List<GrSignature> instead
This commit is contained in:
+2
-3
@@ -20,7 +20,6 @@ import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
@@ -116,8 +115,8 @@ public class GroovyTypeCheckVisitorHelper {
|
||||
if (args == null) return LocalQuickFix.EMPTY_ARRAY;
|
||||
|
||||
final List<Pair<Integer, PsiType>> allErrors = new ArrayList<>();
|
||||
final List<GrClosureSignature> signatures = GrClosureSignatureUtil.generateSimpleSignatures(signature);
|
||||
for (GrClosureSignature closureSignature : signatures) {
|
||||
final List<GrSignature> signatures = GrClosureSignatureUtil.generateSimpleSignatures(Collections.singletonList(signature));
|
||||
for (GrSignature closureSignature : signatures) {
|
||||
final GrClosureSignatureUtil.MapResultWithError map = GrClosureSignatureUtil.mapSimpleSignatureWithErrors(
|
||||
closureSignature, argumentTypes, id, argumentList, 255
|
||||
);
|
||||
|
||||
+7
-2
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
@@ -113,8 +114,12 @@ public class GppClosureParameterTypeProvider extends AbstractClosureParameterEnh
|
||||
@Nullable
|
||||
public static PsiType getSingleMethodParameterType(@Nullable PsiType type, int index, GrClosableBlock closure) {
|
||||
final PsiType[] signature = findSingleAbstractMethodSignature(type);
|
||||
if (signature != null && GrClosureSignatureUtil.isSignatureApplicable(GrClosureSignatureUtil.createSignature(closure), signature, closure)) {
|
||||
return signature.length > index ? signature[index] : PsiType.NULL;
|
||||
if (signature == null) {
|
||||
return null;
|
||||
}
|
||||
final GrSignature closureSignature = GrClosureSignatureUtil.createSignature(closure);
|
||||
if (GrClosureSignatureUtil.isSignatureApplicable(Collections.singletonList(closureSignature), signature, closure)) {
|
||||
return signature.length > index ? signature[index] : PsiType.NULL;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+4
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.gpp;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -30,6 +16,8 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureU
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.GrTypeConverter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil.canAssign;
|
||||
|
||||
/**
|
||||
@@ -73,7 +61,7 @@ public class GppTypeConverter extends GrTypeConverter {
|
||||
}
|
||||
|
||||
public static boolean isClosureOverride(PsiType[] methodParameters, GrClosureType closureType, GroovyPsiElement context) {
|
||||
final GrSignature signature = closureType.getSignature();
|
||||
final List<GrSignature> signature = closureType.getSignatures();
|
||||
if (methodParameters != null && GrClosureSignatureUtil.isSignatureApplicable(signature, methodParameters, context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+4
-18
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.completion.closureParameters;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
@@ -25,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -87,13 +73,13 @@ public class ClosureDescriptor extends LightElement implements PsiElement {
|
||||
final boolean isConstructor = Boolean.TRUE.equals(myMethod.get("constructor"));
|
||||
final MethodSignature signature = MethodSignatureUtil
|
||||
.createMethodSignature(name, types.toArray(PsiType.createArray(types.size())), method.getTypeParameters(), PsiSubstitutor.EMPTY, isConstructor);
|
||||
final GrClosureSignature closureSignature = GrClosureSignatureUtil.createSignature(signature);
|
||||
final GrSignature closureSignature = GrClosureSignatureUtil.createSignature(signature);
|
||||
|
||||
if (method instanceof ClsMethodImpl) method = ((ClsMethodImpl)method).getSourceMirrorMethod();
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
final PsiType[] typeArray =
|
||||
ContainerUtil.map(parameters, parameter -> parameter.getType(), PsiType.createArray(parameters.length));
|
||||
return GrClosureSignatureUtil.isSignatureApplicable(closureSignature, typeArray, place);
|
||||
return GrClosureSignatureUtil.isSignatureApplicable(Collections.singletonList(closureSignature), typeArray, place);
|
||||
}
|
||||
|
||||
private static PsiType convertToPsiType(String type, @NotNull PsiElement place) {
|
||||
|
||||
+3
-18
@@ -1,19 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
@@ -28,7 +13,7 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -260,7 +245,7 @@ public abstract class GroovyPsiElementFactory implements JVMElementFactory {
|
||||
public abstract GrAnnotation createAnnotationFromText(@NotNull @NonNls String annotationText, @Nullable PsiElement context) throws IncorrectOperationException;
|
||||
|
||||
@NotNull
|
||||
public abstract GrMethod createMethodFromSignature(@NotNull String name, @NotNull GrClosureSignature signature);
|
||||
public abstract GrMethod createMethodFromSignature(@NotNull String name, @NotNull GrSignature signature);
|
||||
|
||||
@NotNull
|
||||
public GrMethod createMethodFromText(@NotNull CharSequence methodText) {
|
||||
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.psi.api.signatures;
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public interface GrClosureSignature extends GrSignature {
|
||||
GrClosureSignature[] EMPTY_ARRAY = new GrClosureSignature[0];
|
||||
|
||||
@NotNull PsiSubstitutor getSubstitutor();
|
||||
|
||||
@NotNull
|
||||
GrClosureParameter[] getParameters();
|
||||
|
||||
int getParameterCount();
|
||||
|
||||
boolean isVarargs();
|
||||
|
||||
@Nullable
|
||||
PsiType getReturnType();
|
||||
|
||||
boolean isCurried();
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.signatures;
|
||||
|
||||
public interface GrMultiSignature extends GrSignature {
|
||||
|
||||
GrClosureSignature[] getAllSignatures();
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.psi.api.signatures;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public abstract class GrRecursiveSignatureVisitor extends GrSignatureVisitor {
|
||||
@Override
|
||||
public void visitMultiSignature(GrMultiSignature signature) {
|
||||
super.visitMultiSignature(signature);
|
||||
|
||||
for (GrClosureSignature s : signature.getAllSignatures()) {
|
||||
s.accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-22
@@ -1,33 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.signatures;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public interface GrSignature {
|
||||
|
||||
boolean isValid();
|
||||
|
||||
@Nullable
|
||||
GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context);
|
||||
@NotNull
|
||||
PsiSubstitutor getSubstitutor();
|
||||
|
||||
void accept(@NotNull GrSignatureVisitor visitor);
|
||||
@NotNull
|
||||
GrClosureParameter[] getParameters();
|
||||
|
||||
int getParameterCount();
|
||||
|
||||
boolean isVarargs();
|
||||
|
||||
@Nullable
|
||||
PsiType getReturnType();
|
||||
|
||||
boolean isCurried();
|
||||
}
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.psi.api.signatures;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public abstract class GrSignatureVisitor {
|
||||
public void visitClosureSignature(GrClosureSignature signature){
|
||||
visitSignature(signature);
|
||||
}
|
||||
|
||||
public void visitSignature(GrSignature signature){}
|
||||
|
||||
public void visitMultiSignature(GrMultiSignature signature){
|
||||
visitSignature(signature);
|
||||
}
|
||||
}
|
||||
+3
-17
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -23,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
@@ -60,7 +46,7 @@ public class ArgumentInstruction extends InstructionImpl implements MixinTypeIns
|
||||
|
||||
PsiType result = null;
|
||||
for (GroovyResolveResult variant : variants) {
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(variant);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(variant);
|
||||
if (signature == null) continue;
|
||||
|
||||
if (GrClosureSignatureUtil.mapParametersToArguments(signature, call) != null && !haveNullParameters(call)) {
|
||||
|
||||
+28
-29
@@ -5,47 +5,49 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.CurryKt;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class GrClosureType extends GrLiteralClassType {
|
||||
private final GrSignature mySignature;
|
||||
|
||||
private final List<GrSignature> mySignatures;
|
||||
private volatile PsiType[] myTypeArgs;
|
||||
private GrClosableBlock myClosure;
|
||||
|
||||
private GrClosureType(@NotNull LanguageLevel languageLevel,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull JavaPsiFacade facade,
|
||||
@NotNull GrSignature closureSignature,
|
||||
@NotNull List<GrSignature> signatures,
|
||||
boolean shouldInferTypeParameters) {
|
||||
super(languageLevel, scope, facade);
|
||||
mySignature = closureSignature;
|
||||
mySignatures = signatures;
|
||||
if (!shouldInferTypeParameters) myTypeArgs = PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
private GrClosureType(@NotNull LanguageLevel level,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull JavaPsiFacade facade,
|
||||
@NotNull GrSignature signature,
|
||||
@NotNull List<GrSignature> signatures,
|
||||
@Nullable PsiType[] typeArgs) {
|
||||
super(level, scope, facade);
|
||||
|
||||
mySignature = signature;
|
||||
mySignatures = signatures;
|
||||
myTypeArgs = typeArgs;
|
||||
}
|
||||
|
||||
@@ -78,7 +80,7 @@ public class GrClosureType extends GrLiteralClassType {
|
||||
public PsiType[] inferParameters() {
|
||||
final PsiClass psiClass = resolve();
|
||||
if (psiClass != null && psiClass.getTypeParameters().length == 1) {
|
||||
final PsiType type = GrClosureSignatureUtil.getReturnType(mySignature);
|
||||
final PsiType type = GrClosureSignatureUtil.getReturnType(mySignatures);
|
||||
if (type == PsiType.NULL || type == null) {
|
||||
return new PsiType[]{null};
|
||||
}
|
||||
@@ -104,17 +106,17 @@ public class GrClosureType extends GrLiteralClassType {
|
||||
return this;
|
||||
}
|
||||
|
||||
return new GrClosureType(getLanguageLevel(), getResolveScope(), myFacade, mySignature, false);
|
||||
return new GrClosureType(getLanguageLevel(), getResolveScope(), myFacade, mySignatures, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return mySignature.isValid();
|
||||
return ContainerUtil.all(mySignatures, GrSignature::isValid);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof GrClosureType) {
|
||||
return Comparing.equal(mySignature, ((GrClosureType)obj).mySignature);
|
||||
return Comparing.equal(mySignatures, ((GrClosureType)obj).mySignatures);
|
||||
}
|
||||
|
||||
return super.equals(obj);
|
||||
@@ -123,12 +125,12 @@ public class GrClosureType extends GrLiteralClassType {
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClassType setLanguageLevel(@NotNull final LanguageLevel languageLevel) {
|
||||
return new GrClosureType(languageLevel, myScope, myFacade, mySignature, myTypeArgs);
|
||||
return new GrClosureType(languageLevel, myScope, myFacade, mySignatures, myTypeArgs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GrClosureType create(@NotNull Iterable<? extends GroovyResolveResult> results, @NotNull GroovyPsiElement context) {
|
||||
List<GrClosureSignature> signatures = new ArrayList<>();
|
||||
List<GrSignature> signatures = new ArrayList<>();
|
||||
for (GroovyResolveResult result : results) {
|
||||
if (result.getElement() instanceof PsiMethod) {
|
||||
signatures.add(GrClosureSignatureUtil.createSignature((PsiMethod)result.getElement(), result.getSubstitutor()));
|
||||
@@ -137,42 +139,39 @@ public class GrClosureType extends GrLiteralClassType {
|
||||
|
||||
final GlobalSearchScope resolveScope = context.getResolveScope();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject());
|
||||
if (signatures.size() == 1) {
|
||||
return create(signatures.get(0), resolveScope, facade, LanguageLevel.JDK_1_5, true);
|
||||
}
|
||||
else {
|
||||
return create(GrClosureSignatureUtil.createMultiSignature(signatures.toArray(GrClosureSignature.EMPTY_ARRAY)),
|
||||
resolveScope, facade, LanguageLevel.JDK_1_5, true);
|
||||
}
|
||||
return create(signatures, resolveScope, facade, LanguageLevel.JDK_1_5, true);
|
||||
}
|
||||
|
||||
public static GrClosureType create(@NotNull GrClosableBlock closure, boolean shouldInferTypeParameters) {
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(closure);
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature(closure);
|
||||
final GlobalSearchScope resolveScope = closure.getResolveScope();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(closure.getProject());
|
||||
GrClosureType type = create(signature, resolveScope, facade, LanguageLevel.JDK_1_5, shouldInferTypeParameters);
|
||||
GrClosureType type = create(Collections.singletonList(signature), resolveScope, facade, LanguageLevel.JDK_1_5, shouldInferTypeParameters);
|
||||
type.setClosure(closure);
|
||||
return type;
|
||||
}
|
||||
|
||||
public static GrClosureType create(@NotNull GrSignature signature,
|
||||
@NotNull
|
||||
public static GrClosureType create(@NotNull List<GrSignature> signatures,
|
||||
GlobalSearchScope scope,
|
||||
JavaPsiFacade facade,
|
||||
@NotNull LanguageLevel languageLevel,
|
||||
boolean shouldInferTypeParameters) {
|
||||
return new GrClosureType(languageLevel, scope, facade, signature, shouldInferTypeParameters);
|
||||
return new GrClosureType(languageLevel, scope, facade, signatures, shouldInferTypeParameters);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiType curry(@NotNull PsiType[] args, int position, @NotNull GroovyPsiElement context) {
|
||||
final GrSignature newSignature = mySignature.curry(args, position, context);
|
||||
if (newSignature == null) return null;
|
||||
return new GrClosureType(myLanguageLevel, myScope, myFacade, newSignature, myTypeArgs);
|
||||
final List<GrSignature> curried = CurryKt.curry(mySignatures, args, position, context);
|
||||
if (curried.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new GrClosureType(myLanguageLevel, myScope, myFacade, curried, myTypeArgs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GrSignature getSignature() {
|
||||
return mySignature;
|
||||
public List<GrSignature> getSignatures() {
|
||||
return mySignatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -567,7 +567,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GrMethod createMethodFromSignature(@NotNull String name, @NotNull GrClosureSignature signature) {
|
||||
public GrMethod createMethodFromSignature(@NotNull String name, @NotNull GrSignature signature) {
|
||||
StringBuilder builder = new StringBuilder("public");
|
||||
final PsiType returnType = signature.getReturnType();
|
||||
if (returnType != null && returnType != PsiType.NULL) {
|
||||
|
||||
+3
-31
@@ -1,37 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.signatures;
|
||||
|
||||
import com.intellij.psi.PsiArrayType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
|
||||
class GrClosableSignatureImpl implements GrClosureSignature {
|
||||
class GrClosableSignatureImpl implements GrSignature {
|
||||
|
||||
private final GrClosableBlock myBlock;
|
||||
|
||||
GrClosableSignatureImpl(GrClosableBlock block) {
|
||||
@@ -83,15 +66,4 @@ class GrClosableSignatureImpl implements GrClosureSignature {
|
||||
public boolean isValid() {
|
||||
return myBlock.isValid();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
return GrClosureSignatureUtil.curryImpl(this, args, position, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull GrSignatureVisitor visitor) {
|
||||
visitor.visitClosureSignature(this);
|
||||
}
|
||||
}
|
||||
|
||||
+141
-198
@@ -23,9 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyMethodResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrMultiSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -55,18 +52,14 @@ public class GrClosureSignatureUtil {
|
||||
private GrClosureSignatureUtil() {
|
||||
}
|
||||
|
||||
public static GrMultiSignature createMultiSignature(GrClosureSignature[] signatures) {
|
||||
return new GrMultiSignatureImpl(signatures);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GrClosureSignature createSignature(GrCall call) {
|
||||
public static GrSignature createSignature(GrCall call) {
|
||||
if (call instanceof GrMethodCall) {
|
||||
final GrExpression invokedExpression = ((GrMethodCall)call).getInvokedExpression();
|
||||
final PsiType type = invokedExpression.getType();
|
||||
if (type instanceof GrClosureType) {
|
||||
final GrSignature signature = ((GrClosureType)type).getSignature();
|
||||
final Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult> trinity =
|
||||
final List<GrSignature> signature = ((GrClosureType)type).getSignatures();
|
||||
final Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult> trinity =
|
||||
getApplicableSignature(signature, PsiUtil.getArgumentTypes(invokedExpression, true), call);
|
||||
if (trinity != null) {
|
||||
return trinity.first;
|
||||
@@ -84,42 +77,43 @@ public class GrClosureSignatureUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GrClosureSignature createSignature(MethodSignature signature) {
|
||||
@NotNull
|
||||
public static GrSignature createSignature(@NotNull MethodSignature signature) {
|
||||
final PsiType[] types = signature.getParameterTypes();
|
||||
GrClosureParameter[] parameters = ContainerUtil.map(types, type -> new GrImmediateClosureParameterImpl(type, null, false, null), new GrClosureParameter[types.length]);
|
||||
GrClosureParameter[] parameters = ContainerUtil.map(types, type ->
|
||||
new GrImmediateClosureParameterImpl(type, null, false, null), new GrClosureParameter[types.length]
|
||||
);
|
||||
return new GrImmediateClosureSignatureImpl(parameters, null, false, false);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static GrClosureSignature createSignature(final GrClosableBlock block) {
|
||||
public static GrSignature createSignature(final GrClosableBlock block) {
|
||||
return new GrClosableSignatureImpl(block);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GrClosureSignature createSignature(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
|
||||
public static GrSignature createSignature(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
|
||||
return createSignature(method, substitutor, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GrClosureSignature createSignature(@NotNull PsiMethod method,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
boolean eraseParameterTypes) {
|
||||
public static GrSignature createSignature(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, boolean eraseParameterTypes) {
|
||||
return new GrMethodSignatureImpl(method, substitutor, eraseParameterTypes);
|
||||
}
|
||||
|
||||
public static GrClosureSignature removeParam(final GrClosureSignature signature, int i) {
|
||||
@NotNull
|
||||
public static GrSignature removeParam(final GrSignature signature, int i) {
|
||||
final GrClosureParameter[] newParams = ArrayUtil.remove(signature.getParameters(), i);
|
||||
return new GrClosureSignatureWithNewParameters(signature, newParams);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GrClosureSignature createSignatureWithErasedParameterTypes(final GrClosableBlock closure) {
|
||||
public static GrSignature createSignatureWithErasedParameterTypes(final GrClosableBlock closure) {
|
||||
return new GrClosableSignatureWithErasedParameters(closure);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GrClosureSignature rawSignature(@NotNull final GrClosureSignature signature) {
|
||||
public static GrSignature rawSignature(@NotNull final GrSignature signature) {
|
||||
final GrClosureParameter[] params = signature.getParameters();
|
||||
|
||||
final GrClosureParameter[] closureParams = ContainerUtil.map(params, parameter -> {
|
||||
@@ -130,140 +124,100 @@ public class GrClosureSignatureUtil {
|
||||
return new GrClosureSignatureWithNewParameters(signature, closureParams);
|
||||
}
|
||||
|
||||
|
||||
public static GrClosureSignature createSignature(PsiParameter[] parameters, @Nullable PsiType returnType) {
|
||||
@NotNull
|
||||
public static GrSignature createSignature(PsiParameter[] parameters, @Nullable PsiType returnType) {
|
||||
return new GrImmediateClosureSignatureImpl(parameters, returnType);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static PsiType getReturnType(@NotNull final GrSignature signature, @NotNull GrMethodCall expr) {
|
||||
return getReturnType(signature, PsiUtil.getArgumentTypes(expr.getInvokedExpression(), true), expr);
|
||||
public static PsiType getReturnType(@NotNull final List<GrSignature> signatures, @NotNull GrMethodCall expr) {
|
||||
return getReturnType(signatures, PsiUtil.getArgumentTypes(expr.getInvokedExpression(), true), expr);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getReturnType(@NotNull final GrSignature signature, @Nullable PsiType[] args, @NotNull GroovyPsiElement context) {
|
||||
if (signature instanceof GrClosureSignature) return ((GrClosureSignature)signature).getReturnType();
|
||||
|
||||
if (args == null) {
|
||||
return TypesUtil.getLeastUpperBoundNullable(new Iterable<PsiType>() {
|
||||
|
||||
@Override
|
||||
public Iterator<PsiType> iterator() {
|
||||
return new Iterator<PsiType>() {
|
||||
private final Iterator<GrClosureSignature> it = Arrays.asList(((GrMultiSignature)signature).getAllSignatures()).iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType next() {
|
||||
return it.next().getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}, context.getManager());
|
||||
public static PsiType getReturnType(@NotNull final List<GrSignature> signatures, @Nullable PsiType[] args, @NotNull GroovyPsiElement context) {
|
||||
if (signatures.size() == 1) {
|
||||
return signatures.get(0).getReturnType();
|
||||
}
|
||||
|
||||
final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results =
|
||||
getSignatureApplicabilities(signature, args, context);
|
||||
final PsiManager manager = context.getManager();
|
||||
|
||||
if (args == null) {
|
||||
return TypesUtil.getLeastUpperBoundNullable(ContainerUtil.map(signatures, GrSignature::getReturnType), manager);
|
||||
}
|
||||
|
||||
final List<Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results =
|
||||
getSignatureApplicabilities(signatures, args, context);
|
||||
|
||||
if (results.size() == 1) return results.get(0).first.getReturnType();
|
||||
|
||||
return TypesUtil.getLeastUpperBoundNullable(new Iterable<PsiType>() {
|
||||
@Override
|
||||
public Iterator<PsiType> iterator() {
|
||||
return new Iterator<PsiType>() {
|
||||
private final Iterator<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> myIterator = results.iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return myIterator.hasNext();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType next() {
|
||||
return myIterator.next().first.getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}, context.getManager());
|
||||
return TypesUtil.getLeastUpperBoundNullable(ContainerUtil.map(results, it -> it.first.getReturnType()), manager);
|
||||
}
|
||||
|
||||
public static boolean isSignatureApplicable(@NotNull GrSignature signature, @NotNull PsiType[] args, @NotNull PsiElement context) {
|
||||
public static boolean isSignatureApplicable(@NotNull List<GrSignature> signature, @NotNull PsiType[] args, @NotNull PsiElement context) {
|
||||
return isSignatureApplicableConcrete(signature, args, context) != ApplicabilityResult.inapplicable;
|
||||
}
|
||||
|
||||
public static ApplicabilityResult isSignatureApplicableConcrete(@NotNull GrSignature signature, @NotNull final PsiType[] args, @NotNull final PsiElement context) {
|
||||
final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results =
|
||||
getSignatureApplicabilities(signature, args, context);
|
||||
|
||||
if (results.isEmpty()) return ApplicabilityResult.inapplicable;
|
||||
else if (results.size()==1) return results.get(0).third;
|
||||
else return ApplicabilityResult.ambiguous;
|
||||
public static ApplicabilityResult isSignatureApplicableConcrete(@NotNull List<GrSignature> signatures,
|
||||
@NotNull final PsiType[] args,
|
||||
@NotNull final PsiElement context) {
|
||||
final List<Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results =
|
||||
getSignatureApplicabilities(signatures, args, context);
|
||||
if (results.isEmpty()) {
|
||||
return ApplicabilityResult.inapplicable;
|
||||
}
|
||||
else if (results.size() == 1) {
|
||||
return results.get(0).third;
|
||||
}
|
||||
else {
|
||||
return ApplicabilityResult.ambiguous;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult> getApplicableSignature(@NotNull GrSignature signature,
|
||||
public static Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult> getApplicableSignature(@NotNull List<GrSignature> signatures,
|
||||
@Nullable final PsiType[] args,
|
||||
@NotNull final GroovyPsiElement context) {
|
||||
if (args == null) return null;
|
||||
final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = getSignatureApplicabilities(signature, args, context);
|
||||
final List<Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = getSignatureApplicabilities(signatures, args, context);
|
||||
|
||||
if (results.size() == 1) return results.get(0);
|
||||
else return null;
|
||||
}
|
||||
|
||||
private static List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> getSignatureApplicabilities(@NotNull GrSignature signature,
|
||||
@NotNull final PsiType[] args,
|
||||
@NotNull final PsiElement context) {
|
||||
final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results =
|
||||
new ArrayList<>();
|
||||
signature.accept(new GrRecursiveSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
ArgInfo<PsiType>[] map = mapArgTypesToParameters(signature, args, context, false);
|
||||
if (map != null) {
|
||||
results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
|
||||
return;
|
||||
}
|
||||
private static List<Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult>> getSignatureApplicabilities(@NotNull List<GrSignature> signatures,
|
||||
@NotNull final PsiType[] args,
|
||||
@NotNull final PsiElement context) {
|
||||
final List<Trinity<GrSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = new ArrayList<>();
|
||||
for (GrSignature signature : signatures) {
|
||||
ArgInfo<PsiType>[] map = mapArgTypesToParameters(signature, args, context, false);
|
||||
if (map != null) {
|
||||
results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for the case foo([1, 2, 3]) if foo(int, int, int)
|
||||
if (args.length == 1 && PsiUtil.isInMethodCallContext(context)) {
|
||||
final GrClosureParameter[] parameters = signature.getParameters();
|
||||
if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) {
|
||||
return;
|
||||
}
|
||||
PsiType arg = args[0];
|
||||
if (arg instanceof GrTupleType) {
|
||||
PsiType[] _args = ((GrTupleType)arg).getComponentTypesArray();
|
||||
map = mapArgTypesToParameters(signature, _args, context, false);
|
||||
if (map != null) {
|
||||
results.add(new Trinity<>(signature, map,
|
||||
isSignatureApplicableInner(map,
|
||||
signature)));
|
||||
}
|
||||
// check for the case foo([1, 2, 3]) if foo(int, int, int)
|
||||
if (args.length == 1 && PsiUtil.isInMethodCallContext(context)) {
|
||||
final GrClosureParameter[] parameters = signature.getParameters();
|
||||
if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) {
|
||||
continue;
|
||||
}
|
||||
PsiType arg = args[0];
|
||||
if (arg instanceof GrTupleType) {
|
||||
PsiType[] _args = ((GrTupleType)arg).getComponentTypesArray();
|
||||
map = mapArgTypesToParameters(signature, _args, context, false);
|
||||
if (map != null) {
|
||||
results.add(new Trinity<>(signature, map,
|
||||
isSignatureApplicableInner(map,
|
||||
signature)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ApplicabilityResult isSignatureApplicableInner(@NotNull ArgInfo<PsiType>[] infos, @NotNull GrClosureSignature signature) {
|
||||
private static ApplicabilityResult isSignatureApplicableInner(@NotNull ArgInfo<PsiType>[] infos, @NotNull GrSignature signature) {
|
||||
GrClosureParameter[] parameters = signature.getParameters();
|
||||
for (int i = 0; i < infos.length; i++) {
|
||||
ArgInfo<PsiType> info = infos[i];
|
||||
@@ -279,8 +233,8 @@ public class GrClosureSignatureUtil {
|
||||
return ApplicabilityResult.applicable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static GrSignature curryImpl(@NotNull GrClosureSignature original, PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
@NotNull
|
||||
static List<GrSignature> curryImpl(@NotNull GrSignature original, PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
GrClosureParameter[] params = original.getParameters();
|
||||
|
||||
List<GrClosureParameter> newParams = new ArrayList<>(params.length);
|
||||
@@ -291,7 +245,9 @@ public class GrClosureSignatureUtil {
|
||||
position = params.length - args.length;
|
||||
}
|
||||
|
||||
if (position < 0 || position >= params.length) return null;
|
||||
if (position < 0 || position >= params.length) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (params[i].isOptional()) {
|
||||
@@ -304,7 +260,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
final PsiType rtype = original.getReturnType();
|
||||
final ArrayList<GrClosureSignature> result = new ArrayList<>();
|
||||
final ArrayList<GrSignature> result = new ArrayList<>();
|
||||
checkAndAddSignature(result, args, position, newParams, rtype, context);
|
||||
|
||||
for (int i = 0; i < opts.size(); i++) {
|
||||
@@ -312,12 +268,7 @@ public class GrClosureSignatureUtil {
|
||||
checkAndAddSignature(result, args, position, newParams, rtype, context);
|
||||
}
|
||||
|
||||
if (result.size() == 1) {
|
||||
return result.get(0);
|
||||
}
|
||||
else {
|
||||
return new GrMultiSignatureImpl(result.toArray(GrClosureSignature.EMPTY_ARRAY));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isVarArgsImpl(@NotNull GrClosureParameter[] parameters) {
|
||||
@@ -329,7 +280,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ArgInfo<PsiType>[] mapArgTypesToParameters(@NotNull GrClosureSignature signature,
|
||||
public static ArgInfo<PsiType>[] mapArgTypesToParameters(@NotNull GrSignature signature,
|
||||
@NotNull PsiType[] args,
|
||||
@NotNull PsiElement context,
|
||||
boolean partial) {
|
||||
@@ -337,11 +288,11 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <Arg> ArgInfo<Arg>[] mapParametersToArguments(@NotNull GrClosureSignature signature,
|
||||
@NotNull Arg[] args,
|
||||
@NotNull Function<Arg, PsiType> typeComputer,
|
||||
@NotNull PsiElement context,
|
||||
boolean partial) {
|
||||
public static <Arg> ArgInfo<Arg>[] mapParametersToArguments(@NotNull GrSignature signature,
|
||||
@NotNull Arg[] args,
|
||||
@NotNull Function<Arg, PsiType> typeComputer,
|
||||
@NotNull PsiElement context,
|
||||
boolean partial) {
|
||||
LOG.assertTrue(signature.isValid(), signature.getClass());
|
||||
|
||||
if (checkForOnlyMapParam(signature, args.length)) return ArgInfo.empty_array();
|
||||
@@ -364,7 +315,7 @@ public class GrClosureSignatureUtil {
|
||||
return mapSimple(params, args, typeComputer, context, optional, true);
|
||||
}
|
||||
|
||||
private static boolean checkForOnlyMapParam(@NotNull GrClosureSignature signature, final int argCount) {
|
||||
private static boolean checkForOnlyMapParam(@NotNull GrSignature signature, final int argCount) {
|
||||
if (argCount > 0 || signature.isCurried()) return false;
|
||||
final GrClosureParameter[] parameters = signature.getParameters();
|
||||
if (parameters.length != 1) return false;
|
||||
@@ -421,7 +372,7 @@ public class GrClosureSignatureUtil {
|
||||
return TypesUtil.isAssignableByMethodCallConversion(lType != null ? lType : paramType, rType != null ? rType : argType, context);
|
||||
}
|
||||
|
||||
public static void checkAndAddSignature(List<? super GrClosureSignature> list,
|
||||
public static void checkAndAddSignature(List<? super GrSignature> list,
|
||||
PsiType[] args,
|
||||
int position,
|
||||
List<? extends GrClosureParameter> params,
|
||||
@@ -449,7 +400,7 @@ public class GrClosureSignatureUtil {
|
||||
|
||||
|
||||
@Nullable
|
||||
public static GrClosureSignature createSignature(GroovyResolveResult resolveResult) {
|
||||
public static GrSignature createSignature(GroovyResolveResult resolveResult) {
|
||||
final PsiElement resolved = resolveResult.getElement();
|
||||
if (!(resolved instanceof PsiMethod)) return null;
|
||||
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
@@ -547,7 +498,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getOptionalParamCount(@NotNull GrClosureSignature signature, PsiElement context) {
|
||||
private static int getOptionalParamCount(@NotNull GrSignature signature, PsiElement context) {
|
||||
GrClosureParameter[] parameters = signature.getParameters();
|
||||
boolean isCompileStatic = PsiUtil.isCompileStatic(context);
|
||||
if (parameters.length == 1 && !(parameters[0].getType() instanceof PsiPrimitiveType) && !signature.isCurried() && !isCompileStatic)
|
||||
@@ -604,7 +555,7 @@ public class GrClosureSignatureUtil {
|
||||
@NotNull final GrNamedArgument[] namedArgs,
|
||||
@NotNull final GrExpression[] expressionArgs,
|
||||
@NotNull GrClosableBlock[] closureArguments) {
|
||||
final GrClosureSignature signature;
|
||||
final GrSignature signature;
|
||||
final PsiParameter[] parameters;
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
PsiSubstitutor substitutor;
|
||||
@@ -654,13 +605,13 @@ public class GrClosureSignatureUtil {
|
||||
|
||||
|
||||
@Nullable
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrClosureSignature signature, @NotNull GrCall call) {
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrSignature signature, @NotNull GrCall call) {
|
||||
return mapParametersToArguments(signature, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments(), call,
|
||||
false, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrClosureSignature signature,
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrSignature signature,
|
||||
@NotNull GrNamedArgument[] namedArgs,
|
||||
@NotNull GrExpression[] expressionArgs,
|
||||
@NotNull GrClosableBlock[] closureArguments,
|
||||
@@ -702,7 +653,7 @@ public class GrClosureSignatureUtil {
|
||||
return mapParametersToArguments(signature, innerArgs, hasNamedArgs, partial, context);
|
||||
}
|
||||
|
||||
private static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrClosureSignature signature,
|
||||
private static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrSignature signature,
|
||||
@NotNull List<? extends InnerArg> innerArgs,
|
||||
boolean hasNamedArgs,
|
||||
boolean partial,
|
||||
@@ -737,7 +688,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
public static List<MethodSignature> generateAllSignaturesForMethod(GrMethod method, PsiSubstitutor substitutor) {
|
||||
GrClosureSignature signature = createSignature(method, substitutor);
|
||||
GrSignature signature = createSignature(method, substitutor);
|
||||
String name = method.getName();
|
||||
PsiTypeParameter[] typeParameters = method.getTypeParameters();
|
||||
|
||||
@@ -791,7 +742,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
public static void generateAllMethodSignaturesByClosureSignature(@NotNull String name,
|
||||
@NotNull GrClosureSignature signature,
|
||||
@NotNull GrSignature signature,
|
||||
@NotNull PsiTypeParameter[] typeParameters,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
List<? super MethodSignature> result) {
|
||||
@@ -819,15 +770,13 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
public static List<MethodSignature> generateAllMethodSignaturesBySignature(@NotNull final String name,
|
||||
@NotNull final GrSignature signature) {
|
||||
|
||||
@NotNull final List<GrSignature> signatures) {
|
||||
final ArrayList<MethodSignature> result = new ArrayList<>();
|
||||
signature.accept(new GrRecursiveSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
generateAllMethodSignaturesByClosureSignature(name, signature, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, result);
|
||||
}
|
||||
});
|
||||
|
||||
for (GrSignature signature : signatures) {
|
||||
generateAllMethodSignaturesByClosureSignature(name, signature, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -867,30 +816,27 @@ public class GrClosureSignatureUtil {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param signature
|
||||
* @return return type or null if there is some different return types
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiType getReturnType(GrSignature signature) {
|
||||
if (signature instanceof GrClosureSignature) {
|
||||
return ((GrClosureSignature)signature).getReturnType();
|
||||
public static PsiType getReturnType(List<GrSignature> signatures) {
|
||||
if (signatures.size() == 1) {
|
||||
return signatures.get(0).getReturnType();
|
||||
}
|
||||
else if (signature instanceof GrMultiSignature) {
|
||||
final GrClosureSignature[] signatures = ((GrMultiSignature)signature).getAllSignatures();
|
||||
if (signatures.length == 0) return null;
|
||||
final PsiType type = signatures[0].getReturnType();
|
||||
else if (signatures.size() > 1) {
|
||||
final PsiType type = signatures.get(0).getReturnType();
|
||||
if (type == null) return null;
|
||||
String firstType = type.getCanonicalText();
|
||||
for (int i = 1; i < signatures.length; i++) {
|
||||
final PsiType _type = signatures[i].getReturnType();
|
||||
for (int i = 1; i < signatures.size(); i++) {
|
||||
final PsiType _type = signatures.get(i).getReturnType();
|
||||
if (_type == null) return null;
|
||||
if (!firstType.equals(_type.getCanonicalText())) return null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
return null;
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -907,7 +853,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <Arg> MapResultWithError mapSimpleSignatureWithErrors(@NotNull GrClosureSignature signature,
|
||||
public static <Arg> MapResultWithError mapSimpleSignatureWithErrors(@NotNull GrSignature signature,
|
||||
@NotNull Arg[] args,
|
||||
@NotNull Function<? super Arg, ? extends PsiType> typeComputer,
|
||||
@NotNull GroovyPsiElement context,
|
||||
@@ -947,39 +893,36 @@ public class GrClosureSignatureUtil {
|
||||
return new MapResultWithError(errors);
|
||||
}
|
||||
|
||||
public static List<GrClosureSignature> generateSimpleSignatures(@NotNull GrSignature signature) {
|
||||
final List<GrClosureSignature> result = new ArrayList<>();
|
||||
signature.accept(new GrRecursiveSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
final GrClosureParameter[] original = signature.getParameters();
|
||||
final ArrayList<GrClosureParameter> parameters = new ArrayList<>(original.length);
|
||||
public static List<GrSignature> generateSimpleSignatures(@NotNull List<GrSignature> signatures) {
|
||||
final List<GrSignature> result = new ArrayList<>();
|
||||
for (GrSignature signature : signatures) {
|
||||
final GrClosureParameter[] original = signature.getParameters();
|
||||
final ArrayList<GrClosureParameter> parameters = new ArrayList<>(original.length);
|
||||
|
||||
for (GrClosureParameter parameter : original) {
|
||||
parameters.add(new GrDelegatingClosureParameter(parameter) {
|
||||
@Override
|
||||
public boolean isOptional() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrExpression getDefaultInitializer() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final int pCount = signature.isVarargs() ? signature.getParameterCount() - 2 : signature.getParameterCount() - 1;
|
||||
for (int i = pCount; i >= 0; i--) {
|
||||
if (original[i].isOptional()) {
|
||||
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(GrClosureParameter.EMPTY_ARRAY), signature.getReturnType(), signature.isVarargs(), false));
|
||||
parameters.remove(i);
|
||||
for (GrClosureParameter parameter : original) {
|
||||
parameters.add(new GrDelegatingClosureParameter(parameter) {
|
||||
@Override
|
||||
public boolean isOptional() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(GrClosureParameter.EMPTY_ARRAY), signature.getReturnType(), signature.isVarargs(), false));
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrExpression getDefaultInitializer() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
final int pCount = signature.isVarargs() ? signature.getParameterCount() - 2 : signature.getParameterCount() - 1;
|
||||
for (int i = pCount; i >= 0; i--) {
|
||||
if (original[i].isOptional()) {
|
||||
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(GrClosureParameter.EMPTY_ARRAY), signature.getReturnType(), signature.isVarargs(), false));
|
||||
parameters.remove(i);
|
||||
}
|
||||
}
|
||||
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(GrClosureParameter.EMPTY_ARRAY), signature.getReturnType(), signature.isVarargs(), false));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+5
-32
@@ -1,35 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.signatures;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
|
||||
public class GrClosureSignatureWithNewParameters implements GrClosureSignature {
|
||||
private final GrClosureSignature myDelegate;
|
||||
public class GrClosureSignatureWithNewParameters implements GrSignature {
|
||||
|
||||
private final GrSignature myDelegate;
|
||||
private final GrClosureParameter[] myParams;
|
||||
|
||||
public GrClosureSignatureWithNewParameters(@NotNull GrClosureSignature delegate, @NotNull GrClosureParameter[] newParams) {
|
||||
public GrClosureSignatureWithNewParameters(@NotNull GrSignature delegate, @NotNull GrClosureParameter[] newParams) {
|
||||
myDelegate = delegate;
|
||||
myParams = newParams;
|
||||
}
|
||||
@@ -71,15 +55,4 @@ public class GrClosureSignatureWithNewParameters implements GrClosureSignature {
|
||||
public boolean isValid() {
|
||||
return myDelegate.isValid();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
return GrClosureSignatureUtil.curryImpl(this, args, position, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull GrSignatureVisitor visitor) {
|
||||
visitor.visitClosureSignature(this);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-35
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.signatures;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -21,16 +7,15 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GrImmediateClosureSignatureImpl implements GrClosureSignature {
|
||||
public class GrImmediateClosureSignatureImpl implements GrSignature {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(GrImmediateClosureSignatureImpl.class);
|
||||
|
||||
private final boolean myIsVarargs;
|
||||
@@ -99,12 +84,6 @@ public class GrImmediateClosureSignatureImpl implements GrClosureSignature {
|
||||
return myParameters.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
return GrClosureSignatureUtil.curryImpl(this, args, position, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
for (GrClosureParameter parameter : myParameters) {
|
||||
@@ -116,9 +95,9 @@ public class GrImmediateClosureSignatureImpl implements GrClosureSignature {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof GrClosureSignature) {
|
||||
return Comparing.equal(myParameters, ((GrClosureSignature)obj).getParameters()) &&
|
||||
Comparing.equal(myIsVarargs, ((GrClosureSignature)obj).isVarargs());
|
||||
if (obj instanceof GrSignature) {
|
||||
return Comparing.equal(myParameters, ((GrSignature)obj).getParameters()) &&
|
||||
Comparing.equal(myIsVarargs, ((GrSignature)obj).isVarargs());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
@@ -129,9 +108,9 @@ public class GrImmediateClosureSignatureImpl implements GrClosureSignature {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GrClosureSignature getLeastUpperBound(@NotNull GrClosureSignature signature1,
|
||||
@NotNull GrClosureSignature signature2,
|
||||
PsiManager manager) {
|
||||
public static GrSignature getLeastUpperBound(@NotNull GrSignature signature1,
|
||||
@NotNull GrSignature signature2,
|
||||
@NotNull PsiManager manager) {
|
||||
GrClosureParameter[] parameters1 = signature1.getParameters();
|
||||
GrClosureParameter[] parameters2 = signature2.getParameters();
|
||||
|
||||
@@ -154,11 +133,6 @@ public class GrImmediateClosureSignatureImpl implements GrClosureSignature {
|
||||
}
|
||||
return null; //todo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull GrSignatureVisitor visitor) {
|
||||
visitor.visitClosureSignature(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-16
@@ -1,19 +1,19 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.signatures;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
class GrMethodSignatureImpl implements GrClosureSignature {
|
||||
class GrMethodSignatureImpl implements GrSignature {
|
||||
|
||||
private final PsiMethod myMethod;
|
||||
private final PsiSubstitutor mySubstitutor;
|
||||
@@ -82,15 +82,4 @@ class GrMethodSignatureImpl implements GrClosureSignature {
|
||||
public boolean isValid() {
|
||||
return myMethod.isValid() && getSubstitutor().isValid();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
return GrClosureSignatureUtil.curryImpl(this, args, position, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull GrSignatureVisitor visitor) {
|
||||
visitor.visitClosureSignature(this);
|
||||
}
|
||||
}
|
||||
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.psi.impl.signatures;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrMultiSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMultiSignatureImpl implements GrMultiSignature {
|
||||
private final GrClosureSignature[] mySignatures;
|
||||
|
||||
public GrMultiSignatureImpl(GrClosureSignature[] signatures) {
|
||||
mySignatures = signatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrClosureSignature[] getAllSignatures() {
|
||||
return mySignatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
for (GrClosureSignature signature : mySignatures) {
|
||||
if (!signature.isValid()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context) {
|
||||
List<GrClosureSignature> newClosures = new ArrayList<>();
|
||||
|
||||
for (GrClosureSignature old : mySignatures) {
|
||||
final GrSignature curried = old.curry(args, position, context);
|
||||
if (curried instanceof GrClosureSignature) {
|
||||
newClosures.add((GrClosureSignature)curried);
|
||||
}
|
||||
else if (curried instanceof GrMultiSignature) {
|
||||
newClosures.addAll(Arrays.asList(((GrMultiSignature)curried).getAllSignatures()));
|
||||
}
|
||||
}
|
||||
return new GrMultiSignatureImpl(newClosures.toArray(GrClosureSignature.EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull GrSignatureVisitor visitor) {
|
||||
visitor.visitMultiSignature(this);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.signatures
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature
|
||||
|
||||
fun curry(signatures: List<GrSignature>, args: Array<PsiType>, position: Int, context: PsiElement): List<GrSignature> {
|
||||
return signatures.flatMap {
|
||||
GrClosureSignatureUtil.curryImpl(it, args, position, context)
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -26,7 +26,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.SpreadState;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
@@ -370,7 +369,7 @@ public class TypesUtil implements TypeConstants {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getLeastUpperBound(@NotNull PsiType type1, @NotNull PsiType type2, PsiManager manager) {
|
||||
public static PsiType getLeastUpperBound(@NotNull PsiType type1, @NotNull PsiType type2, @NotNull PsiManager manager) {
|
||||
{
|
||||
PsiType numericLUB = getNumericLUB(type1, type2);
|
||||
if (numericLUB != null) return numericLUB;
|
||||
@@ -415,17 +414,18 @@ public class TypesUtil implements TypeConstants {
|
||||
else if (type1 instanceof GrClosureType && type2 instanceof GrClosureType) {
|
||||
GrClosureType clType1 = (GrClosureType)type1;
|
||||
GrClosureType clType2 = (GrClosureType)type2;
|
||||
GrSignature signature1 = clType1.getSignature();
|
||||
GrSignature signature2 = clType2.getSignature();
|
||||
List<GrSignature> signatures1 = clType1.getSignatures();
|
||||
List<GrSignature> signatures2 = clType2.getSignatures();
|
||||
|
||||
if (signature1 instanceof GrClosureSignature && signature2 instanceof GrClosureSignature) {
|
||||
if (((GrClosureSignature)signature1).getParameterCount() == ((GrClosureSignature)signature2).getParameterCount()) {
|
||||
final GrClosureSignature signature = GrImmediateClosureSignatureImpl.getLeastUpperBound(((GrClosureSignature)signature1),
|
||||
((GrClosureSignature)signature2), manager);
|
||||
if (signatures1.size() == 1 && signatures2.size() == 1) {
|
||||
final GrSignature signature1 = signatures1.get(0);
|
||||
final GrSignature signature2 = signatures2.get(0);
|
||||
if (signature1.getParameterCount() == signature2.getParameterCount()) {
|
||||
final GrSignature signature = GrImmediateClosureSignatureImpl.getLeastUpperBound(signature1, signature2, manager);
|
||||
if (signature != null) {
|
||||
GlobalSearchScope scope = clType1.getResolveScope().intersectWith(clType2.getResolveScope());
|
||||
final LanguageLevel languageLevel = ComparatorUtil.max(clType1.getLanguageLevel(), clType2.getLanguageLevel());
|
||||
return GrClosureType.create(signature, scope, JavaPsiFacade.getInstance(manager.getProject()), languageLevel, true);
|
||||
return GrClosureType.create(Collections.singletonList(signature), scope, JavaPsiFacade.getInstance(manager.getProject()), languageLevel, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,7 +465,7 @@ public class TypesUtil implements TypeConstants {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static PsiType genNewListBy(PsiType genericOwner, PsiManager manager) {
|
||||
private static PsiType genNewListBy(PsiType genericOwner, @NotNull PsiManager manager) {
|
||||
PsiClass list = JavaPsiFacade.getInstance(manager.getProject()).findClass(CommonClassNames.JAVA_UTIL_LIST, genericOwner.getResolveScope());
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject());
|
||||
if (list == null) return factory.createTypeFromText(CommonClassNames.JAVA_UTIL_LIST, null);
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ public class DefaultCallExpressionTypeCalculator extends GrCallExpressionTypeCal
|
||||
private static PsiType extractReturnTypeFromType(PsiType type, boolean returnTypeIfFail, GrMethodCall callExpression) {
|
||||
PsiType returnType = returnTypeIfFail ? type: null;
|
||||
if (type instanceof GrClosureType) {
|
||||
returnType = GrClosureSignatureUtil.getReturnType(((GrClosureType)type).getSignature(), callExpression);
|
||||
returnType = GrClosureSignatureUtil.getReturnType(((GrClosureType)type).getSignatures(), callExpression);
|
||||
}
|
||||
else if (TypesUtil.isPsiClassTypeToClosure(type)) {
|
||||
assert type instanceof PsiClassType;
|
||||
@@ -155,7 +155,7 @@ public class DefaultCallExpressionTypeCalculator extends GrCallExpressionTypeCal
|
||||
if (!(qType instanceof GrClosureType)) return null;
|
||||
|
||||
if ("call".equals(resolved.getName())) {
|
||||
return GrClosureSignatureUtil.getReturnType(((GrClosureType)qType).getSignature(), callExpression);
|
||||
return GrClosureSignatureUtil.getReturnType(((GrClosureType)qType).getSignatures(), callExpression);
|
||||
}
|
||||
else if ("curry".equals(resolved.getName()) || "trampoline".equals(resolved.getName())) {
|
||||
return ((GrClosureType)qType).curry(PsiUtil.getArgumentTypes(refExpr, false), 0, callExpression);
|
||||
|
||||
+7
-16
@@ -18,9 +18,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
@@ -169,7 +167,7 @@ public class GdkMethodUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static GrMethod createMethod(@NotNull GrClosureSignature signature,
|
||||
private static GrMethod createMethod(@NotNull GrSignature signature,
|
||||
@NotNull String name,
|
||||
@NotNull GrAssignmentExpression statement,
|
||||
@NotNull PsiClass closure) {
|
||||
@@ -201,7 +199,7 @@ public class GdkMethodUtil {
|
||||
Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
|
||||
if (original == null) return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
|
||||
final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
|
||||
final Pair<List<GrSignature>, String> signatures = getTypeToMix(assignment);
|
||||
if (signatures == null) return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
|
||||
final String name = signatures.second;
|
||||
@@ -210,14 +208,9 @@ public class GdkMethodUtil {
|
||||
final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
|
||||
if (closure == null) return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
|
||||
signatures.first.accept(new GrSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
super.visitClosureSignature(signature);
|
||||
GrMethod method = createMethod(signature, name, assignment, closure);
|
||||
methods.add(method);
|
||||
}
|
||||
});
|
||||
for (GrSignature signature : signatures.first) {
|
||||
methods.add(createMethod(signature, name, assignment, closure));
|
||||
}
|
||||
|
||||
return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
@@ -242,19 +235,17 @@ public class GdkMethodUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<GrSignature, String> getTypeToMix(GrAssignmentExpression assignment) {
|
||||
private static Pair<List<GrSignature>, String> getTypeToMix(GrAssignmentExpression assignment) {
|
||||
GrExpression mixinRef = assignment.getRValue();
|
||||
if (mixinRef == null) return null;
|
||||
|
||||
final PsiType type = mixinRef.getType();
|
||||
if (type instanceof GrClosureType) {
|
||||
final GrSignature signature = ((GrClosureType)type).getSignature();
|
||||
|
||||
final GrExpression lValue = assignment.getLValue();
|
||||
assert lValue instanceof GrReferenceExpression;
|
||||
final String name = ((GrReferenceExpression)lValue).getReferenceName();
|
||||
|
||||
return Pair.create(signature, name);
|
||||
return Pair.create(((GrClosureType)type).getSignatures(), name);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+15
-16
@@ -35,7 +35,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
@@ -79,6 +78,7 @@ import java.util.*;
|
||||
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT;
|
||||
import static com.intellij.psi.GenericsUtil.isTypeArgumentsApplicable;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.*;
|
||||
|
||||
/**
|
||||
@@ -138,13 +138,13 @@ public class PsiUtil {
|
||||
PsiElement place,
|
||||
final boolean eraseParameterTypes) {
|
||||
if (argumentTypes == null) return GrClosureSignatureUtil.ApplicabilityResult.canBeApplicable;
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, substitutor, eraseParameterTypes);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(method, substitutor, eraseParameterTypes);
|
||||
|
||||
GrClosureSignatureUtil.ApplicabilityResult result =
|
||||
GroovyApplicabilityProvider.checkProviders(argumentTypes, method, substitutor, place, eraseParameterTypes);
|
||||
if (result != null) return result;
|
||||
|
||||
result = GrClosureSignatureUtil.isSignatureApplicableConcrete(signature, argumentTypes, place);
|
||||
result = GrClosureSignatureUtil.isSignatureApplicableConcrete(singletonList(signature), argumentTypes, place);
|
||||
if (result != GrClosureSignatureUtil.ApplicabilityResult.inapplicable &&
|
||||
isTypeArgumentsApplicable(method.getTypeParameters(), substitutor, place)) {
|
||||
return result;
|
||||
@@ -154,24 +154,23 @@ public class PsiUtil {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if (parameters.length > 0 && parameters[0].getType() instanceof GrMapType &&
|
||||
(argumentTypes.length == 0 || !(argumentTypes[0] instanceof GrMapType))) {
|
||||
return GrClosureSignatureUtil.isSignatureApplicableConcrete(GrClosureSignatureUtil.removeParam(signature, 0), argumentTypes, place);
|
||||
return GrClosureSignatureUtil.isSignatureApplicableConcrete(singletonList(GrClosureSignatureUtil.removeParam(signature, 0)), argumentTypes, place);
|
||||
}
|
||||
}
|
||||
return GrClosureSignatureUtil.ApplicabilityResult.inapplicable;
|
||||
}
|
||||
|
||||
public static boolean isApplicable(@Nullable PsiType[] argumentTypes,
|
||||
GrClosureType type,
|
||||
GroovyPsiElement context) {
|
||||
@NotNull GrClosureType type,
|
||||
@NotNull GroovyPsiElement context) {
|
||||
return isApplicableConcrete(argumentTypes, type, context) != GrClosureSignatureUtil.ApplicabilityResult.inapplicable;
|
||||
}
|
||||
|
||||
public static GrClosureSignatureUtil.ApplicabilityResult isApplicableConcrete(@Nullable PsiType[] argumentTypes,
|
||||
GrClosureType type,
|
||||
GroovyPsiElement context) {
|
||||
@NotNull GrClosureType type,
|
||||
@NotNull GroovyPsiElement context) {
|
||||
if (argumentTypes == null) return GrClosureSignatureUtil.ApplicabilityResult.canBeApplicable;
|
||||
|
||||
GrSignature signature = type.getSignature();
|
||||
List<GrSignature> signature = type.getSignatures();
|
||||
return GrClosureSignatureUtil.isSignatureApplicableConcrete(signature, argumentTypes, context);
|
||||
}
|
||||
|
||||
@@ -533,15 +532,15 @@ public class PsiUtil {
|
||||
}
|
||||
|
||||
private static boolean isRawClosureCall(GrMethodCallExpression call, GroovyResolveResult result, GrClosureType returnType) {
|
||||
final GrSignature signature = returnType.getSignature();
|
||||
GrClosureSignature _signature;
|
||||
if (signature instanceof GrClosureSignature) {
|
||||
_signature = (GrClosureSignature)signature;
|
||||
final List<GrSignature> signatures = returnType.getSignatures();
|
||||
GrSignature _signature;
|
||||
if (signatures.size() == 1) {
|
||||
_signature = signatures.get(0);
|
||||
}
|
||||
else {
|
||||
final PsiType[] types = getArgumentTypes(call.getInvokedExpression(), true);
|
||||
final Trinity<GrClosureSignature, GrClosureSignatureUtil.ArgInfo<PsiType>[], GrClosureSignatureUtil.ApplicabilityResult>
|
||||
resultTrinity = types != null ? GrClosureSignatureUtil.getApplicableSignature(signature, types, call) : null;
|
||||
final Trinity<GrSignature, GrClosureSignatureUtil.ArgInfo<PsiType>[], GrClosureSignatureUtil.ApplicabilityResult>
|
||||
resultTrinity = types != null ? GrClosureSignatureUtil.getApplicableSignature(signatures, types, call) : null;
|
||||
_signature = Trinity.getFirst(resultTrinity);
|
||||
}
|
||||
if (_signature != null) {
|
||||
|
||||
+2
-2
@@ -770,7 +770,7 @@ public class ResolveUtil {
|
||||
if (!(type instanceof GrClosureType)) return false;
|
||||
if (argTypes == null) return true;
|
||||
|
||||
final GrSignature signature = ((GrClosureType)type).getSignature();
|
||||
final List<GrSignature> signature = ((GrClosureType)type).getSignatures();
|
||||
return GrClosureSignatureUtil.isSignatureApplicable(signature, argTypes, place);
|
||||
}
|
||||
|
||||
@@ -793,7 +793,7 @@ public class ResolveUtil {
|
||||
return null;
|
||||
}
|
||||
if (type instanceof GrClosureType) {
|
||||
final GrSignature signature = ((GrClosureType)type).getSignature();
|
||||
final List<GrSignature> signature = ((GrClosureType)type).getSignatures();
|
||||
PsiType returnType = GrClosureSignatureUtil.getReturnType(signature, args, expression);
|
||||
return TypesUtil.substituteAndNormalizeType(returnType, candidate.getSubstitutor(), candidate.getSpreadState(), expression);
|
||||
}
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ import com.intellij.psi.util.TypeConversionUtil
|
||||
import groovy.lang.Closure.*
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyMethodResult
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression
|
||||
@@ -65,7 +65,7 @@ class DefaultDelegatesToProvider : GrDelegatesToProvider {
|
||||
return DelegatesToInfo(delegateType, strategyValue)
|
||||
}
|
||||
|
||||
private fun mapArgs(place: PsiElement, call: GrCall, signature: GrClosureSignature): Array<GrClosureSignatureUtil.ArgInfo<PsiElement>>? {
|
||||
private fun mapArgs(place: PsiElement, call: GrCall, signature: GrSignature): Array<GrClosureSignatureUtil.ArgInfo<PsiElement>>? {
|
||||
val rawSignature = GrClosureSignatureUtil.rawSignature(signature)
|
||||
return GrClosureSignatureUtil.mapParametersToArguments(
|
||||
rawSignature, call.namedArguments, call.expressionArguments, call.closureArguments, place, false, false
|
||||
@@ -105,7 +105,7 @@ class DefaultDelegatesToProvider : GrDelegatesToProvider {
|
||||
|
||||
private fun getFromTarget(parameterList: PsiParameterList,
|
||||
delegatesTo: PsiAnnotation,
|
||||
signature: GrClosureSignature,
|
||||
signature: GrSignature,
|
||||
map: Array<GrClosureSignatureUtil.ArgInfo<PsiElement>>): PsiType? {
|
||||
val target = GrAnnotationUtil.inferStringAttribute(delegatesTo, "target") ?: return null
|
||||
|
||||
@@ -122,7 +122,7 @@ class DefaultDelegatesToProvider : GrDelegatesToProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private fun inferGenericArgType(signature: GrClosureSignature, targetType: PsiType?, genericIndex: Int, param: Int): PsiType? {
|
||||
private fun inferGenericArgType(signature: GrSignature, targetType: PsiType?, genericIndex: Int, param: Int): PsiType? {
|
||||
if (targetType !is PsiClassType) return null
|
||||
val result = targetType.resolveGenerics()
|
||||
val psiClass = result.element ?: return null
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
@@ -169,9 +169,9 @@ public class SubstitutorComputer {
|
||||
@NotNull PsiType[] argTypes) {
|
||||
if (typeParameters.length == 0 || myArgumentTypes == null) return partialSubstitutor;
|
||||
|
||||
final GrClosureSignature erasedSignature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor, true);
|
||||
final GrSignature erasedSignature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor, true);
|
||||
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor);
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature(method, partialSubstitutor);
|
||||
final GrClosureParameter[] params = signature.getParameters();
|
||||
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiType>[] argInfos =
|
||||
|
||||
+5
-20
@@ -1,19 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.intentions.conversions;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -28,7 +13,6 @@ import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import java.util.HashSet;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
@@ -39,7 +23,6 @@ import org.jetbrains.plugins.groovy.lang.documentation.GroovyPresentationUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
@@ -53,6 +36,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureU
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -111,8 +95,9 @@ public class ConvertClosureToMethodIntention extends Intention {
|
||||
LOG.assertTrue(initializer != null);
|
||||
final PsiType type = initializer.getType();
|
||||
LOG.assertTrue(type instanceof GrClosureType);
|
||||
final GrSignature signature = ((GrClosureType)type).getSignature();
|
||||
final List<MethodSignature> signatures = GrClosureSignatureUtil.generateAllMethodSignaturesBySignature(fieldName, signature);
|
||||
final List<MethodSignature> signatures = GrClosureSignatureUtil.generateAllMethodSignaturesBySignature(
|
||||
fieldName, ((GrClosureType)type).getSignatures()
|
||||
);
|
||||
for (MethodSignature s : signatures) {
|
||||
final PsiMethod method = MethodSignatureUtil.findMethodBySignature(containingClass, s, true);
|
||||
if (method != null) {
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
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.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParameterListOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
@@ -211,7 +211,7 @@ public class ConvertParameterToMapEntryIntention extends Intention {
|
||||
}
|
||||
}
|
||||
if (refExpr == null) continue;
|
||||
final GrClosureSignature signature = generateSignature(owner, refExpr);
|
||||
final GrSignature signature = generateSignature(owner, refExpr);
|
||||
if (signature == null) continue;
|
||||
GrCall call;
|
||||
if (isExplicitGetterCall) {
|
||||
@@ -321,7 +321,7 @@ public class ConvertParameterToMapEntryIntention extends Intention {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static GrClosureSignature generateSignature(GrParameterListOwner owner, GrReferenceExpression refExpr) {
|
||||
private static GrSignature generateSignature(GrParameterListOwner owner, GrReferenceExpression refExpr) {
|
||||
if (owner instanceof PsiMethod) {
|
||||
final GroovyResolveResult resolveResult = refExpr.advancedResolve();
|
||||
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
|
||||
+9
-15
@@ -19,8 +19,7 @@ import org.jetbrains.plugins.groovy.lang.documentation.TypePresentation;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -157,12 +156,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
|
||||
private static void addSignatureVariant(@NotNull final List<Object> elementToShow, @NotNull GrClosureType type) {
|
||||
type.getSignature().accept(new GrRecursiveSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
elementToShow.add(signature);
|
||||
}
|
||||
});
|
||||
elementToShow.addAll(type.getSignatures());
|
||||
}
|
||||
|
||||
private static void filterOutReflectedMethods(List toShow) {
|
||||
@@ -231,8 +225,8 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
if (argTypes == null) continue;
|
||||
}
|
||||
else if (objects[i] instanceof GrClosureSignature) {
|
||||
final GrClosureSignature signature = (GrClosureSignature)objects[i];
|
||||
else if (objects[i] instanceof GrSignature) {
|
||||
final GrSignature signature = (GrSignature)objects[i];
|
||||
argTypes = PsiUtil.getArgumentTypes(place, false);
|
||||
parameterTypes = PsiType.createArray(signature.getParameterCount());
|
||||
int j = 0;
|
||||
@@ -304,8 +298,8 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (o instanceof GrClosureSignature) {
|
||||
if (!((GrClosureSignature)o).isValid()) {
|
||||
else if (o instanceof GrSignature) {
|
||||
if (!((GrSignature)o).isValid()) {
|
||||
context.setUIComponentEnabled(false);
|
||||
return;
|
||||
}
|
||||
@@ -377,8 +371,8 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
} else if (element instanceof PsiClass) {
|
||||
buffer.append("no parameters");
|
||||
}
|
||||
else if (element instanceof GrClosureSignature) {
|
||||
GrClosureParameter[] parameters = ((GrClosureSignature)element).getParameters();
|
||||
else if (element instanceof GrSignature) {
|
||||
GrClosureParameter[] parameters = ((GrSignature)element).getParameters();
|
||||
if (parameters.length > 0) {
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (i > 0) buffer.append(", ");
|
||||
@@ -396,7 +390,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
int endOffset = buffer.length();
|
||||
|
||||
if (context.isUIComponentEnabled() &&
|
||||
(i == currentParameter || (i == parameters.length - 1 && ((GrClosureSignature)element).isVarargs() && currentParameter >= parameters.length))) {
|
||||
(i == currentParameter || (i == parameters.length - 1 && ((GrSignature)element).isVarargs() && currentParameter >= parameters.length))) {
|
||||
highlightStartOffset = startOffset;
|
||||
highlightEndOffset = endOffset;
|
||||
}
|
||||
|
||||
+3
-17
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.changeSignature;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -27,7 +13,7 @@ import com.intellij.refactoring.changeSignature.PossiblyIncorrectUsage;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
|
||||
@@ -73,7 +59,7 @@ public class GrMethodCallUsageInfo extends UsageInfo implements PossiblyIncorrec
|
||||
}
|
||||
}
|
||||
}
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, mySubstitutor);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(method, mySubstitutor);
|
||||
myToChangeArguments = isToChangeArguments;
|
||||
myToCatchExceptions = isToCatchExceptions;
|
||||
final GrCall call = GroovyRefactoringUtil.getCallExpressionByMethodReference(element);
|
||||
|
||||
+13
-34
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.changeSignature;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
@@ -20,8 +6,6 @@ import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.plugins.groovy.lang.documentation.GroovyPresentationUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
@@ -75,26 +59,21 @@ public class GrMethodConflictUtil {
|
||||
}
|
||||
if (!(returnType instanceof GrClosureType)) return;
|
||||
|
||||
final GrSignature signature = ((GrClosureType)returnType).getSignature();
|
||||
signature.accept(new GrRecursiveSignatureVisitor() {
|
||||
@Override
|
||||
public void visitClosureSignature(GrClosureSignature signature) {
|
||||
NextSignature:
|
||||
for (MethodSignature prototypeSignature : prototypeSignatures) {
|
||||
final GrClosureParameter[] params = signature.getParameters();
|
||||
final PsiType[] types = prototypeSignature.getParameterTypes();
|
||||
if (types.length != params.length) continue;
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
|
||||
continue NextSignature;
|
||||
}
|
||||
final List<GrSignature> signatures = ((GrClosureType)returnType).getSignatures();
|
||||
for (GrSignature signature : signatures) {
|
||||
NextSignature:
|
||||
for (MethodSignature prototypeSignature : prototypeSignatures) {
|
||||
final GrClosureParameter[] params = signature.getParameters();
|
||||
final PsiType[] types = prototypeSignature.getParameterTypes();
|
||||
if (types.length != params.length) continue;
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
|
||||
continue NextSignature;
|
||||
}
|
||||
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
|
||||
}
|
||||
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkForMethodSignatureOverload(PsiClass clazz,
|
||||
|
||||
+3
-17
@@ -1,24 +1,10 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.convertToJava;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
@@ -89,7 +75,7 @@ public class AnonymousFromMapGenerator {
|
||||
|
||||
final GrParameter[] parameters = actual.toArray(GrParameter.EMPTY_ARRAY);
|
||||
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(parameters, clReturnType);
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature(parameters, clReturnType);
|
||||
final GrMethod pattern = factory.createMethodFromSignature(name, signature);
|
||||
|
||||
PsiMethod found = null;
|
||||
|
||||
+3
-17
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.convertToJava;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -23,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
@@ -49,7 +35,7 @@ class ArgumentListGenerator {
|
||||
myExpressionGenerator = new ExpressionGenerator(builder, context);
|
||||
}
|
||||
|
||||
public void generate(@Nullable GrClosureSignature signature,
|
||||
public void generate(@Nullable GrSignature signature,
|
||||
@NotNull GrExpression[] exprs,
|
||||
@NotNull GrNamedArgument[] namedArgs,
|
||||
@NotNull GrClosableBlock[] clArgs,
|
||||
|
||||
+3
-18
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.convertToJava;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
@@ -21,7 +7,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightMethodBuilder;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import java.util.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection;
|
||||
@@ -31,7 +16,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
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.auxiliary.modifiers.annotation.GrAnnotationMemberValue;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
@@ -76,7 +61,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator {
|
||||
final GrArgumentList argumentList = constant.getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final GroovyResolveResult resolveResult = constant.advancedResolve();
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(resolveResult);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(resolveResult);
|
||||
new ArgumentListGenerator(builder, context.extend()).generate(
|
||||
signature,
|
||||
argumentList.getExpressionArguments(),
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ 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.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
@@ -213,7 +213,7 @@ public class ExpressionGenerator extends Generator {
|
||||
final GrArgumentList argList = newExpression.getArgumentList();
|
||||
if (argList != null) {
|
||||
|
||||
GrClosureSignature signature = null;
|
||||
GrSignature signature = null;
|
||||
|
||||
final GroovyResolveResult resolveResult = newExpression.advancedResolve();
|
||||
final PsiElement constructor = resolveResult.getElement();
|
||||
@@ -1342,7 +1342,7 @@ public class ExpressionGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
builder.append(method.getName());
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, substitutor);
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature(method, substitutor);
|
||||
new ArgumentListGenerator(builder, this.context).generate(signature, exprs, namedArgs, closures, context);
|
||||
}
|
||||
|
||||
|
||||
+3
-17
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.convertToJava;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
@@ -20,7 +6,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
|
||||
@@ -122,7 +108,7 @@ public class TypeProvider {
|
||||
}
|
||||
|
||||
if (!paramInds.isEmpty()) {
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, PsiSubstitutor.EMPTY);
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature(method, PsiSubstitutor.EMPTY);
|
||||
MethodReferencesSearch.search(method, true).forEach(psiReference -> {
|
||||
final PsiElement element = psiReference.getElement();
|
||||
final PsiManager manager = element.getManager();
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
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.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
@@ -430,7 +430,7 @@ public class GroovyInlineMethodUtil {
|
||||
Project project = call.getProject();
|
||||
|
||||
final GroovyResolveResult resolveResult = call.advancedResolve();
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, resolveResult.getSubstitutor());
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(method, resolveResult.getSubstitutor());
|
||||
|
||||
if (signature == null) {
|
||||
return;
|
||||
@@ -456,7 +456,7 @@ public class GroovyInlineMethodUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static GrExpression inferArg(GrClosureSignature signature,
|
||||
private static GrExpression inferArg(GrSignature signature,
|
||||
GrParameter[] parameters,
|
||||
GrParameter parameter,
|
||||
GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo,
|
||||
|
||||
+3
-3
@@ -35,7 +35,7 @@ import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
|
||||
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.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
@@ -386,7 +386,7 @@ public class GrIntroduceClosureParameterProcessor extends BaseRefactoringProcess
|
||||
|
||||
final GrExpression anchor = getAnchorForArgument(oldArgs, toReplaceIn.isVarArgs(), toReplaceIn.getParameterList());
|
||||
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(callExpression);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(callExpression);
|
||||
if (signature == null) signature = GrClosureSignatureUtil.createSignature(toReplaceIn);
|
||||
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs = GrClosureSignatureUtil
|
||||
@@ -567,7 +567,7 @@ public class GrIntroduceClosureParameterProcessor extends BaseRefactoringProcess
|
||||
final GroovyResolveResult resolveResult = methodCall.advancedResolve();
|
||||
final PsiElement resolved = resolveResult.getElement();
|
||||
LOG.assertTrue(resolved instanceof PsiMethod);
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor());
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor());
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
|
||||
LOG.assertTrue(argInfos != null);
|
||||
settings.parametersToRemove().forEach(value -> {
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParameterListOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
@@ -212,7 +212,7 @@ public class GroovyIntroduceParameterUtil {
|
||||
final GroovyResolveResult resolveResult = methodCall.advancedResolve();
|
||||
final PsiElement resolved = resolveResult.getElement();
|
||||
LOG.assertTrue(resolved instanceof PsiMethod);
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor());
|
||||
final GrSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor());
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
|
||||
LOG.assertTrue(argInfos != null);
|
||||
settings.parametersToRemove().forEach(value -> {
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParameterListOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
@@ -88,7 +88,7 @@ public class GroovyIntroduceParameterMethodUsagesProcessor implements IntroduceP
|
||||
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(argList, PsiMethod.class);
|
||||
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(callExpression);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(callExpression);
|
||||
if (signature == null) signature = GrClosureSignatureUtil.createSignature(data.getMethodToSearchFor(), PsiSubstitutor.EMPTY);
|
||||
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs = GrClosureSignatureUtil
|
||||
|
||||
+4
-4
@@ -13,14 +13,13 @@ import com.intellij.refactoring.IntroduceParameterRefactoring;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import java.util.HashMap;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
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.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
@@ -33,6 +32,7 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -57,7 +57,7 @@ public class OldReferencesResolver {
|
||||
private final PsiElement myParameterInitializer;
|
||||
private final PsiManager myManager;
|
||||
private final PsiParameter[] myParameters;
|
||||
private final GrClosureSignature mySignature;
|
||||
private final GrSignature mySignature;
|
||||
|
||||
private final Set<PsiParameter> myParamsToNotInline = new HashSet<>();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class OldReferencesResolver {
|
||||
PsiElement toReplaceIn,
|
||||
int replaceFieldsWithGetters,
|
||||
PsiElement parameterInitializer,
|
||||
final GrClosureSignature signature,
|
||||
final GrSignature signature,
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs, PsiParameter[] parameters) throws IncorrectOperationException {
|
||||
myContext = context;
|
||||
myExpr = expr;
|
||||
|
||||
+7
-19
@@ -1,31 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.safeDelete;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.refactoring.safeDelete.JavaSafeDeleteDelegate;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodReference;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
|
||||
|
||||
@@ -52,7 +40,7 @@ public class JavaSafeDeleteDelegateForGroovy implements JavaSafeDeleteDelegate {
|
||||
call = (GrCall)element.getParent();
|
||||
}
|
||||
if (call != null) {
|
||||
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(call);
|
||||
GrSignature signature = GrClosureSignatureUtil.createSignature(call);
|
||||
if (signature == null) return;//todo ???
|
||||
GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, call);
|
||||
if (argInfos == null) return; //todo???
|
||||
|
||||
Reference in New Issue
Block a user