diff options
author | paltherr <paltherr@epfl.ch> | 2003-04-14 14:26:02 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-04-14 14:26:02 +0000 |
commit | e38818336a932006340aca4bb3579e875b291689 (patch) | |
tree | a50d7eaba16a412a0cbe294a6d1a501cbc58a9a4 /sources/meta/scalac | |
parent | 0aa5643808efec65ae5fccbd40fc97bebf0de526 (diff) | |
download | scala-e38818336a932006340aca4bb3579e875b291689.tar.gz scala-e38818336a932006340aca4bb3579e875b291689.tar.bz2 scala-e38818336a932006340aca4bb3579e875b291689.zip |
- Added Phase.java
- Added Tree.java
- Added TreeField.java
- Added TreeKind.java
- Added TreeNode.java
- Added TreeSymbol.java
- Added TreeType.java
Diffstat (limited to 'sources/meta/scalac')
-rw-r--r-- | sources/meta/scalac/Phase.java | 45 | ||||
-rw-r--r-- | sources/meta/scalac/ast/Tree.java | 364 | ||||
-rw-r--r-- | sources/meta/scalac/ast/TreeField.java | 38 | ||||
-rw-r--r-- | sources/meta/scalac/ast/TreeKind.java | 63 | ||||
-rw-r--r-- | sources/meta/scalac/ast/TreeNode.java | 144 | ||||
-rw-r--r-- | sources/meta/scalac/ast/TreeSymbol.java | 27 | ||||
-rw-r--r-- | sources/meta/scalac/ast/TreeType.java | 66 |
7 files changed, 747 insertions, 0 deletions
diff --git a/sources/meta/scalac/Phase.java b/sources/meta/scalac/Phase.java new file mode 100644 index 0000000000..eeeb32aa58 --- /dev/null +++ b/sources/meta/scalac/Phase.java @@ -0,0 +1,45 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac; + +/** A representation for Scala compiler phases. */ +public class Phase { + + //######################################################################## + // Public Constants + + public static final Phase + START = new Phase("start", null), + PARSER = new Phase("parser", "PARSER"), + ANALYZER = new Phase("analyzer", "ANALYZER"), + DESUGARIZER = new Phase("desugarizer", "ANALYZER"), + UNCURRY = new Phase("uncurry", "UNCURRY"), + LAMBDALIFT = new Phase("lambdalift", "LAMBDALIFT"), + TRANSMATCH = new Phase("transmatch", "TRANSMATCH"), + OPTIMIZER = new Phase("optimizer", null), // !!! "OPTIMIZE" + ERASURE = new Phase("erasure", "ERASURE"), + UNKNOWN = new Phase("? !!!", null), + END = new Phase("-", null); + + //######################################################################## + // Public Fields + + public final String name; + public final String constant; + + //######################################################################## + // Public Constructors + + public Phase(String name, String constant) { + this.name = name; + this.constant = constant; + } + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java new file mode 100644 index 0000000000..de209f803f --- /dev/null +++ b/sources/meta/scalac/ast/Tree.java @@ -0,0 +1,364 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +import java.util.List; +import java.util.ArrayList; + +import meta.java.Type; +import meta.scalac.Phase; + +/** This class describes all tree nodes. */ +public class Tree { + + //######################################################################## + // Public Constants + + public static final String PACKAGE = "scalac.ast"; + public static final String NAME = "Tree"; + + //######################################################################## + // Private Constants + + private static final TreeKind Any = TreeKind.Any; + private static final TreeKind Type = TreeKind.Type; + private static final TreeKind Term = TreeKind.Term; + private static final TreeKind Dual = TreeKind.Dual; + private static final TreeKind Test = TreeKind.Test; + private static final TreeKind None = TreeKind.None; + + private static final TreeSymbol NoSym = TreeSymbol.NoSym; + private static final TreeSymbol HasSym = TreeSymbol.HasSym; + private static final TreeSymbol DefSym = TreeSymbol.DefSym; + + private final List list = new ArrayList(); + + //######################################################################## + // Public Constants + + public final TreeNode + n_Bad = node("Bad" , Any , HasSym), + n_Empty = node("Empty" , Any , NoSym), + n_ClassDef = node("ClassDef" , None, DefSym), + n_PackageDef = node("PackageDef" , None, NoSym), + n_ModuleDef = node("ModuleDef" , None, DefSym), + n_ValDef = node("ValDef" , None, DefSym), + n_PatDef = node("PatDef" , None, NoSym), + n_DefDef = node("DefDef" , None, DefSym), + n_TypeDef = node("TypeDef" , None, DefSym), + n_Import = node("Import" , None, HasSym), + n_CaseDef = node("CaseDef" , None, NoSym), + n_Template = node("Template" , None, HasSym), // !!! HasSym + n_LabelDef = node("LabelDef" , Term, DefSym), + n_Block = node("Block" , Term, NoSym), + n_Tuple = node("Tuple" , Term, NoSym), + n_Visitor = node("Visitor" , Term, NoSym), + n_Function = node("Function" , Term, NoSym), + n_Assign = node("Assign" , Term, NoSym), + n_If = node("If" , Term, NoSym), + n_New = node("New" , Term, NoSym), + n_Typed = node("Typed" , Term, NoSym), + n_TypeApply = node("TypeApply" , Term, NoSym), + n_Apply = node("Apply" , Term, NoSym), + n_Super = node("Super" , Term, NoSym), + n_This = node("This" , Term, NoSym), + n_Select = node("Select" , Test, HasSym), + n_Ident = node("Ident" , Test, HasSym), + n_Literal = node("Literal" , Term, NoSym), + n_TypeTerm = node("TypeTerm" , Type, NoSym), + n_SingletonType = node("SingletonType" , Type, NoSym), + n_SelectFromType = node("SelectFromType", Type, HasSym), + n_FunType = node("FunType" , Type, NoSym), + n_CompoundType = node("CompoundType" , Type, NoSym), + n_AppliedType = node("AppliedType" , Type, NoSym), + n_CovariantType = node("CovariantType" , Type, NoSym); + + public final TreeNode[] nodes; + + public final Type + t_int = TreeType.INT, + t_Object = TreeType.Reference(null, "Object"), + t_Global = TreeType.Reference("scalac", "Global"), + t_Unit = TreeType.Reference("scalac", "Unit"), + t_TreeGen = TreeType.Reference("scalac.ast", "TreeGen"), + t_Symbol = TreeType.Reference("scalac.symtab", "Symbol"), + t_Type = TreeType.Reference("scalac.symtab", "Type"), + t_Debug = TreeType.Reference("scalac.util", "Debug"), + t_Name = TreeType.Name(Any), + t_TypeName = TreeType.Name(Type), + t_TermName = TreeType.Name(Term), + t_TestName = TreeType.Name(Test), + t_Names = TreeType.Array(t_Name), + t_Tree = TreeType.Tree(Any), + t_TypeTree = TreeType.Tree(Type), + t_TermTree = TreeType.Tree(Term), + t_Trees = TreeType.Array(t_Tree), + t_TypeTrees = TreeType.Array(t_TypeTree), + t_TermTrees = TreeType.Array(t_TermTree), + t_Treess = TreeType.Array(t_Trees), + t_ValDef = n_ValDef.getType(0), + t_ValDefs = n_ValDef.getType(1), + t_ValDefss = n_ValDef.getType(2), + t_TypeDef = n_TypeDef.getType(0), + t_TypeDefs = n_TypeDef.getType(1), + t_Template = n_Template.getType(0), + t_CaseDef = n_CaseDef.getType(0), + t_CaseDefs = n_CaseDef.getType(1), + t_Ident = n_Ident.getType(0), + t_Idents = n_Ident.getType(1); + + //######################################################################## + // Public Constructors + + public Tree() { + nodes = (TreeNode[])list.toArray(new TreeNode[list.size()]); + + n_Bad. + setDescription("Representation for parser errors"). + setRange(Phase.PARSER, Phase.END); + + n_Empty. + setDescription("A tree node for the absence of a tree"). + setRange(Phase.PARSER, Phase.UNKNOWN). + noFields(); + + n_ClassDef. + setDescription("Class and data declaration"). + setRange(Phase.PARSER, Phase.END). + addField(t_int, "mods"). + addField(t_TypeName, "name"). + addField(t_TypeDefs, "tparams"). + addField(t_ValDefss, "vparams"). + addField(t_TypeTree, "tpe"). + addField(t_Template, "impl"); + + n_PackageDef. + setDescription("Package declaration"). + setRange(Phase.PARSER, Phase.UNKNOWN). + addField(t_TermTree, "packaged"). + addField(t_Template, "impl"); + + n_ModuleDef. + setDescription("Module declaration"). + setRange(Phase.PARSER, Phase.UNKNOWN). + addField(t_int, "mods"). + addField(t_TermName, "name"). + addField(t_TypeTree, "tpe"). + addField(t_Template, "impl"); + + n_ValDef. + setDescription("Value declaration (var or let)"). + setRange(Phase.PARSER, Phase.END). + addField(t_int, "mods"). + addField(t_TermName, "name"). + addField(t_TypeTree, "tpe"). + addField(t_TermTree, "rhs"); + + + n_PatDef. + setDescription("Value declaration with patterns (val)"). + setRange(Phase.PARSER, Phase.DESUGARIZER). + addField(t_int, "mods"). + addField(t_TermTree, "pat"). + addField(t_TermTree, "rhs"); + + n_DefDef. + setDescription("Function declaration (def)"). + setRange(Phase.PARSER, Phase.END). + addField(t_int, "mods"). + addField(t_TermName, "name"). + addField(t_TypeDefs, "tparams"). + addField(t_ValDefss, "vparams"). + addField(t_TypeTree, "tpe"). + addField(t_TermTree, "rhs"); + + n_TypeDef. + setDescription("Type declaration"). + setRange(Phase.PARSER, Phase.ERASURE). // !!! could/should be removed earlier?) + addField(t_int, "mods"). + addField(t_TypeName, "name"). + addField(t_TypeTree, "rhs"); + + n_Import. + setDescription("Import declaration"). + setRange(Phase.START, Phase.ANALYZER). + addField(t_TermTree, "expr"). + addField(t_Names, "selectors"); + + n_CaseDef. + setDescription("Case declaration"). + setRange(Phase.PARSER, Phase.UNKNOWN). + addField(t_TermTree, "pat"). + addField(t_TermTree, "guard"). + addField(t_TermTree, "body"); + + n_Template. + setDescription("Instantiation templates"). + setRange(Phase.PARSER, Phase.END). + addField(t_TermTrees, "parents"). + addField(t_Trees, "body"); + + n_LabelDef. + setDescription("Labelled expression - the symbols in the array (must be Idents!) are those the label takes as argument"). + setRange(Phase.OPTIMIZER, Phase.END). + addField(t_TermTrees, "params"). // !!! shoudl be t_Idents + addField(t_TermTree, "rhs"); + + n_Block. + setDescription("Block of expressions " + + "(semicolon separated expressions)"). + setRange(Phase.PARSER, Phase.END). + addField(t_Trees, "stats"); + + n_Tuple. + setDescription("Tuple of expressions (comma separated expressions)"). + setRange(Phase.UNCURRY, Phase.LAMBDALIFT). + addField(t_TermTrees, "trees"); + + n_Visitor. + setDescription("Visitor (a sequence of cases)"). + setRange(Phase.PARSER, Phase.TRANSMATCH). + addField(t_CaseDefs, "cases"); + + + n_Function. + setDescription("Anonymous function"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_ValDefs, "vparams"). + addField(t_TermTree, "body"); + + n_Assign. + setDescription("Assignment"). + setRange(Phase.PARSER, Phase.END). + addField(t_TermTree, "lhs"). + addField(t_TermTree, "rhs"); + + n_If. + setDescription("Conditional expression"). + setRange(Phase.PARSER, Phase.END). + addField(t_TermTree, "cond"). + addField(t_TermTree, "thenp"). + addField(t_TermTree, "elsep"); + + n_New. + setDescription("Instantiation"). + setRange(Phase.PARSER, Phase.END). + addField(t_Template, "templ"); + + n_Typed. + setDescription("Type annotation"). + setRange(Phase.PARSER, Phase.UNKNOWN). // !!! could be removed by analyzer? + addField(t_TermTree, "expr"). + addField(t_TypeTree, "tpe"); + + + n_TypeApply. + setDescription("Type application"). + setRange(Phase.PARSER, Phase.END). + addField(t_TermTree, "fun"). + addField(t_TypeTrees, "args"); + + n_Apply. + setDescription("Value application"). + setRange(Phase.PARSER, Phase.END). + addField(t_Tree, "fun"). // !!! should be t_TermTree + addField(t_TermTrees, "args"); + + n_Super. + setDescription("Super reference"). + setRange(Phase.PARSER, Phase.END). + addField(t_TypeTree, "tpe"); + + n_This. + setDescription("Self reference"). + setRange(Phase.PARSER, Phase.END). + addField(t_TypeTree, "qualifier"); + + n_Select. + setDescription("Designator"). + setRange(Phase.START, Phase.END). + addField(t_TermTree, "qualifier"). + addField(t_TestName, "selector"); + + n_Ident. + setDescription("Identifier"). + setRange(Phase.START, Phase.END). + addField(t_TestName, "name"); + + n_Literal. + setDescription("Literal"). + setRange(Phase.PARSER, Phase.END). + addField(t_Object, "value"); + + n_TypeTerm. + setDescription("TypeTerm"). + setRange(Phase.PARSER, Phase.END); + + n_SingletonType. + setDescription("Singleton type"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TermTree, "ref"); + + n_SelectFromType. + setDescription("Type selection"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TypeTree, "qualifier"). + addField(t_TypeName, "selector"); + + n_FunType. + setDescription("Function type"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TypeTrees, "argtpes"). + addField(t_TypeTree, "restpe"); + + n_CompoundType. + setDescription("Object type (~ Template)"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TypeTrees, "parents"). + addField(t_Trees, "refinements"); + + n_AppliedType. + setDescription("Applied type"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TypeTree, "tpe"). + addField(t_TypeTrees, "args"); + + n_CovariantType. + setDescription("Covariant type"). + setRange(Phase.PARSER, Phase.ANALYZER). + addField(t_TypeTree, "tpe"); + + } + + //######################################################################## + // Public Functions + + public static boolean isTree(Type type) { + switch (type) { + case Array(Type item): + return isTree(item); + case TreeType.Tree(_): + case TreeType.Node(_): + return true; + default: + return false; + } + } + + //######################################################################## + // Private Methods + + private TreeNode node(String name, TreeKind kind, TreeSymbol symbol) { + TreeNode node = new TreeNode(name, kind, symbol); + list.add(node); + return node; + } + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/TreeField.java b/sources/meta/scalac/ast/TreeField.java new file mode 100644 index 0000000000..9944e4178b --- /dev/null +++ b/sources/meta/scalac/ast/TreeField.java @@ -0,0 +1,38 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +import meta.java.Type; + +/** This class describes a tree node field. */ +public class TreeField { + + //######################################################################## + // Public Fields + + public final Type type; + public final String name; + + //######################################################################## + // Public Constructors + + public TreeField(Type type, String name) { + this.type = type; + this.name = name; + } + + //######################################################################## + // Public Methods + + public String toString() { + return name; + } + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/TreeKind.java b/sources/meta/scalac/ast/TreeKind.java new file mode 100644 index 0000000000..35dcd0dd55 --- /dev/null +++ b/sources/meta/scalac/ast/TreeKind.java @@ -0,0 +1,63 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +/** This class enumerates the different kinds of tree nodes. */ +public class TreeKind { + + //######################################################################## + // Public Cases + + /** Designates a type, a term or anything else. */ + public case Any; + + /** Designates a type. */ + public case Type; + + /** Designates a term. */ + public case Term; + + /** Designates either a type or a term. */ + public case Dual; + + /** Designates either a type or a term (a test may indicate which one). */ + public case Test; + + /** Designates neither a type nor a term. */ + public case None; + + //######################################################################## + // Public Method + + public boolean isA(TreeKind that) { + switch (this) { + case Any : return true; + case Type: return that == Type; + case Term: return that == Term; + case Dual: return that == Type || that == Term || that == Dual; + case Test: return that == Type || that == Term || that == Dual; + case None: return that == None; + default : throw new Error(); + } + } + + public String toString() { + switch(this) { + case Any : return "Any"; + case Type: return "Type"; + case Term: return "Term"; + case Dual: return "Dual"; + case Test: return "Test"; + case None: return "None"; + default : throw new Error(); + } + } + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/TreeNode.java b/sources/meta/scalac/ast/TreeNode.java new file mode 100644 index 0000000000..514a9b058c --- /dev/null +++ b/sources/meta/scalac/ast/TreeNode.java @@ -0,0 +1,144 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +import meta.java.Type; +import meta.java.JavaWriter; +import meta.scalac.Phase; + +/** This class describes a tree node. */ +public class TreeNode { + + //######################################################################## + // Public Fields + + public final String name; + public final TreeKind kind; + public final TreeSymbol symbol; + public String description; + public Phase start; + public Phase stop; + public TreeField[] fields; + public int arrays; + + //######################################################################## + // Public Constructors + + public TreeNode(String name, TreeKind kind, TreeSymbol symbol) { + this(name, kind, symbol, new TreeField[0]); + } + + public TreeNode(String name, TreeKind kind, TreeSymbol symbol, + TreeField[] fields) + { + this.name = name; + this.kind = kind; + this.symbol = symbol; + this.fields = fields; + } + + //######################################################################## + // Public Methods + + public boolean hasExtClass() { + return hasSymbol(); + } + + public boolean hasSymbol() { + return symbol == symbol.HasSym || symbol == symbol.DefSym; + } + + public boolean definesSymbol() { + return symbol == symbol.DefSym; + } + + public Type getType(int rank) { + arrays = Math.max(arrays , rank); + return rank == 0 ? TreeType.Node(this) : Type.Array(getType(rank - 1)); + } + + public TreeNode setDescription(String description) { + this.description = description; + return this; + } + + public TreeNode setRange(Phase start, Phase stop) { + this.start = start; + this.stop = stop; + return this; + } + + public TreeNode noFields() { + fields = null; + return this; + } + + public TreeNode addField(Type type, String name) { + TreeField[] array = new TreeField[fields.length + 1]; + for (int i = 0; i < fields.length; i++) array[i] = fields[i]; + array[fields.length] = new TreeField(type, name); + fields = array; + return this; + } + + public JavaWriter printCase(JavaWriter writer, boolean wildcards) { + writer.print("case ").print(name); + if (fields!=null) printParams(writer.print("("),wildcards).print(")"); + return writer.print(":").space(); + } + + public JavaWriter printParams(JavaWriter writer) { + return printParams(writer, false); + } + + public JavaWriter printParams(JavaWriter writer, String prefix) { + return printParams(printPrefix(writer, prefix)); + } + + public JavaWriter printParams(JavaWriter writer, boolean wildcards) { + if (fields != null) for (int i = 0; i < fields.length; i++) { + if (i > 0) writer.print(", "); + if (wildcards) writer.print("_"); + else writer.print(fields[i].type).space().print(fields[i].name); + } + return writer; + } + + public JavaWriter printArgs(JavaWriter writer) { + if (fields != null) for (int i = 0; i < fields.length; i++) { + if (i > 0) writer.print(", "); + writer.print(fields[i].name); + } + return writer; + } + + public JavaWriter printArgs(JavaWriter writer, String prefix) { + return printArgs(printPrefix(writer, prefix)); + } + + public JavaWriter printPrefix(JavaWriter writer, String prefix) { + if (prefix != null) { + writer.print(prefix); + if (fields != null && fields.length > 0 && prefix != null) + writer.print(", "); + } + return writer; + } + + public JavaWriter printNew(JavaWriter writer) { + String classname = (hasExtClass() ? "Ext" : "") + name; + return printArgs(writer.print("new " + classname + "(")).print(")"); + } + + public String toString() { + return name; + } + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/TreeSymbol.java b/sources/meta/scalac/ast/TreeSymbol.java new file mode 100644 index 0000000000..8040239800 --- /dev/null +++ b/sources/meta/scalac/ast/TreeSymbol.java @@ -0,0 +1,27 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +/** This class describes the symbol stored in some tree nodes. */ +public class TreeSymbol { + + //######################################################################## + // Public Cases + + /** Indicates the absence of symbol. */ + public case NoSym; + + /** Indicates the presence of a symbol. */ + public case HasSym; + + /** Indicates the presence of a symbol that is define here. */ + public case DefSym; + + //######################################################################## +} diff --git a/sources/meta/scalac/ast/TreeType.java b/sources/meta/scalac/ast/TreeType.java new file mode 100644 index 0000000000..f15e7ec676 --- /dev/null +++ b/sources/meta/scalac/ast/TreeType.java @@ -0,0 +1,66 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package meta.scalac.ast; + +import meta.java.Type; + +/** This class describes types used in tree nodes. */ +public class TreeType extends Type { + + //######################################################################## + // Public Constants + + // !!! + public static final String NAME_PACKAGE = "scalac.util"; + public static final String NAME_NAME = "Name"; + public static final String NAME_FULLNAME = NAME_PACKAGE + "." + NAME_NAME; + public static final String TREE_PACKAGE = meta.scalac.ast.Tree.PACKAGE; + public static final String TREE_NAME = meta.scalac.ast.Tree.NAME; + public static final String TREE_FULLNAME = TREE_PACKAGE + "." + TREE_NAME; + + //######################################################################## + // Public Cases + + public case Name(TreeKind kind); + public case Tree(TreeKind kind); + public case Node(TreeNode node); + + //######################################################################## + // Public Methods + + /** Returns the type's (possibly fully qualified) name. */ + public String getName(boolean qualified) { + switch (this) { + case Name(_): + return qualified ? NAME_FULLNAME : NAME_NAME; + case Tree(_): + return qualified ? TREE_FULLNAME : TREE_NAME; + case Node(TreeNode node): + return qualified ? TREE_FULLNAME + "." + node.name : node.name; + default: + return super.getName(qualified); + } + } + + /** Returns the type's owner (its package or enclosing type). */ + public String getOwner() { + switch (this) { + case Name(_): + return NAME_PACKAGE; + case Tree(_): + return TREE_PACKAGE; + case Node(TreeNode node): + return TREE_FULLNAME; + default: + return super.getOwner(); + } + } + + //######################################################################## +} |