use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrReferenceAdjuster method process.
private static boolean process(@NotNull PsiElement element, int start, int end, boolean addImports, boolean incomplete, boolean useFqInJavadoc, boolean useFqInCode) {
boolean result = false;
if (element instanceof GrQualifiedReference<?> && ((GrQualifiedReference) element).resolve() instanceof PsiClass) {
result = shortenReferenceInner((GrQualifiedReference<?>) element, addImports, incomplete, useFqInJavadoc, useFqInCode);
} else if (element instanceof GrReferenceExpression && PsiUtil.isSuperReference(((GrReferenceExpression) element).getQualifier())) {
result = shortenReferenceInner((GrReferenceExpression) element, addImports, incomplete, useFqInJavadoc, useFqInCode);
}
PsiElement child = element.getFirstChild();
while (child != null) {
final TextRange range = child.getTextRange();
if (start < range.getEndOffset() && range.getStartOffset() < end) {
result |= process(child, start, end, addImports, incomplete, useFqInJavadoc, useFqInCode);
}
child = child.getNextSibling();
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GroovyMapValueTypeEnhancer method getReferenceType.
@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
if (resolved != null)
return null;
GrExpression qualifierExpression = ref.getQualifierExpression();
if (qualifierExpression == null)
return null;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return null;
}
PsiElement qResolved;
if (qualifierExpression instanceof GrReferenceExpression) {
qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
} else if (qualifierExpression instanceof GrMethodCall) {
qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
} else {
return null;
}
String key = ref.getReferenceName();
if (key == null)
return null;
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
if (type != null) {
return type;
}
}
if (mapType instanceof GrMapType) {
return ((GrMapType) mapType).getTypeByStringKey(key);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression 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);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrNamedArgumentSearchVisitor method visitReferenceExpression.
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
if (myFirstArgumentName.equals(referenceExpression.getReferenceName()) && !referenceExpression.isQualified()) {
PsiElement parent = referenceExpression.getParent();
if (parent instanceof GrReferenceExpression) {
GrReferenceExpression parentRef = (GrReferenceExpression) parent;
PsiElement parentParent = parentRef.getParent();
if (parentParent instanceof GrMethodCallExpression) {
if (METHOD_NAMES.contains(parentRef.getReferenceName())) {
extractArguments(((GrMethodCallExpression) parentParent).getArgumentList());
}
} else {
add(parentRef.getReferenceName());
}
} else if (parent instanceof GrIndexProperty) {
GrIndexProperty indexProperty = (GrIndexProperty) parent;
extractArguments(indexProperty.getArgumentList());
}
}
super.visitReferenceExpression(referenceExpression);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GroovyReadWriteAccessDetector method getExpressionAccess.
@NotNull
@Override
public Access getExpressionAccess(@NotNull PsiElement expression) {
if (expression instanceof GrExpression) {
GrExpression expr = (GrExpression) expression;
boolean readAccess = PsiUtil.isAccessedForReading(expr);
boolean writeAccess = PsiUtil.isAccessedForWriting(expr);
if (!writeAccess && expr instanceof GrReferenceExpression) {
//when searching usages of fields, should show all found setters as a "only write usage"
PsiElement actualReferee = ((GrReferenceExpression) expr).resolve();
if (actualReferee instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertySetter((PsiMethod) actualReferee)) {
writeAccess = true;
readAccess = false;
}
}
if (writeAccess && readAccess)
return Access.ReadWrite;
return writeAccess ? Access.Write : Access.Read;
} else if (expression instanceof PsiExpression) {
PsiExpression expr = (PsiExpression) expression;
boolean readAccess = com.intellij.psi.util.PsiUtil.isAccessedForReading(expr);
boolean writeAccess = com.intellij.psi.util.PsiUtil.isAccessedForWriting(expr);
if (!writeAccess && expr instanceof PsiReferenceExpression) {
//when searching usages of fields, should show all found setters as a "only write usage"
PsiElement actualReferee = ((PsiReferenceExpression) expr).resolve();
if (actualReferee instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertySetter((PsiMethod) actualReferee)) {
writeAccess = true;
readAccess = false;
}
}
if (writeAccess && readAccess)
return Access.ReadWrite;
return writeAccess ? Access.Write : Access.Read;
} else {
return Access.Read;
}
}
Aggregations