Object literal expression

This commit is contained in:
Maxim Shafirov
2011-01-09 00:29:43 +03:00
parent 6eb3a22059
commit 851d83272e
4 changed files with 68 additions and 2 deletions
@@ -11,11 +11,12 @@ import java.util.List;
/**
* @author max
*/
public class JetClass extends JetTypeParameterListOwner {
public class JetClass extends JetTypeParameterListOwner implements JetClassOrObject {
public JetClass(@NotNull ASTNode node) {
super(node);
}
@Override
public List<JetDeclaration> getDeclarations() {
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
if (body == null) return Collections.emptyList();
@@ -39,4 +40,17 @@ public class JetClass extends JetTypeParameterListOwner {
if (list == null) return Collections.emptyList();
return list.getParameters();
}
@Override
@Nullable
public JetDelegationSpecifierList getDelegationSpecifierList() {
return (JetDelegationSpecifierList) findChildByType(JetNodeTypes.DELEGATION_SPECIFIER_LIST);
}
@Override
@NotNull
public List<JetDelegationSpecifier> getDelegationSpecifiers() {
JetDelegationSpecifierList list = getDelegationSpecifierList();
return list != null ? list.getDelegationSpecifiers() : Collections.<JetDelegationSpecifier>emptyList();
}
}
@@ -0,0 +1,19 @@
package org.jetbrains.jet.lang.psi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author max
*/
public interface JetClassOrObject {
List<JetDeclaration> getDeclarations();
@Nullable
JetDelegationSpecifierList getDelegationSpecifierList();
@NotNull
List<JetDelegationSpecifier> getDelegationSpecifiers();
}
@@ -1,8 +1,11 @@
package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author max
*/
@@ -15,4 +18,8 @@ public class JetDelegationSpecifierList extends JetElement {
public void accept(JetVisitor visitor) {
visitor.visitDelegationSpecifierList(this);
}
public List<JetDelegationSpecifier> getDelegationSpecifiers() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDelegationSpecifier.class);
}
}
@@ -2,11 +2,16 @@ package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import java.util.Collections;
import java.util.List;
/**
* @author max
*/
public class JetObjectLiteralExpression extends JetExpression {
public class JetObjectLiteralExpression extends JetExpression implements JetClassOrObject {
public JetObjectLiteralExpression(@NotNull ASTNode node) {
super(node);
}
@@ -15,4 +20,25 @@ public class JetObjectLiteralExpression extends JetExpression {
public void accept(JetVisitor visitor) {
visitor.visitObjectLiteralExpression(this);
}
@Override
@Nullable
public JetDelegationSpecifierList getDelegationSpecifierList() {
return (JetDelegationSpecifierList) findChildByType(JetNodeTypes.DELEGATION_SPECIFIER_LIST);
}
@Override
@NotNull
public List<JetDelegationSpecifier> getDelegationSpecifiers() {
JetDelegationSpecifierList list = getDelegationSpecifierList();
return list != null ? list.getDelegationSpecifiers() : Collections.<JetDelegationSpecifier>emptyList();
}
@Override
public List<JetDeclaration> getDeclarations() {
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
if (body == null) return Collections.emptyList();
return body.getDeclarations();
}
}