use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrRefactoringConflictsUtil method checkUsedElements.
public static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<GrMember> membersToMove, @Nullable Set<PsiMethod> abstractMethods, @Nullable PsiClass targetClass, @NotNull PsiElement context, MultiMap<PsiElement, String> conflicts) {
final Set<PsiMember> moving = new HashSet<>(membersToMove);
if (abstractMethods != null) {
moving.addAll(abstractMethods);
}
if (scope instanceof GrReferenceExpression) {
GrReferenceExpression refExpr = (GrReferenceExpression) scope;
PsiElement refElement = refExpr.resolve();
if (refElement instanceof PsiMember) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
GrExpression qualifier = refExpr.getQualifierExpression();
PsiClass accessClass = (PsiClass) (qualifier != null ? PsiUtil.getAccessObjectClass(qualifier).getElement() : null);
RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, accessClass, member, conflicts);
}
}
} else if (scope instanceof GrNewExpression) {
final GrNewExpression newExpression = (GrNewExpression) scope;
final GrAnonymousClassDefinition anonymousClass = newExpression.getAnonymousClassDefinition();
if (anonymousClass != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(anonymousClass, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility(anonymousClass, context, anonymousClass, member, conflicts);
}
} else {
final PsiMethod refElement = newExpression.resolveMethod();
if (refElement != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility(refElement, context, null, member, conflicts);
}
}
}
} else if (scope instanceof GrCodeReferenceElement) {
GrCodeReferenceElement refExpr = (GrCodeReferenceElement) scope;
PsiElement refElement = refExpr.resolve();
if (refElement instanceof PsiMember) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, null, member, conflicts);
}
}
}
for (PsiElement child : scope.getChildren()) {
if (child instanceof PsiWhiteSpace || child instanceof PsiComment)
continue;
checkUsedElements(member, child, membersToMove, abstractMethods, targetClass, context, conflicts);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project android by JetBrains.
the class AndroidGradleSpellcheckingStrategy method isPrint.
private static boolean isPrint(PsiElement element) {
PsiElement parent0 = element.getParent();
if (parent0 == null) {
return false;
}
PsiElement parent1 = parent0.getParent();
if (parent1 == null) {
return false;
}
PsiElement parent2 = parent1.getParent();
if (parent2 == null) {
return false;
}
if (parent2 instanceof GrCommandArgumentList) {
parent2 = parent2.getParent();
}
if (parent2 instanceof GrApplicationStatement) {
GrApplicationStatement call = (GrApplicationStatement) parent2;
GrExpression propertyExpression = call.getInvokedExpression();
if (propertyExpression instanceof GrReferenceExpression) {
GrReferenceExpression propertyRef = (GrReferenceExpression) propertyExpression;
String property = propertyRef.getReferenceName();
if ("print".equals(property) || "println".equals(property)) {
return true;
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GradleUnresolvedReferenceFilter method isReject.
@Override
public boolean isReject(@NotNull GrReferenceExpression expression) {
final PsiType psiType = GradleResolverUtil.getTypeOf(expression);
if (psiType == null) {
PsiElement child = expression.getFirstChild();
if (child == null)
return false;
PsiReference reference = child.getReference();
if (reference instanceof GrReferenceExpression) {
PsiType type = ((GrReferenceExpression) reference).getType();
if (type != null) {
PsiClassType extType = createGenericType(GRADLE_API_EXTRA_PROPERTIES_EXTENSION, expression, null);
return TypeConversionUtil.areTypesConvertible(type, extType);
}
}
return false;
}
Set<String> toIgnore = new HashSet<>(IGNORE_SET);
GradleExtensionsSettings.GradleExtensionsData extensionsData = GradleExtensionsContributor.Companion.getExtensionsFor(expression);
if (extensionsData != null) {
for (GradleExtensionsSettings.GradleExtension extension : extensionsData.extensions) {
if (StringUtil.isNotEmpty(extension.namedObjectTypeFqn)) {
toIgnore.add(extension.namedObjectTypeFqn);
}
}
}
return toIgnore.contains(TypesUtil.getQualifiedName(psiType));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class SecondUnsafeCallQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (!(element instanceof GrReferenceExpression))
return;
final PsiElement newDot = GroovyPsiElementFactory.getInstance(project).createDotToken(GroovyTokenTypes.mOPTIONAL_DOT.toString());
((GrReferenceExpression) element).replaceDotToken(newDot);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrHighlightUtil method isScriptPropertyAccess.
private static boolean isScriptPropertyAccess(GrReferenceExpression refExpr) {
final GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null) {
final PsiClass clazz = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class);
if (clazz == null) {
//script
return true;
}
//in class, a property should normally be defined, so it's not a declaration
return false;
}
final PsiType type = qualifier.getType();
if (type instanceof PsiClassType && !(qualifier instanceof GrReferenceExpression && ((GrReferenceExpression) qualifier).resolve() instanceof GroovyScriptClass)) {
final PsiClassType classType = (PsiClassType) type;
final PsiClass psiClass = classType.resolve();
if (psiClass instanceof GroovyScriptClass) {
return true;
}
}
return false;
}
Aggregations