Extract interface out of JavaSignatureFormatter
This commit is contained in:
+2
-2
@@ -109,7 +109,7 @@ public final class DescriptorResolverUtils {
|
|||||||
if (member instanceof JavaField && ((JavaField) member).isEnumEntry()) return true;
|
if (member instanceof JavaField && ((JavaField) member).isEnumEntry()) return true;
|
||||||
|
|
||||||
if (!(member instanceof JavaMethod)) return false;
|
if (!(member instanceof JavaMethod)) return false;
|
||||||
String signature = JavaSignatureFormatter.formatMethod((JavaMethod) member);
|
String signature = JavaSignatureFormatter.getInstance().formatMethod((JavaMethod) member);
|
||||||
|
|
||||||
return "values()".equals(signature) ||
|
return "values()".equals(signature) ||
|
||||||
"valueOf(java.lang.String)".equals(signature);
|
"valueOf(java.lang.String)".equals(signature);
|
||||||
@@ -124,7 +124,7 @@ public final class DescriptorResolverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isObjectMethod(@NotNull JavaMethod method) {
|
public static boolean isObjectMethod(@NotNull JavaMethod method) {
|
||||||
String signature = JavaSignatureFormatter.formatMethod(method);
|
String signature = JavaSignatureFormatter.getInstance().formatMethod(method);
|
||||||
return "hashCode()".equals(signature) ||
|
return "hashCode()".equals(signature) ||
|
||||||
"equals(java.lang.Object)".equals(signature) ||
|
"equals(java.lang.Object)".equals(signature) ||
|
||||||
"toString()".equals(signature);
|
"toString()".equals(signature);
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class JavaToKotlinMethodMap {
|
|||||||
|
|
||||||
Set<ClassDescriptor> allSuperClasses = DescriptorUtils.getAllSuperClasses(containingClass);
|
Set<ClassDescriptor> allSuperClasses = DescriptorUtils.getAllSuperClasses(containingClass);
|
||||||
|
|
||||||
String serializedMethod = JavaSignatureFormatter.formatMethod(javaMethod);
|
String serializedMethod = JavaSignatureFormatter.getInstance().formatMethod(javaMethod);
|
||||||
for (ClassData classData : classDatas) {
|
for (ClassData classData : classDatas) {
|
||||||
String expectedSerializedFunction = classData.method2Function.get(serializedMethod);
|
String expectedSerializedFunction = classData.method2Function.get(serializedMethod);
|
||||||
if (expectedSerializedFunction == null) continue;
|
if (expectedSerializedFunction == null) continue;
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
|
|||||||
+ "super class = " + superFunction.getContainingDeclaration() + "\n"
|
+ "super class = " + superFunction.getContainingDeclaration() + "\n"
|
||||||
+ "sub function = " + function + "\n"
|
+ "sub function = " + function + "\n"
|
||||||
+ "sub class = " + function.getContainingDeclaration() + "\n"
|
+ "sub class = " + function.getContainingDeclaration() + "\n"
|
||||||
+ "sub method = " + JavaSignatureFormatter.getExternalName(method) + "\n"
|
+ "sub method = " + JavaSignatureFormatter.getInstance().getExternalName(method) + "\n"
|
||||||
+ "@KotlinSignature = " + SignaturesUtil.getKotlinSignature(annotationResolver, method));
|
+ "@KotlinSignature = " + SignaturesUtil.getKotlinSignature(annotationResolver, method));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-13
@@ -16,31 +16,26 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java.structure;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import static com.intellij.psi.util.PsiFormatUtilBase.*;
|
public abstract class JavaSignatureFormatter {
|
||||||
|
public static JavaSignatureFormatter getInstance() {
|
||||||
public class JavaSignatureFormatter {
|
// TODO: ServiceLoader.load
|
||||||
private JavaSignatureFormatter() {
|
return new JavaSignatureFormatterImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a formatted signature of a method, showing method name and fully qualified names of its parameter types, e.g.:
|
* @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)"}
|
* {@code "foo(double, java.lang.String)"}
|
||||||
*/
|
*/
|
||||||
public static String formatMethod(@NotNull JavaMethod method) {
|
@NotNull
|
||||||
return PsiFormatUtil.formatMethod(method.getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
|
public abstract String formatMethod(@NotNull JavaMethod method);
|
||||||
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
|
* @return a formatted signature of a method, showing method's containing class, return type and parameter types, all names are fully
|
||||||
* qualified, e.g.:
|
* qualified, e.g.:
|
||||||
* {@code "java.lang.Class boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>)"}
|
* {@code "java.lang.Class boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>)"}
|
||||||
*/
|
*/
|
||||||
public static String getExternalName(@NotNull JavaMethod method) {
|
@NotNull
|
||||||
return PsiFormatUtil.getExternalName(method.getPsi());
|
public abstract String getExternalName(@NotNull JavaMethod method);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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 JavaSignatureFormatterImpl extends JavaSignatureFormatter {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String formatMethod(@NotNull JavaMethod method) {
|
||||||
|
return PsiFormatUtil.formatMethod(method.getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
|
||||||
|
SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getExternalName(@NotNull JavaMethod method) {
|
||||||
|
String result = PsiFormatUtil.getExternalName(method.getPsi());
|
||||||
|
return result == null ? "null" : result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user