From f4c1722a46c3d0c51727df2566afb581644c00e6 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 26 Nov 2012 21:01:27 +0400 Subject: [PATCH] Extracted method creating copy of type parameters (to reuse in SignaturesPropagationData). --- .../AlternativeMethodSignatureData.java | 15 +----- .../java/kotlinSignature/SignaturesUtil.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesUtil.java diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/AlternativeMethodSignatureData.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/AlternativeMethodSignatureData.java index e949dcfe5d9..e56f8876f81 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/AlternativeMethodSignatureData.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/AlternativeMethodSignatureData.java @@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,8 +48,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD private JetType altReturnType; private List altTypeParameters; - private final Map originalToAltTypeParameters = - new HashMap(); + private Map originalToAltTypeParameters; public AlternativeMethodSignatureData( @NotNull PsiMethodWrapper method, @@ -70,16 +68,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD Project project = method.getPsiMethod().getProject(); altFunDeclaration = JetPsiFactory.createFunction(project, signature); - for (TypeParameterDescriptor typeParameter : methodTypeParameters) { - originalToAltTypeParameters.put(typeParameter, - TypeParameterDescriptorImpl.createForFurtherModification( - typeParameter.getContainingDeclaration(), - typeParameter.getAnnotations(), - typeParameter.isReified(), - typeParameter.getVariance(), - typeParameter.getName(), - typeParameter.getIndex())); - } + originalToAltTypeParameters = SignaturesUtil.recreateTypeParametersAndReturnMapping(methodTypeParameters); try { checkForSyntaxErrors(altFunDeclaration); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesUtil.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesUtil.java new file mode 100644 index 00000000000..4b9c109bd59 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesUtil.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2012 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.jet.lang.resolve.java.kotlinSignature; + +import com.google.common.collect.Maps; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl; + +import java.util.List; +import java.util.Map; + +public class SignaturesUtil { + public static Map recreateTypeParametersAndReturnMapping( + @NotNull List originalParameters + ) { + Map result = Maps.newHashMap(); + for (TypeParameterDescriptor typeParameter : originalParameters) { + result.put(typeParameter, + TypeParameterDescriptorImpl.createForFurtherModification( + typeParameter.getContainingDeclaration(), + typeParameter.getAnnotations(), + typeParameter.isReified(), + typeParameter.getVariance(), + typeParameter.getName(), + typeParameter.getIndex())); + } + return result; + } + + private SignaturesUtil() { + } +}