use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class ChangeToOperatorInspection method getFix.
@Nullable
protected GroovyFix getFix(@NotNull Transformation transformation, @NotNull String methodName) {
return new GroovyFix() {
@Nls
@NotNull
@Override
public String getFamilyName() {
return message("replace.with.operator.fix", methodName);
}
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
PsiElement call = descriptor.getPsiElement().getParent();
if (call == null)
return;
call = call.getParent();
if (!(call instanceof GrMethodCall))
return;
GrMethodCall methodCall = (GrMethodCall) call;
GrExpression invokedExpression = methodCall.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression))
return;
Options options = getOptions();
if (!transformation.couldApply(methodCall, options))
return;
transformation.apply(methodCall, options);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class AsTypeTransformation method apply.
@Override
public void apply(@NotNull GrMethodCall methodCall, @NotNull ChangeToOperatorInspection.Options options) {
GrReferenceExpression rhs = (GrReferenceExpression) getRhs(methodCall);
GrExpression rhsQualifierExpression = rhs.isQualified() ? rhs.getQualifierExpression() : rhs;
if (rhsQualifierExpression == null)
return;
replaceExpression(methodCall, format("%s %s %s", getLhs(methodCall).getText(), kAS, rhsQualifierExpression.getText()));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class WritesCounterDFAInstance method getVariable.
@Contract("null -> null")
@Nullable
private static GrVariable getVariable(@Nullable PsiElement instructionElement) {
final GrVariable variable;
if (instructionElement instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) instructionElement).resolve();
variable = resolved instanceof GrVariable ? (GrVariable) resolved : null;
} else if (instructionElement instanceof GrVariable) {
variable = (GrVariable) instructionElement;
} else {
variable = null;
}
return variable != null && PsiUtil.isLocalOrParameter(variable) ? variable : null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GroovyUntypedAccessInspection method buildVisitor.
@Override
@NotNull
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) {
super.visitReferenceExpression(refExpr);
if (PsiUtil.isThisOrSuperRef(refExpr))
return;
GroovyResolveResult resolveResult = refExpr.advancedResolve();
PsiElement resolved = resolveResult.getElement();
if (resolved != null) {
if (GrHighlightUtil.isDeclarationAssignment(refExpr) || resolved instanceof PsiPackage)
return;
} else {
GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null && GrHighlightUtil.isDeclarationAssignment(refExpr))
return;
}
final PsiType refExprType = refExpr.getType();
if (refExprType == null) {
if (resolved != null) {
registerError(refExpr);
}
} else if (refExprType instanceof PsiClassType && ((PsiClassType) refExprType).resolve() == null) {
registerError(refExpr);
}
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class SpockMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (ResolveUtil.shouldProcessProperties(classHint)) {
GrMethod method = PsiTreeUtil.getParentOfType(place, GrMethod.class);
if (method == null)
return;
if (aClass != method.getContainingClass())
return;
Map<String, SpockVariableDescriptor> cachedValue = SpockUtils.getVariableMap(method);
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
for (SpockVariableDescriptor spockVar : cachedValue.values()) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
} else {
SpockVariableDescriptor spockVar = cachedValue.get(nameHint);
if (spockVar != null && spockVar.getNavigationElement() != place) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
nameHint = place instanceof GrReferenceExpression ? ((GrReferenceExpression) place).getReferenceName() : null;
if (nameHint != null)
nameHint = GroovyPropertyUtils.getGetterNameNonBoolean(nameHint);
}
if ("get_".equals(nameHint)) {
GrLightMethodBuilder m = new GrLightMethodBuilder(aClass.getManager(), "get_");
m.setReturnType(null);
if (!processor.execute(m, state))
return;
}
}
}
Aggregations