Added storing alternative signature reading errors in class resolve data.
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class AlternativeSignatureMismatchException extends Exception {
|
||||||
|
public AlternativeSignatureMismatchException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
-12
@@ -21,7 +21,9 @@ import com.google.common.collect.Maps;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
|
import com.intellij.util.Function;
|
||||||
import jet.typeinfo.TypeInfoVariance;
|
import jet.typeinfo.TypeInfoVariance;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -145,6 +147,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
final boolean staticMembers;
|
final boolean staticMembers;
|
||||||
final boolean kotlin;
|
final boolean kotlin;
|
||||||
final ClassOrNamespaceDescriptor classOrNamespaceDescriptor;
|
final ClassOrNamespaceDescriptor classOrNamespaceDescriptor;
|
||||||
|
private List<String> alternativeSignatureErrors;
|
||||||
|
|
||||||
protected ResolverScopeData(@Nullable PsiClass psiClass, @Nullable PsiPackage psiPackage, @NotNull FqName fqName, boolean staticMembers, @NotNull ClassOrNamespaceDescriptor descriptor) {
|
protected ResolverScopeData(@Nullable PsiClass psiClass, @Nullable PsiPackage psiPackage, @NotNull FqName fqName, boolean staticMembers, @NotNull ClassOrNamespaceDescriptor descriptor) {
|
||||||
checkPsiClassIsNotJet(psiClass);
|
checkPsiClassIsNotJet(psiClass);
|
||||||
@@ -195,6 +198,13 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
|
|
||||||
private Map<Name, NamedMembers> namedMembersMap;
|
private Map<Name, NamedMembers> namedMembersMap;
|
||||||
|
|
||||||
|
public void addAlternativeSignatureError(@NotNull String errorMessage) {
|
||||||
|
if (alternativeSignatureErrors == null) {
|
||||||
|
alternativeSignatureErrors = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
alternativeSignatureErrors.add(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract List<TypeParameterDescriptor> getTypeParameters();
|
public abstract List<TypeParameterDescriptor> getTypeParameters();
|
||||||
}
|
}
|
||||||
@@ -1621,19 +1631,42 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
// TODO consider better place for this check
|
// TODO consider better place for this check
|
||||||
String signature = method.getSignatureAnnotation().signature();
|
String signature = method.getSignatureAnnotation().signature();
|
||||||
if (!signature.isEmpty()) {
|
if (!signature.isEmpty()) {
|
||||||
JetNamedFunction altFunDeclaration = JetPsiFactory.createFunction(project, signature);
|
try {
|
||||||
List<PsiErrorElement> syntaxErrors = AnalyzingUtils.getSyntaxErrorRanges(altFunDeclaration);
|
JetNamedFunction altFunDeclaration = JetPsiFactory.createFunction(project, signature);
|
||||||
if (!syntaxErrors.isEmpty()) {
|
List<PsiErrorElement> syntaxErrors = AnalyzingUtils.getSyntaxErrorRanges(altFunDeclaration);
|
||||||
// TODO report syntax error as diagnostic when method is used
|
if (!syntaxErrors.isEmpty()) {
|
||||||
}
|
String textSignature = String.format("%s(%s)", method.getName(),
|
||||||
else {
|
StringUtil.join(method.getPsiMethod().getSignature(PsiSubstitutor.EMPTY).getParameterTypes(),
|
||||||
valueParameterDescriptors = AlternativeSignatureParsing
|
new Function<PsiType, String>() {
|
||||||
.computeAlternativeValueParameters(valueParameterDescriptors, altFunDeclaration);
|
@Override
|
||||||
JetTypeReference returnTypeRef = altFunDeclaration.getReturnTypeRef();
|
public String fun(PsiType psiType) {
|
||||||
if (returnTypeRef != null) {
|
return psiType.getPresentableText();
|
||||||
returnType = AlternativeSignatureParsing.computeAlternativeTypeFromAnnotation(returnTypeRef.getTypeElement(), returnType);
|
}
|
||||||
|
}, ", "));
|
||||||
|
int errorOffset = syntaxErrors.get(0).getTextOffset();
|
||||||
|
String syntaxErrorDescription = syntaxErrors.get(0).getErrorDescription();
|
||||||
|
|
||||||
|
String errorText = syntaxErrors.size() == 1
|
||||||
|
? String.format("Alternative signature for %s has syntax error at %d: %s", textSignature,
|
||||||
|
errorOffset, syntaxErrorDescription)
|
||||||
|
: String.format("Alternative signature for %s has %d syntax errors, first is at %d: %s", textSignature,
|
||||||
|
syntaxErrors.size(), errorOffset, syntaxErrorDescription);
|
||||||
|
throw new AlternativeSignatureMismatchException(errorText);
|
||||||
}
|
}
|
||||||
methodTypeParameters = AlternativeSignatureParsing.computeAlternativeTypeParameters(methodTypeParameters, altFunDeclaration);
|
else {
|
||||||
|
valueParameterDescriptors = AlternativeSignatureParsing
|
||||||
|
.computeAlternativeValueParameters(valueParameterDescriptors, altFunDeclaration);
|
||||||
|
JetTypeReference returnTypeRef = altFunDeclaration.getReturnTypeRef();
|
||||||
|
if (returnTypeRef != null) {
|
||||||
|
returnType = AlternativeSignatureParsing.computeAlternativeTypeFromAnnotation(returnTypeRef.getTypeElement(),
|
||||||
|
returnType);
|
||||||
|
}
|
||||||
|
methodTypeParameters = AlternativeSignatureParsing.computeAlternativeTypeParameters(methodTypeParameters,
|
||||||
|
altFunDeclaration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AlternativeSignatureMismatchException e) {
|
||||||
|
scopeData.addAlternativeSignatureError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user