use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyDslDefaultMembers method delegatesTo.
/**
* **********************************************************************************
* Methods and properties of the GroovyDSL language
* **********************************************************************************
*/
public void delegatesTo(@Nullable PsiElement elem, GdslMembersHolderConsumer consumer) {
if (elem instanceof PsiClass) {
final PsiClass clazz = (PsiClass) elem;
final NonCodeMembersHolder holder = new NonCodeMembersHolder();
if (clazz instanceof GrTypeDefinition) {
final PsiClassType type = JavaPsiFacade.getElementFactory(consumer.getProject()).createType(clazz);
final ResolverProcessor processor = CompletionProcessor.createPropertyCompletionProcessor(clazz);
final GroovyPsiElement context = (GroovyPsiElement) clazz;
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
for (GroovyResolveResult result : processor.getCandidates()) {
final PsiElement element = result.getElement();
if (element instanceof PsiMethod && !((PsiMethod) element).isConstructor() || element instanceof PsiField) {
holder.addDeclaration(element);
}
}
} else {
for (PsiMethod method : clazz.getAllMethods()) {
if (!method.isConstructor())
holder.addDeclaration(method);
}
for (PsiField field : clazz.getAllFields()) {
holder.addDeclaration(field);
}
}
consumer.addMemberHolder(holder);
} else if (elem instanceof GrExpression) {
GrExpression expr = (GrExpression) elem;
final PsiType type = expr.getType();
if (type instanceof PsiClassType) {
PsiClassType ctype = (PsiClassType) type;
delegatesTo(ctype.resolve(), consumer);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method checkOperator.
private void checkOperator(@NotNull CallInfo<? extends GrBinaryExpression> info) {
if (hasErrorElements(info.getCall()))
return;
if (isSpockTimesOperator(info.getCall()))
return;
GroovyResolveResult[] results = info.multiResolve();
GroovyResolveResult resolveResult = info.advancedResolve();
if (isOperatorWithSimpleTypes(info.getCall(), resolveResult))
return;
if (!checkCannotInferArgumentTypes(info))
return;
if (resolveResult.getElement() != null) {
checkMethodApplicability(resolveResult, true, info);
} else if (results.length > 0) {
for (GroovyResolveResult result : results) {
if (!checkMethodApplicability(result, false, info))
return;
}
registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("method.call.is.ambiguous"));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method checkIndexProperty.
private void checkIndexProperty(@NotNull CallInfo<? extends GrIndexProperty> info) {
if (hasErrorElements(info.getArgumentList()))
return;
if (!checkCannotInferArgumentTypes(info))
return;
final PsiType type = info.getQualifierInstanceType();
if (ResolveUtil.getClassReferenceFromExpression(info.getCall()) != null) {
return;
}
final PsiType[] types = info.getArgumentTypes();
if (checkSimpleArrayAccess(info, type, types))
return;
final GroovyResolveResult[] results = info.multiResolve();
final GroovyResolveResult resolveResult = info.advancedResolve();
if (resolveResult.getElement() != null) {
PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiMethod && !resolveResult.isInvokedOnProperty()) {
checkMethodApplicability(resolveResult, true, info);
} else if (resolved instanceof GrField) {
checkCallApplicability(((GrField) resolved).getTypeGroovy(), true, info);
} else if (resolved instanceof PsiField) {
checkCallApplicability(((PsiField) resolved).getType(), true, info);
}
} else if (results.length > 0) {
for (GroovyResolveResult result : results) {
PsiElement resolved = result.getElement();
if (resolved instanceof PsiMethod && !result.isInvokedOnProperty()) {
if (!checkMethodApplicability(result, false, info))
return;
} else if (resolved instanceof GrField) {
if (!checkCallApplicability(((GrField) resolved).getTypeGroovy(), false, info))
return;
} else if (resolved instanceof PsiField) {
if (!checkCallApplicability(((PsiField) resolved).getType(), false, info))
return;
}
}
registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("method.call.is.ambiguous"));
} else {
final String typesString = buildArgTypesList(types);
registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("cannot.find.operator.overload.method", typesString));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyChangeUtilSupport method encodeInformation.
@Override
public void encodeInformation(final TreeElement element, final ASTNode original, final Map<Object, Object> encodingState) {
if (original instanceof CompositeElement) {
if (original.getElementType() == GroovyElementTypes.REFERENCE_ELEMENT || original.getElementType() == GroovyElementTypes.REFERENCE_EXPRESSION) {
PsiElement psi = original.getPsi();
Project project = psi.getProject();
if (!PsiUtil.isThisOrSuperRef(psi) && project.isInitialized() && !DumbService.isDumb(project)) {
final GroovyResolveResult result = ((GrReferenceElement) psi).advancedResolve();
if (result != null) {
final PsiElement target = result.getElement();
if (target instanceof PsiClass || (target instanceof PsiMethod || target instanceof PsiField) && ((PsiMember) target).hasModifierProperty(PsiModifier.STATIC) && result.getCurrentFileResolveContext() instanceof GrImportStatement) {
element.putCopyableUserData(REFERENCED_MEMBER_KEY, (PsiMember) target);
}
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyConstructorNamedArgumentProvider method getNamedArguments.
@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
if (!(call instanceof GrNewExpression))
return;
PsiElement resolve = resolveResult.getElement();
if (resolve != null) {
if (!(resolve instanceof PsiMethod))
return;
PsiMethod method = (PsiMethod) resolve;
if (!method.isConstructor())
return;
}
GrNewExpression newCall = (GrNewExpression) call;
GrArgumentList argumentList = newCall.getArgumentList();
if (argumentList == null)
return;
GrExpression[] expressionArguments = argumentList.getExpressionArguments();
if (expressionArguments.length > 1 || (expressionArguments.length == 1 && !(expressionArguments[0] instanceof GrReferenceExpression))) {
return;
}
for (GroovyResolveResult newResult : newCall.multiResolveClass()) {
PsiElement element = newResult.getElement();
if (!(element instanceof PsiClass))
continue;
PsiClass aClass = (PsiClass) element;
if (!isClassHasConstructorWithMap(aClass))
continue;
PsiClassType classType = JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass);
processClass(call, classType, argumentName, result);
}
}
Aggregations