use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method visitParameterList.
@Override
public void visitParameterList(@NotNull final GrParameterList parameterList) {
super.visitParameterList(parameterList);
PsiElement parent = parameterList.getParent();
if (!(parent instanceof GrClosableBlock))
return;
GrParameter[] parameters = parameterList.getParameters();
if (parameters.length > 0) {
List<PsiType[]> signatures = ClosureParamsEnhancer.findFittingSignatures((GrClosableBlock) parent);
final List<PsiType> paramTypes = ContainerUtil.map(parameters, parameter -> parameter.getType());
if (signatures.size() > 1) {
final PsiType[] fittingSignature = ContainerUtil.find(signatures, types -> {
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(paramTypes.get(i), types[i], parameterList)) {
return false;
}
}
return true;
});
if (fittingSignature == null) {
registerError(parameterList, GroovyInspectionBundle.message("no.applicable.signature.found"), null, ProblemHighlightType.GENERIC_ERROR);
}
} else if (signatures.size() == 1) {
PsiType[] types = signatures.get(0);
for (int i = 0; i < types.length; i++) {
GrTypeElement typeElement = parameters[i].getTypeElementGroovy();
if (typeElement == null)
continue;
PsiType expected = types[i];
PsiType actual = paramTypes.get(i);
if (!TypesUtil.isAssignableByMethodCallConversion(actual, expected, parameterList)) {
registerError(typeElement, GroovyInspectionBundle.message("expected.type.0", expected.getCanonicalText(false), actual.getCanonicalText(false)), null, ProblemHighlightType.GENERIC_ERROR);
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyRefactoringUtil method verifySafeCopyExpressionSubElement.
private static int verifySafeCopyExpressionSubElement(PsiElement element) {
int result = RefactoringUtil.EXPR_COPY_SAFE;
if (element == null)
return result;
if (element instanceof GrNamedElement) {
return RefactoringUtil.EXPR_COPY_SAFE;
}
if (element instanceof GrMethodCallExpression) {
result = RefactoringUtil.EXPR_COPY_UNSAFE;
}
if (element instanceof GrNewExpression) {
return RefactoringUtil.EXPR_COPY_PROHIBITED;
}
if (element instanceof GrAssignmentExpression) {
return RefactoringUtil.EXPR_COPY_PROHIBITED;
}
if (element instanceof GrClosableBlock) {
return RefactoringUtil.EXPR_COPY_PROHIBITED;
}
if (isPlusPlusOrMinusMinus(element)) {
return RefactoringUtil.EXPR_COPY_PROHIBITED;
}
PsiElement[] children = element.getChildren();
for (PsiElement child : children) {
int childResult = verifySafeCopyExpressionSubElement(child);
result = Math.max(result, childResult);
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrClosureDelegateTypeCalculator method calculateType.
@Nullable
protected PsiType calculateType(@NotNull GrExpression expression, @NotNull PsiMethod method) {
if (!"getDelegate".equals(method.getName()) || method.getParameterList().getParametersCount() != 0)
return null;
final GrClosableBlock closure = PsiTreeUtil.getParentOfType(expression, GrClosableBlock.class);
if (closure == null)
return null;
final PsiClass closureClass = JavaPsiFacade.getInstance(expression.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, expression.getResolveScope());
if (closureClass == null || !closureClass.equals(method.getContainingClass()))
return null;
final DelegatesToInfo info = GrDelegatesToUtilKt.getDelegatesToInfo(closure);
if (info == null)
return null;
return info.getTypeToDelegate();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrMethodCallExpressionImpl method replaceClosureArgument.
@Override
public GrExpression replaceClosureArgument(@NotNull GrClosableBlock closure, @NotNull GrExpression newExpr) throws IncorrectOperationException {
if (newExpr instanceof GrClosableBlock) {
return closure.replaceWithExpression(newExpr, true);
}
final GrClosableBlock[] closureArguments = getClosureArguments();
final int i = ArrayUtil.find(closureArguments, closure);
GrArgumentList argList = getArgumentList();
if (argList.getText().isEmpty()) {
argList = (GrArgumentList) argList.replace(GroovyPsiElementFactory.getInstance(getProject()).createArgumentList());
}
for (int j = 0; j < i; j++) {
argList.add(closureArguments[j]);
closureArguments[j].delete();
}
final GrExpression result = (GrExpression) argList.add(newExpr);
closure.delete();
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GriffonPropertyListenerAnnotationChecker method checkArgumentList.
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
if (!"griffon.transform.PropertyListener".equals(annotation.getQualifiedName()))
return false;
final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
if (attributes.length != 1)
return false;
final GrAnnotationNameValuePair attribute = attributes[0];
final GrAnnotationMemberValue value = attribute.getValue();
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof GrField) {
if (value instanceof GrClosableBlock) {
return true;
}
} else if (owner instanceof GrTypeDefinition) {
if (value instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) value).resolve();
if (resolved instanceof GrField) {
final PsiClass containingClass = ((GrField) resolved).getContainingClass();
if (annotation.getManager().areElementsEquivalent((PsiElement) owner, containingClass)) {
return true;
}
}
}
}
return false;
}
Aggregations