Create JavaSignatureFormatter, a wrapper over PsiFormatUtil
This commit is contained in:
+4
-12
@@ -18,24 +18,18 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.impl.compiled.ClsClassImpl;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.FakeOverrideVisibilityResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.psi.util.PsiFormatUtilBase.*;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumClassObject;
|
||||
|
||||
public final class DescriptorResolverUtils {
|
||||
@@ -124,8 +118,7 @@ public final class DescriptorResolverUtils {
|
||||
if (member instanceof JavaField && ((JavaField) member).isEnumEntry()) return true;
|
||||
|
||||
if (!(member instanceof JavaMethod)) return false;
|
||||
String signature = PsiFormatUtil.formatMethod(((JavaMethod) member).getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
|
||||
SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
|
||||
String signature = JavaSignatureFormatter.formatMethod((JavaMethod) member);
|
||||
|
||||
return "values()".equals(signature) ||
|
||||
"valueOf(java.lang.String)".equals(signature);
|
||||
@@ -140,9 +133,8 @@ public final class DescriptorResolverUtils {
|
||||
}
|
||||
|
||||
public static boolean isObjectMethod(@NotNull JavaMethod method) {
|
||||
String formattedMethod = PsiFormatUtil.formatMethod(
|
||||
method.getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS, SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
|
||||
return OBJECT_METHODS.contains(formattedMethod);
|
||||
String signature = JavaSignatureFormatter.formatMethod(method);
|
||||
return OBJECT_METHODS.contains(signature);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-12
@@ -21,14 +21,12 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaSignatureFormatter;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -39,8 +37,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.psi.util.PsiFormatUtilBase.*;
|
||||
|
||||
public class JavaToKotlinMethodMap {
|
||||
public static final JavaToKotlinMethodMap INSTANCE = new JavaToKotlinMethodMap();
|
||||
|
||||
@@ -61,7 +57,7 @@ public class JavaToKotlinMethodMap {
|
||||
|
||||
Set<ClassDescriptor> allSuperClasses = DescriptorUtils.getAllSuperClasses(containingClass);
|
||||
|
||||
String serializedMethod = serializePsiMethod(javaMethod.getPsi());
|
||||
String serializedMethod = JavaSignatureFormatter.formatMethod(javaMethod);
|
||||
for (ClassData classData : classDatas) {
|
||||
String expectedSerializedFunction = classData.method2Function.get(serializedMethod);
|
||||
if (expectedSerializedFunction == null) continue;
|
||||
@@ -81,12 +77,6 @@ public class JavaToKotlinMethodMap {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String serializePsiMethod(@NotNull PsiMethod psiMethod) {
|
||||
return PsiFormatUtil.formatMethod(
|
||||
psiMethod, PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS, SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String serializeFunction(@NotNull FunctionDescriptor fun) {
|
||||
return DescriptorRenderer.COMPACT.render(fun);
|
||||
|
||||
+2
-2
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -36,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.scope.NamedMembers;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaSignatureFormatter;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -229,7 +229,7 @@ public final class JavaFunctionResolver {
|
||||
+ "super class = " + superFunction.getContainingDeclaration() + "\n"
|
||||
+ "sub function = " + functionDescriptor + "\n"
|
||||
+ "sub class = " + functionDescriptor.getContainingDeclaration() + "\n"
|
||||
+ "sub method = " + PsiFormatUtil.getExternalName(method.getPsi()) + "\n"
|
||||
+ "sub method = " + JavaSignatureFormatter.getExternalName(method) + "\n"
|
||||
+ "@KotlinSignature = " + SignaturesUtil.getKotlinSignature(method));
|
||||
}
|
||||
}
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure;
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.psi.util.PsiFormatUtilBase.*;
|
||||
|
||||
public class JavaSignatureFormatter {
|
||||
private JavaSignatureFormatter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a formatted signature of a method, showing method name and fully qualified names of its parameter types, e.g.:
|
||||
* {@code "foo(double, java.lang.String)"}
|
||||
*/
|
||||
public static String formatMethod(@NotNull JavaMethod method) {
|
||||
return PsiFormatUtil.formatMethod(method.getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
|
||||
SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a formatted signature of a method, showing method's containing class, return type and parameter types, all names are fully
|
||||
* qualified, e.g.:
|
||||
* {@code "java.lang.Class boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>)"}
|
||||
*/
|
||||
public static String getExternalName(@NotNull JavaMethod method) {
|
||||
return PsiFormatUtil.getExternalName(method.getPsi());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user