use of org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate in project intellij-community by JetBrains.
the class GrSetStrongTypeIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
PsiElement parent = element.getParent();
PsiElement pparent;
if (isNameIdentifierOfVariable(element, parent) || isModifierListOfVar(element, parent)) {
pparent = parent.getParent();
} else if (isModifierListOfVarDecl(element, parent)) {
pparent = parent;
} else {
return false;
}
if (pparent instanceof GrVariableDeclaration) {
if (((GrVariableDeclaration) pparent).getTypeElementGroovy() != null)
return false;
GrVariable[] variables = ((GrVariableDeclaration) pparent).getVariables();
for (GrVariable variable : variables) {
if (isVarDeclaredWithInitializer(variable))
return true;
}
} else if (pparent instanceof GrForInClause) {
final GrVariable variable = ((GrForInClause) pparent).getDeclaredVariable();
return variable != null && variable.getTypeElementGroovy() == null && PsiUtil.extractIteratedType((GrForInClause) pparent) != null;
} else if (parent instanceof GrParameter && pparent instanceof GrParameterList) {
return ((GrParameter) parent).getTypeElementGroovy() == null && getClosureParameterType((PsiParameter) parent) != null;
} else {
final GrVariable variable = (GrVariable) parent;
return variable.getTypeElementGroovy() == null && isVarDeclaredWithInitializer(variable);
}
return false;
}
private boolean isModifierListOfVarDecl(PsiElement element, PsiElement parent) {
return parent instanceof GrVariableDeclaration && ((GrVariableDeclaration) parent).getModifierList() == element;
}
private boolean isModifierListOfVar(PsiElement element, PsiElement parent) {
return parent instanceof GrVariable && ((GrVariable) parent).getModifierList() == element;
}
private boolean isNameIdentifierOfVariable(PsiElement element, PsiElement parent) {
return parent instanceof GrVariable && ((GrVariable) parent).getTypeElementGroovy() == null && element == ((GrVariable) parent).getNameIdentifierGroovy();
}
};
}
use of org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate in project intellij-community by JetBrains.
the class GrAliasImportIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (element instanceof GrReferenceExpression) {
GroovyResolveResult result = ((GrReferenceExpression) element).advancedResolve();
PsiElement context = result.getCurrentFileResolveContext();
if (!(context instanceof GrImportStatement))
return false;
GrImportStatement importStatement = (GrImportStatement) context;
if (!importStatement.isStatic() || importStatement.isAliasedImport())
return false;
return true;
} else if (element instanceof GrImportStatement) {
final GrImportStatement importStatement = (GrImportStatement) element;
if (!importStatement.isStatic())
return false;
if (importStatement.isOnDemand())
return false;
if (importStatement.isAliasedImport())
return false;
return true;
}
return false;
}
};
}
use of org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate in project intellij-community by JetBrains.
the class FlipIfIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!element.getNode().getElementType().equals(GroovyTokenTypes.kIF))
return false;
if (!(element.getParent() instanceof GrIfStatement))
return false;
final GrIfStatement ifStatement = DefaultGroovyMethods.asType(element.getParent(), GrIfStatement.class);
final GrIfStatement elseIf = getElseIf(ifStatement);
return elseIf != null && checkIf(ifStatement) && checkIf(elseIf);
}
};
}
use of org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate in project intellij-community by JetBrains.
the class ImportOnDemandIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrReferenceElement))
return false;
final GrReferenceElement ref = (GrReferenceElement) element;
final PsiElement parent = ref.getParent();
if (!(parent instanceof GrReferenceElement))
return false;
final PsiElement resolved = ref.resolve();
if (resolved == null)
return false;
return resolved instanceof PsiClass;
}
};
}
use of org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate in project intellij-community by JetBrains.
the class ConvertJavaStyleArrayIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression))
return false;
final GrExpression expression = ((GrMethodCallExpression) element).getInvokedExpression();
if (!(expression instanceof GrNewExpression))
return false;
if (((GrNewExpression) expression).getArrayCount() == 0)
return false;
if (!((GrMethodCallExpression) element).getArgumentList().getText().trim().isEmpty())
return false;
final GrClosableBlock[] closureArguments = ((GrMethodCallExpression) element).getClosureArguments();
if (closureArguments.length != 1)
return false;
final GrClosableBlock block = closureArguments[0];
if (block.getLBrace() == null || block.getRBrace() == null)
return false;
return true;
}
};
}
Aggregations