use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class OldReferencesResolver method getQualifierFromGetterCall.
/**
* checks for the case: qualifier.getFoo()(args)
* @param methodExpression
*/
@Nullable
private static GrExpression getQualifierFromGetterCall(GrMethodCall methodExpression) {
final GroovyResolveResult result = methodExpression.advancedResolve();
if (!(result.getElement() instanceof GrAccessorMethod) || result.isInvokedOnProperty())
return null;
final GrExpression invoked = methodExpression.getInvokedExpression();
if (invoked instanceof GrReferenceExpression)
return ((GrReferenceExpression) invoked).getQualifier();
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GroovyPostHighlightingPass method isFieldUnused.
private static boolean isFieldUnused(GrField field, ProgressIndicator progress, GlobalUsageHelper usageHelper) {
if (!UnusedSymbolUtil.isFieldUnused(field.getProject(), field.getContainingFile(), field, progress, usageHelper))
return false;
final GrAccessorMethod[] getters = field.getGetters();
final GrAccessorMethod setter = field.getSetter();
for (GrAccessorMethod getter : getters) {
if (getter.findSuperMethods().length > 0) {
return false;
}
}
if (setter != null) {
if (setter.findSuperMethods().length > 0) {
return false;
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GroovyNamedArgumentProvider method getNamedArgumentsFromAllProviders.
@Nullable
public static Map<String, NamedArgumentDescriptor> getNamedArgumentsFromAllProviders(@NotNull GrCall call, @Nullable String argumentName, boolean forCompletion) {
Map<String, NamedArgumentDescriptor> namedArguments = new HashMap<String, NamedArgumentDescriptor>() {
@Override
public NamedArgumentDescriptor put(String key, NamedArgumentDescriptor value) {
NamedArgumentDescriptor oldValue = super.put(key, value);
if (oldValue != null) {
super.put(key, oldValue);
}
//noinspection ConstantConditions
return oldValue;
}
};
GroovyResolveResult[] callVariants = call.getCallVariants(null);
if (callVariants.length == 0 || PsiUtil.isSingleBindingVariant(callVariants)) {
for (GroovyNamedArgumentProvider namedArgumentProvider : EP_NAME.getExtensions()) {
namedArgumentProvider.getNamedArguments(call, GroovyResolveResult.EMPTY_RESULT, argumentName, forCompletion, namedArguments);
}
} else {
boolean mapExpected = false;
for (GroovyResolveResult result : callVariants) {
PsiElement element = result.getElement();
if (element instanceof GrAccessorMethod)
continue;
if (element instanceof PsiMethod) {
PsiMethod method = (PsiMethod) element;
PsiParameter[] parameters = method.getParameterList().getParameters();
if (!method.isConstructor() && !(parameters.length > 0 && canBeMap(parameters[0])))
continue;
mapExpected = true;
for (GroovyMethodInfo methodInfo : GroovyMethodInfo.getInfos(method)) {
if (methodInfo.getNamedArguments() != null || methodInfo.isNamedArgumentProviderDefined()) {
if (methodInfo.isApplicable(method)) {
if (methodInfo.isNamedArgumentProviderDefined()) {
methodInfo.getNamedArgProvider().getNamedArguments(call, result, argumentName, forCompletion, namedArguments);
}
if (methodInfo.getNamedArguments() != null) {
namedArguments.putAll(methodInfo.getNamedArguments());
}
}
}
}
}
for (GroovyNamedArgumentProvider namedArgumentProvider : EP_NAME.getExtensions()) {
namedArgumentProvider.getNamedArguments(call, result, argumentName, forCompletion, namedArguments);
}
if (element instanceof GrVariable && InheritanceUtil.isInheritor(((GrVariable) element).getTypeGroovy(), GroovyCommonClassNames.GROOVY_LANG_CLOSURE)) {
mapExpected = true;
}
}
if (!mapExpected && namedArguments.isEmpty()) {
return null;
}
}
return namedArguments;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class AccessorReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (element instanceof PsiMethod) {
final String propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod) element);
if (propertyName == null)
return;
SearchScope scope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope());
queryParameters.getOptimizer().searchWord(propertyName, scope, UsageSearchContext.IN_CODE, true, element);
} else if (element instanceof GrField) {
for (GrAccessorMethod method : ((GrField) element).getGetters()) {
MethodReferencesSearch.search(method, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
final GrAccessorMethod setter = ((GrField) element).getSetter();
if (setter != null) {
MethodReferencesSearch.search(setter, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method calculateType.
@Nullable
private static PsiType calculateType(@NotNull GrReferenceExpressionImpl refExpr, boolean forceRValue) {
final GroovyResolveResult[] results = refExpr.multiResolve(false, forceRValue);
final GroovyResolveResult result = PsiImplUtil.extractUniqueResult(results);
final PsiElement resolved = result.getElement();
for (GrExpressionTypeCalculator calculator : GrExpressionTypeCalculator.EP_NAME.getExtensions()) {
PsiType type = calculator.calculateType(refExpr, resolved);
if (type != null)
return type;
}
if (ResolveUtil.isClassReference(refExpr)) {
GrExpression qualifier = refExpr.getQualifier();
LOG.assertTrue(qualifier != null);
return qualifier.getType();
}
if (PsiUtil.isCompileStatic(refExpr)) {
final PsiType type;
if (resolved instanceof GrField) {
type = ((GrField) resolved).getType();
} else if (resolved instanceof GrVariable) {
type = ((GrVariable) resolved).getDeclaredType();
} else if (resolved instanceof GrAccessorMethod) {
type = ((GrAccessorMethod) resolved).getProperty().getType();
} else {
type = null;
}
if (type != null) {
return result.getSubstitutor().substitute(type);
}
}
final PsiType nominal = refExpr.getNominalType(forceRValue);
Boolean reassigned = GrReassignedLocalVarsChecker.isReassignedVar(refExpr);
if (reassigned != null && reassigned.booleanValue()) {
return GrReassignedLocalVarsChecker.getReassignedVarType(refExpr, true);
}
final PsiType inferred = getInferredTypes(refExpr, resolved);
if (inferred == null) {
if (nominal == null) {
//inside nested closure we could still try to infer from variable initializer. Not sound, but makes sense
if (resolved instanceof GrVariable) {
LOG.assertTrue(resolved.isValid());
return ((GrVariable) resolved).getTypeGroovy();
}
}
return nominal;
}
if (nominal == null)
return inferred;
if (!TypeConversionUtil.isAssignable(TypeConversionUtil.erasure(nominal), inferred, false)) {
if (resolved instanceof GrVariable && ((GrVariable) resolved).getTypeElementGroovy() != null) {
return nominal;
}
}
return inferred;
}
Aggregations