Extract interface out of JavaSignatureFormatter

This commit is contained in:
Alexander Udalov
2013-08-19 18:06:00 +04:00
parent f6b43bb7b2
commit 214f290de7
5 changed files with 51 additions and 17 deletions
@@ -109,7 +109,7 @@ public final class DescriptorResolverUtils {
if (member instanceof JavaField && ((JavaField) member).isEnumEntry()) return true;
if (!(member instanceof JavaMethod)) return false;
String signature = JavaSignatureFormatter.formatMethod((JavaMethod) member);
String signature = JavaSignatureFormatter.getInstance().formatMethod((JavaMethod) member);
return "values()".equals(signature) ||
"valueOf(java.lang.String)".equals(signature);
@@ -124,7 +124,7 @@ public final class DescriptorResolverUtils {
}
public static boolean isObjectMethod(@NotNull JavaMethod method) {
String signature = JavaSignatureFormatter.formatMethod(method);
String signature = JavaSignatureFormatter.getInstance().formatMethod(method);
return "hashCode()".equals(signature) ||
"equals(java.lang.Object)".equals(signature) ||
"toString()".equals(signature);
@@ -57,7 +57,7 @@ public class JavaToKotlinMethodMap {
Set<ClassDescriptor> allSuperClasses = DescriptorUtils.getAllSuperClasses(containingClass);
String serializedMethod = JavaSignatureFormatter.formatMethod(javaMethod);
String serializedMethod = JavaSignatureFormatter.getInstance().formatMethod(javaMethod);
for (ClassData classData : classDatas) {
String expectedSerializedFunction = classData.method2Function.get(serializedMethod);
if (expectedSerializedFunction == null) continue;
@@ -86,7 +86,7 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
+ "super class = " + superFunction.getContainingDeclaration() + "\n"
+ "sub function = " + function + "\n"
+ "sub class = " + function.getContainingDeclaration() + "\n"
+ "sub method = " + JavaSignatureFormatter.getExternalName(method) + "\n"
+ "sub method = " + JavaSignatureFormatter.getInstance().getExternalName(method) + "\n"
+ "@KotlinSignature = " + SignaturesUtil.getKotlinSignature(annotationResolver, method));
}
}
@@ -16,31 +16,26 @@
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() {
public abstract class JavaSignatureFormatter {
public static JavaSignatureFormatter getInstance() {
// TODO: ServiceLoader.load
return new JavaSignatureFormatterImpl();
}
/**
* @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);
}
@NotNull
public abstract String formatMethod(@NotNull JavaMethod method);
/**
* @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&lt;? extends java.lang.annotation.Annotation&gt;)"}
*/
public static String getExternalName(@NotNull JavaMethod method) {
return PsiFormatUtil.getExternalName(method.getPsi());
}
@NotNull
public abstract String getExternalName(@NotNull JavaMethod method);
}
@@ -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;
}
}