A bit more psi nodes
This commit is contained in:
@@ -5,19 +5,28 @@ package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.jet.lang.JetLanguage;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
public interface JetNodeTypes {
|
||||
IFileElementType JET_FILE = new IFileElementType(JetLanguage.INSTANCE);
|
||||
|
||||
JetNodeType NAMESPACE = new JetNodeType("NAMESPACE", JetNamespace.class);
|
||||
JetNodeType CLASS = new JetNodeType("CLASS");
|
||||
JetNodeType PROPERTY = new JetNodeType("PROPERTY");
|
||||
JetNodeType FUN = new JetNodeType("FUN");
|
||||
JetNodeType EXTENSION = new JetNodeType("EXTENSION");
|
||||
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF");
|
||||
JetNodeType DECOMPOSER = new JetNodeType("DECOMPOSER");
|
||||
JetNodeType CLASS = new JetNodeType("CLASS", JetClass.class);
|
||||
JetNodeType PROPERTY = new JetNodeType("PROPERTY", JetProperty.class);
|
||||
JetNodeType FUN = new JetNodeType("FUN", JetFunction.class);
|
||||
JetNodeType EXTENSION = new JetNodeType("EXTENSION", JetExtension.class);
|
||||
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
||||
JetNodeType DECOMPOSER = new JetNodeType("DECOMPOSER", JetDecomposer.class);
|
||||
|
||||
JetNodeType CLASS_OBJECT = new JetNodeType("CLASS_OBJECT", JetClassObject.class);
|
||||
JetNodeType CONSTRUCTOR = new JetNodeType("CONSTRUCTOR", JetConstructor.class);
|
||||
|
||||
TokenSet DECLARATIONS = TokenSet.create(
|
||||
NAMESPACE, CLASS, PROPERTY, FUN, EXTENSION,
|
||||
TYPEDEF, DECOMPOSER, CLASS_OBJECT, CONSTRUCTOR);
|
||||
|
||||
JetNodeType TYPE_PARAMETER_LIST = new JetNodeType("TYPE_PARAMETER_LIST");
|
||||
JetNodeType TYPE_PARAMETER = new JetNodeType("TYPE_PARAMETER");
|
||||
JetNodeType PRIMARY_CONSTRUCTOR_PARAMETERS_LIST = new JetNodeType("PRIMARY_CONSTRUCTOR_PARAMETERS_LIST");
|
||||
@@ -29,8 +38,8 @@ public interface JetNodeTypes {
|
||||
JetNodeType DELEGATOR_SUPER_CLASS = new JetNodeType("DELEGATOR_SUPER_CLASS");
|
||||
JetNodeType VALUE_PARAMETER_LIST = new JetNodeType("VALUE_PARAMETER_LIST");
|
||||
JetNodeType NAMED_ARGUMENT = new JetNodeType("NAMED_ARGUMENT");
|
||||
JetNodeType CLASS_BODY = new JetNodeType("CLASS_BODY");
|
||||
JetNodeType IMPORT_DIRECTIVE = new JetNodeType("IMPORT_DIRECTIVE");
|
||||
JetNodeType CLASS_BODY = new JetNodeType("CLASS_BODY", JetClassBody.class);
|
||||
JetNodeType IMPORT_DIRECTIVE = new JetNodeType("IMPORT_DIRECTIVE", JetImportDirective.class);
|
||||
JetNodeType IMPORTED = new JetNodeType("IMPORTED");
|
||||
JetNodeType NAMESPACE_BODY = new JetNodeType("NAMESPACE_BODY");
|
||||
JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST");
|
||||
@@ -49,11 +58,9 @@ public interface JetNodeTypes {
|
||||
// TODO: review
|
||||
JetNodeType RECEIVER_TYPE_ATTRIBUTES = new JetNodeType("RECEIVER_TYPE_ATTRIBUTES");
|
||||
JetNodeType PROPERTY_ACCESSOR = new JetNodeType("PROPERTY_ACCESSOR");
|
||||
JetNodeType CONSTRUCTOR = new JetNodeType("CONSTRUCTOR");
|
||||
JetNodeType INITIALIZER_LIST = new JetNodeType("INITIALIZER_LIST");
|
||||
JetNodeType THIS_CALL = new JetNodeType("THIS_CALL");
|
||||
JetNodeType BLOCK = new JetNodeType("BLOCK");
|
||||
JetNodeType CLASS_OBJECT = new JetNodeType("CLASS_OBJECT");
|
||||
JetNodeType TYPE_CONSTRAINT_LIST = new JetNodeType("TYPE_CONSTRAINT_LIST");
|
||||
JetNodeType TYPE_CONSTRAINT = new JetNodeType("TYPE_CONSTRAINT");
|
||||
JetNodeType ENUM_ENTRY = new JetNodeType("ENUM_ENTRY");
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetFileType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetChangeUtil {
|
||||
@NotNull
|
||||
public static JetFile createFile(Project project, String text) {
|
||||
return (JetFile) PsiFileFactory.getInstance(project).createFileFromText("dummy.jet", JetFileType.INSTANCE, text, LocalTimeCounter.currentTime(), true);
|
||||
}
|
||||
|
||||
public static JetProperty createProperty(Project project, String name, String type) {
|
||||
JetFile file = createFile(project, "val " + name + (type != null ? ":" + type : ""));
|
||||
JetNamespace rootNamespace = file.getRootNamespace();
|
||||
List<JetDeclaration> dcls = rootNamespace.getDeclarations();
|
||||
assert dcls.size() == 1;
|
||||
return (JetProperty) dcls.get(0);
|
||||
}
|
||||
|
||||
public static PsiElement createNameIdentifier(Project project, String name) {
|
||||
return createProperty(project, name, null).getNameIdentifier();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClass extends JetNamedDeclaration{
|
||||
public JetClass(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
||||
if (body == null) return Collections.emptyList();
|
||||
|
||||
return body.getDeclarations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitClass(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClassBody extends JetElement {
|
||||
public JetClassBody(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
return findChildrenByType(JetNodeTypes.DECLARATIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitClassBody(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClassObject extends JetDeclaration {
|
||||
public JetClassObject(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitClassObject(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetConstructor extends JetDeclaration {
|
||||
public JetConstructor(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitConstructor(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public abstract class JetDeclaration extends JetElement {
|
||||
public JetDeclaration(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetDecomposer extends JetNamedDeclaration {
|
||||
public JetDecomposer(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitDecomposer(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetExtension extends JetNamedDeclaration {
|
||||
public JetExtension(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
||||
if (body == null) return Collections.emptyList();
|
||||
|
||||
return body.getDeclarations();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitExtension(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.intellij.extapi.psi.PsiFileBase;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,4 +29,19 @@ public class JetFile extends PsiFileBase {
|
||||
public String toString() {
|
||||
return "JetFile: " + getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetNamespace getRootNamespace() {
|
||||
return (JetNamespace) getNode().findChildByType(JetNodeTypes.NAMESPACE).getPsi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitJetFile(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitFile(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetFunction extends JetNamedDeclaration {
|
||||
public JetFunction(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitFunction(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetImportDirective extends JetElement {
|
||||
public JetImportDirective(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitImportDirective(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public abstract class JetNamedDeclaration extends JetDeclaration implements PsiNameIdentifierOwner {
|
||||
public JetNamedDeclaration(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
PsiElement identifier = getNameIdentifier();
|
||||
return identifier != null ? identifier.getText() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
return findChildByType(JetTokens.IDENTIFIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetChangeUtil.createNameIdentifier(getProject(), name));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,44 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetNamespace extends JetElement {
|
||||
public class JetNamespace extends JetDeclaration {
|
||||
public JetNamespace(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitNamespace(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
PsiElement body = findChildByType(JetNodeTypes.NAMESPACE_BODY);
|
||||
return PsiTreeUtil.getChildrenOfTypeAsList(body != null ? body : this, JetDeclaration.class);
|
||||
}
|
||||
|
||||
public List<JetImportDirective> getImportDirectives() {
|
||||
PsiElement body = findChildByType(JetNodeTypes.NAMESPACE_BODY);
|
||||
return PsiTreeUtil.getChildrenOfTypeAsList(body != null ? body : this, JetImportDirective.class);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
PsiElement nameNode = findChildByType(JetNodeTypes.NAMESPACE_NAME);
|
||||
return nameNode != null ? nameNode.getText() : "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetProperty extends JetNamedDeclaration {
|
||||
public JetProperty(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitProperty(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetTypedef extends JetNamedDeclaration {
|
||||
public JetTypedef(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JetVisitor) {
|
||||
((JetVisitor) visitor).visitTypedef(this);
|
||||
}
|
||||
else {
|
||||
visitor.visitElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitJetElement(JetElement elem) {
|
||||
visitElement(elem);
|
||||
}
|
||||
|
||||
public void visitDeclaration(JetDeclaration dcl) {
|
||||
visitJetElement(dcl);
|
||||
}
|
||||
|
||||
public void visitNamespace(JetNamespace namespace) {
|
||||
visitDeclaration(namespace);
|
||||
}
|
||||
|
||||
public void visitClass(JetClass klass) {
|
||||
visitDeclaration(klass);
|
||||
}
|
||||
|
||||
public void visitClassObject(JetClassObject classObject) {
|
||||
visitDeclaration(classObject);
|
||||
}
|
||||
|
||||
public void visitConstructor(JetConstructor constructor) {
|
||||
visitDeclaration(constructor);
|
||||
}
|
||||
|
||||
public void visitDecomposer(JetDecomposer decomposer) {
|
||||
visitDeclaration(decomposer);
|
||||
}
|
||||
|
||||
public void visitExtension(JetExtension extension) {
|
||||
visitDeclaration(extension);
|
||||
}
|
||||
|
||||
public void visitFunction(JetFunction fun) {
|
||||
visitDeclaration(fun);
|
||||
}
|
||||
|
||||
public void visitProperty(JetProperty property) {
|
||||
visitDeclaration(property);
|
||||
}
|
||||
|
||||
public void visitTypedef(JetTypedef typedef) {
|
||||
visitDeclaration(typedef);
|
||||
}
|
||||
|
||||
public void visitJetFile(JetFile file) {
|
||||
visitFile(file);
|
||||
}
|
||||
|
||||
public void visitImportDirective(JetImportDirective importDirective) {
|
||||
visitJetElement(importDirective);
|
||||
}
|
||||
|
||||
public void visitClassBody(JetClassBody classBody) {
|
||||
visitJetElement(classBody);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user