use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class LambdaHighlightingUtil method checkInterfaceFunctional.
@Nullable
public static String checkInterfaceFunctional(PsiType functionalInterfaceType) {
if (functionalInterfaceType instanceof PsiIntersectionType) {
final Set<MethodSignature> signatures = new HashSet<>();
for (PsiType type : ((PsiIntersectionType) functionalInterfaceType).getConjuncts()) {
if (checkInterfaceFunctional(type) == null) {
final MethodSignature signature = LambdaUtil.getFunction(PsiUtil.resolveClassInType(type));
LOG.assertTrue(signature != null, type.getCanonicalText());
signatures.add(signature);
}
}
if (signatures.size() > 1) {
return "Multiple non-overriding abstract methods found in " + functionalInterfaceType.getPresentableText();
}
return null;
}
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiClass aClass = resolveResult.getElement();
if (aClass != null) {
//should be logged as cyclic inference
if (aClass instanceof PsiTypeParameter)
return null;
MethodSignature functionalMethod = LambdaUtil.getFunction(aClass);
if (functionalMethod != null && functionalMethod.getTypeParameters().length > 0)
return "Target method is generic";
if (checkReturnTypeApplicable(resolveResult, aClass)) {
return "No instance of type " + functionalInterfaceType.getPresentableText() + " exists so that lambda expression can be type-checked";
}
return checkInterfaceFunctional(aClass);
}
return functionalInterfaceType.getPresentableText() + " is not a functional interface";
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class PsiNameValuePairImpl method getReference.
@Override
public PsiReference getReference() {
return new PsiReference() {
@Nullable
private PsiClass getReferencedClass() {
LOG.assertTrue(getParent() instanceof PsiAnnotationParameterList && getParent().getParent() instanceof PsiAnnotation);
PsiAnnotation annotation = (PsiAnnotation) getParent().getParent();
PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
if (nameRef == null)
return null;
PsiElement target = nameRef.resolve();
return target instanceof PsiClass ? (PsiClass) target : null;
}
@Override
public PsiElement getElement() {
PsiIdentifier nameIdentifier = getNameIdentifier();
if (nameIdentifier != null) {
return nameIdentifier;
}
return PsiNameValuePairImpl.this;
}
@Override
public TextRange getRangeInElement() {
PsiIdentifier id = getNameIdentifier();
if (id != null) {
return new TextRange(0, id.getTextLength());
}
return TextRange.EMPTY_RANGE;
}
@Override
public PsiElement resolve() {
PsiClass refClass = getReferencedClass();
if (refClass == null)
return null;
String name = getName();
if (name == null)
name = PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME;
MethodSignature signature = MethodSignatureUtil.createMethodSignature(name, PsiType.EMPTY_ARRAY, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
return MethodSignatureUtil.findMethodBySignature(refClass, signature, false);
}
@Override
@NotNull
public String getCanonicalText() {
String name = getName();
return name != null ? name : PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME;
}
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
PsiIdentifier nameIdentifier = getNameIdentifier();
if (nameIdentifier != null) {
PsiImplUtil.setName(nameIdentifier, newElementName);
} else if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(getNode().getFirstChildNode().getElementType())) {
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
nameIdentifier = factory.createIdentifier(newElementName);
addBefore(nameIdentifier, SourceTreeToPsiMap.treeElementToPsi(getNode().getFirstChildNode()));
}
return PsiNameValuePairImpl.this;
}
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
throw new IncorrectOperationException("Not implemented");
}
@Override
public boolean isReferenceTo(PsiElement element) {
return element instanceof PsiMethod && element.equals(resolve());
}
@Override
@NotNull
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
@Override
public boolean isSoft() {
return false;
}
};
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class StubGenerator method collectMethods.
@Override
public Collection<PsiMethod> collectMethods(PsiClass typeDefinition) {
List<PsiMethod> methods = new ArrayList<>();
for (PsiMethod method : typeDefinition.getMethods()) {
if (method instanceof DelegatedMethod) {
PsiMethod prototype = ((DelegatedMethod) method).getPrototype();
PsiClass aClass = prototype.getContainingClass();
if (prototype.hasModifierProperty(PsiModifier.FINAL) && aClass != null && typeDefinition.isInheritor(aClass, true)) {
//skip final super methods
continue;
}
}
methods.add(method);
}
boolean isClass = !typeDefinition.isInterface() && !typeDefinition.isAnnotationType() && !typeDefinition.isEnum() && !(typeDefinition instanceof GroovyScriptClass);
if (isClass) {
final Collection<MethodSignature> toOverride = OverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition);
for (MethodSignature signature : toOverride) {
if (!(signature instanceof MethodSignatureBackedByPsiMethod))
continue;
final PsiMethod method = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
final PsiClass baseClass = method.getContainingClass();
if (baseClass == null)
continue;
final String qname = baseClass.getQualifiedName();
if (GroovyCommonClassNames.GROOVY_OBJECT.equals(qname) || GroovyCommonClassNames.GROOVY_OBJECT_SUPPORT.equals(qname) || method.hasModifierProperty(PsiModifier.ABSTRACT) && typeDefinition.isInheritor(baseClass, true)) {
if (method.isConstructor())
continue;
methods.add(mirrorMethod(typeDefinition, method, baseClass, signature.getSubstitutor()));
}
}
final Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition);
for (MethodSignature signature : toImplement) {
if (!(signature instanceof MethodSignatureBackedByPsiMethod))
continue;
final PsiMethod resolved = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
final PsiClass baseClass = resolved.getContainingClass();
if (baseClass == null)
continue;
if (!GroovyCommonClassNames.GROOVY_OBJECT.equals(baseClass.getQualifiedName()))
continue;
methods.add(mirrorMethod(typeDefinition, resolved, baseClass, signature.getSubstitutor()));
}
}
return methods;
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class TransformationContextImpl method doAddMethod.
private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
if (method instanceof GrLightMethodBuilder) {
((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
} else if (method instanceof LightMethodBuilder) {
((LightMethodBuilder) method).setContainingClass(myCodeClass);
}
MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
if (signatures.add(signature)) {
if (prepend) {
myMethods.addFirst(method);
} else {
myMethods.addLast(method);
}
}
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.
private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
final String name = prototype.getName();
if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
return;
final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
final PsiType returnType;
if (getter instanceof GrMethod) {
returnType = ((GrMethod) getter).getInferredReturnType();
} else if (getter instanceof GrAccessorMethod) {
returnType = ((GrAccessorMethod) getter).getInferredReturnType();
} else {
return;
}
if (!(returnType instanceof GrClosureType))
return;
final GrSignature signature = ((GrClosureType) returnType).getSignature();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
final GrClosureParameter[] params = signature.getParameters();
final PsiType[] types = prototypeSignature.getParameterTypes();
if (types.length != params.length)
continue;
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
continue NextSignature;
}
}
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
}
}
});
}
Aggregations