static HighlightInfo checkRawConstructorReference(@NotNull PsiMethodReferenceExpression expression) { if(expression.isConstructor()) { PsiType[] typeParameters = expression.getTypeParameters(); if(typeParameters.length > 0) { PsiElement qualifier = expression.getQualifier(); if(qualifier instanceof PsiReferenceExpression) { PsiElement resolve = ((PsiReferenceExpression) qualifier).resolve(); if(resolve instanceof PsiClass && ((PsiClass) resolve).hasTypeParameters()) { return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression) .descriptionAndTooltip("Raw constructor reference with explicit type parameters for " + "constructor").create(); } } } } return null; }
public T mapFirst(PsiMethodReferenceExpression methodRef) { if(methodRef == null) { return null; } List<CallHandler<T>> functions = myMap.get(methodRef.getReferenceName()); if(functions == null) { return null; } for(CallHandler<T> function : functions) { T t = function.applyMethodReference(methodRef); if(t != null) { return t; } } return null; }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiMethodReferenceExpression methodRef = ObjectUtils.tryCast(descriptor.getStartElement(), PsiMethodReferenceExpression.class); if(methodRef == null) { return; } PsiLambdaExpression lambdaExpression = LambdaRefactoringUtil.convertMethodReferenceToLambda(methodRef, true, true); if(lambdaExpression == null) { return; } PsiElement body = lambdaExpression.getBody(); if(body == null) { return; } body.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(myValue, lambdaExpression)); }
public static CustomMethodHandler find(MethodCallInstruction instruction) { PsiElement context = instruction.getContext(); if(context instanceof PsiMethodCallExpression) { return CUSTOM_METHOD_HANDLERS.mapFirst((PsiMethodCallExpression) context); } else if(context instanceof PsiMethodReferenceExpression) { return CUSTOM_METHOD_HANDLERS.mapFirst((PsiMethodReferenceExpression) context); } return null; }
@Override public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) { mVisitor.report("PsiMethodReferenceExpression", expression.getText(), expression); super.visitReferenceExpression(expression); }
public MethodCallUsageInfo(final PsiReferenceExpression referenceExpression, final boolean internal) { super(referenceExpression); myIsInternal = internal; myMethodCallExpression = referenceExpression instanceof PsiMethodReferenceExpression ? referenceExpression : referenceExpression.getParent(); }
@Override public PsiMethodReferenceExpression createPsi(@NotNull ASTNode node) { return new PsiMethodReferenceExpressionImpl(node); }
@Override public PsiMethodReferenceExpression createPsi(@NotNull FunctionalExpressionStub<PsiMethodReferenceExpression> stub) { return new PsiMethodReferenceExpressionImpl(stub); }
public T applyMethodReference(PsiMethodReferenceExpression ref) { return matcher().methodReferenceMatches(ref) ? myTransformer.apply(null) : null; }