/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/closure/ForToEachPredicate.java

https://bitbucket.org/nbargnesi/idea · Java · 38 lines · 20 code · 3 blank · 15 comment · 4 complexity · 37ebc77e166282ea65eb79a694467b06 MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jetbrains.plugins.groovy.intentions.closure;
  17. import com.intellij.psi.PsiElement;
  18. import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
  19. import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
  20. import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
  21. import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause;
  22. import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause;
  23. class ForToEachPredicate implements PsiElementPredicate {
  24. public boolean satisfiedBy(PsiElement element) {
  25. if (!(element instanceof GrForStatement)) {
  26. return false;
  27. }
  28. final GrForStatement statement = (GrForStatement) element;
  29. final GrForClause clause = statement.getClause();
  30. if (!(clause instanceof GrForInClause) || ((GrForInClause) clause).getIteratedExpression() == null) {
  31. return false;
  32. }
  33. return !ErrorUtil.containsError(element);
  34. }
  35. }