EA-27064 - assert: GrParameterImpl.getDeclarationScope

This commit is contained in:
Maxim Medvedev
2011-04-19 14:54:18 +04:00
parent a1f887806e
commit 1fffe54e4c
3 changed files with 19 additions and 7 deletions
@@ -18,12 +18,13 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParametersOwner;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
/**
* @author ilyas
*/
public interface GrForClause extends GroovyPsiElement {
public interface GrForClause extends GroovyPsiElement, GrParametersOwner {
@Nullable
GrVariable getDeclaredVariable();
}
@@ -19,13 +19,13 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.clauses;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
/**
@@ -44,7 +44,7 @@ public class GrTraditionalForClauseImpl extends GroovyPsiElementImpl implements
return "Traditional FOR clause";
}
public GrVariable getDeclaredVariable() {
public GrParameter getDeclaredVariable() {
return findChildByClass(GrParameter.class);
}
@@ -85,7 +85,7 @@ public class GrTraditionalForClauseImpl extends GroovyPsiElementImpl implements
@Nullable
private ASTNode getFirstSemicolon() {
for (ASTNode child = getNode().getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (child.getElementType() == GroovyElementTypes.mSEMI) {
if (child.getElementType() == GroovyTokenTypes.mSEMI) {
return child;
}
}
@@ -97,7 +97,7 @@ public class GrTraditionalForClauseImpl extends GroovyPsiElementImpl implements
private ASTNode getSecondSemicolon() {
boolean firstPassed = false;
for (ASTNode child = getNode().getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (child.getElementType() == GroovyElementTypes.mSEMI) {
if (child.getElementType() == GroovyTokenTypes.mSEMI) {
if (firstPassed) {
return child;
} else {
@@ -107,4 +107,15 @@ public class GrTraditionalForClauseImpl extends GroovyPsiElementImpl implements
}
return null;
}
@Override
public GrParameter[] getParameters() {
final GrParameter declaredVariable = getDeclaredVariable();
return declaredVariable == null ? GrParameter.EMPTY_ARRAY : new GrParameter[]{declaredVariable};
}
@Override
public GrParameterList getParameterList() {
return null;
}
}
@@ -215,7 +215,7 @@ public class GrParameterImpl extends GrVariableBaseImpl<GrParameterStub> impleme
public PsiElement getDeclarationScope() {
final GrParametersOwner owner = PsiTreeUtil.getParentOfType(this, GrParametersOwner.class);
assert owner != null;
if (owner instanceof GrForInClause) return owner.getParent();
if (owner instanceof GrForClause) return owner.getParent();
return owner;
}