PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull 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 static boolean isModifierListOfVarDecl(PsiElement element, PsiElement parent) { return parent instanceof GrVariableDeclaration && ((GrVariableDeclaration)parent).getModifierList() == element; } private static boolean isModifierListOfVar(PsiElement element, PsiElement parent) { return parent instanceof GrVariable && ((GrVariable)parent).getModifierList() == element; } private static boolean isNameIdentifierOfVariable(PsiElement element, PsiElement parent) { return parent instanceof GrVariable && ((GrVariable)parent).getTypeElementGroovy() == null && element == ((GrVariable)parent).getNameIdentifierGroovy(); } }; }