Commit 3079b60a authored by Daniil Ovchinnikov's avatar Daniil Ovchinnikov
Browse files

[groovy] get rid of GrMultiSignature and visitors, use GrSignature and List<GrSignature> instead

parent 05a20f1f
Showing with 242 additions and 620 deletions
+242 -620
......@@ -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
);
......
......@@ -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;
}
......
/*
* 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;
}
......
/*
* 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) {
......
/*
* 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) {
......
/*
* 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();
}
// 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();
}
/*
* 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);
}
}
}
/*
* 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();
@NotNull
PsiSubstitutor getSubstitutor();
@NotNull
GrClosureParameter[] getParameters();
int getParameterCount();
boolean isVarargs();
@Nullable
GrSignature curry(@NotNull PsiType[] args, int position, @NotNull PsiElement context);
PsiType getReturnType();
void accept(@NotNull GrSignatureVisitor visitor);
boolean isCurried();
}
/*
* 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);
}
}
/*
* 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)) {
......
......@@ -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
......
......@@ -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) {
......
/*
* 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);
}
}
/*
* 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);
}
}
/*
* 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);
}
}
// 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);
}
}
/*
* 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);
}
}
// 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)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment