polyglot.ast
Class SourceFile_c

java.lang.Object
  extended by polyglot.ast.Node_c
      extended by polyglot.ast.SourceFile_c
All Implemented Interfaces:
java.lang.Cloneable, JL, Node, NodeOps, SourceFile, Copy

public class SourceFile_c
extends Node_c
implements SourceFile

A SourceFile is an immutable representations of a Java langauge source file. It consists of a package name, a list of Imports, and a list of GlobalDecls.


Field Summary
protected  java.util.List decls
           
protected  java.util.List imports
           
protected  ImportTable importTable
           
protected  PackageNode package_
           
protected  Source source
           
 
Fields inherited from class polyglot.ast.Node_c
del, error, ext, position
 
Constructor Summary
SourceFile_c(Position pos, PackageNode package_, java.util.List imports, java.util.List decls)
           
 
Method Summary
 NodeVisitor buildTypesEnter(TypeBuilder tb)
          Build type objects for the source file.
 java.util.List decls()
          Get the declarations of the source file.
 SourceFile decls(java.util.List decls)
          Set the declarations of the source file.
 Node disambiguateOverride(Node parent, AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 void dump(CodeWriter w)
          Dump the AST node for debugging purposes.
 Context enterScope(Context c)
          Build type objects for the source file.
 java.util.List imports()
          Get the imports of the source file.
 SourceFile imports(java.util.List imports)
          Set the imports of the source file.
 ImportTable importTable()
          Get the declarations of the source file.
 SourceFile importTable(ImportTable importTable)
          Set the declarations of the source file.
 boolean isDisambiguated()
           
 PackageNode package_()
          Get the package of the source file.
 SourceFile package_(PackageNode package_)
          Set the package of the source file.
 void prettyPrint(CodeWriter w, PrettyPrinter tr)
          Write the source file to an output file.
protected  SourceFile_c reconstruct(PackageNode package_, java.util.List imports, java.util.List decls)
          Reconstruct the source file.
 Source source()
          Get the source of the source file.
 SourceFile source(Source source)
          Set the source of the source file.
 java.lang.String toString()
           
 Node typeCheck(TypeChecker tc)
          Type check the source file.
 Node visitChildren(NodeVisitor v)
          Visit the children of the source file.
 
Methods inherited from class polyglot.ast.Node_c
addDecls, buildTypes, checkConstants, childExpectedType, copy, del, del, disambiguate, disambiguateEnter, dump, dump, enterChildScope, error, error, exceptionCheck, exceptionCheckEnter, ext, ext, ext, ext, init, isTypeChecked, node, position, position, prettyPrint, prettyPrint, print, printBlock, printSubStmt, throwTypes, translate, typeCheckEnter, typeCheckOverride, visit, visitChild, visitEdge, visitList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface polyglot.ast.Node
childExpectedType, del, del, error, error, ext, ext, ext, ext, isTypeChecked, position, position, visit, visitChild, visitEdge, visitList
 
Methods inherited from interface polyglot.ast.JL
init, node
 
Methods inherited from interface polyglot.ast.NodeOps
addDecls, buildTypes, checkConstants, disambiguate, disambiguateEnter, dump, dump, enterChildScope, exceptionCheck, exceptionCheckEnter, prettyPrint, prettyPrint, throwTypes, translate, typeCheckEnter, typeCheckOverride
 
Methods inherited from interface polyglot.util.Copy
copy
 

Field Detail

package_

protected PackageNode package_

imports

protected java.util.List imports

decls

protected java.util.List decls

importTable

protected ImportTable importTable

source

protected Source source
Constructor Detail

SourceFile_c

public SourceFile_c(Position pos,
                    PackageNode package_,
                    java.util.List imports,
                    java.util.List decls)
Method Detail

isDisambiguated

public boolean isDisambiguated()
Specified by:
isDisambiguated in interface Node
Overrides:
isDisambiguated in class Node_c
Returns:
true if the all type information for the node (but not necessarily for the node's children) is unambiguous.

source

public Source source()
Get the source of the source file.

Specified by:
source in interface SourceFile

source

public SourceFile source(Source source)
Set the source of the source file.

Specified by:
source in interface SourceFile

package_

public PackageNode package_()
Get the package of the source file.

Specified by:
package_ in interface SourceFile

package_

public SourceFile package_(PackageNode package_)
Set the package of the source file.

Specified by:
package_ in interface SourceFile

imports

public java.util.List imports()
Get the imports of the source file.

Specified by:
imports in interface SourceFile
Returns:
A list of Import.

imports

public SourceFile imports(java.util.List imports)
Set the imports of the source file.

Specified by:
imports in interface SourceFile
Parameters:
imports - A list of Import.

decls

public java.util.List decls()
Get the declarations of the source file.

Specified by:
decls in interface SourceFile
Returns:
A list of TopLevelDecl.

decls

public SourceFile decls(java.util.List decls)
Set the declarations of the source file.

Specified by:
decls in interface SourceFile
Parameters:
decls - A list of TopLevelDecl.

importTable

public ImportTable importTable()
Get the declarations of the source file.

Specified by:
importTable in interface SourceFile

importTable

public SourceFile importTable(ImportTable importTable)
Set the declarations of the source file.

Specified by:
importTable in interface SourceFile

reconstruct

protected SourceFile_c reconstruct(PackageNode package_,
                                   java.util.List imports,
                                   java.util.List decls)
Reconstruct the source file.


visitChildren

public Node visitChildren(NodeVisitor v)
Visit the children of the source file.

Specified by:
visitChildren in interface NodeOps
Overrides:
visitChildren in class Node_c
Parameters:
v - The visitor that will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

buildTypesEnter

public NodeVisitor buildTypesEnter(TypeBuilder tb)
                            throws SemanticException
Build type objects for the source file. Set the visitor's import table field before we recurse into the declarations.

Specified by:
buildTypesEnter in interface NodeOps
Overrides:
buildTypesEnter in class Node_c
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

enterScope

public Context enterScope(Context c)
Build type objects for the source file. Sets the import table field for the source. public Node buildTypes(TypeBuilder tb) throws SemanticException { ImportTable it = tb.importTable(); // Clear the import table in case we use the same visitor // to visit a different source file. tb.setImportTable(null); return importTable(it); }

Specified by:
enterScope in interface NodeOps
Overrides:
enterScope in class Node_c
Parameters:
c - the current Context
Returns:
the Context to be used for visiting this node.

typeCheck

public Node typeCheck(TypeChecker tc)
               throws SemanticException
Type check the source file.

Specified by:
typeCheck in interface NodeOps
Overrides:
typeCheck in class Node_c
Throws:
SemanticException

toString

public java.lang.String toString()
Overrides:
toString in class Node_c

prettyPrint

public void prettyPrint(CodeWriter w,
                        PrettyPrinter tr)
Write the source file to an output file.

Specified by:
prettyPrint in interface NodeOps
Overrides:
prettyPrint in class Node_c
Parameters:
w - The code writer to which to write.
tr - The pretty printer. This is not a visitor.

disambiguateOverride

public Node disambiguateOverride(Node parent,
                                 AmbiguityRemover ar)
                          throws SemanticException
Description copied from interface: NodeOps
Remove any remaining ambiguities from the AST. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
disambiguateOverride in interface NodeOps
Overrides:
disambiguateOverride in class Node_c
Parameters:
parent -
ar -
Throws:
SemanticException

dump

public void dump(CodeWriter w)
Description copied from interface: Node
Dump the AST node for debugging purposes.

Specified by:
dump in interface Node
Overrides:
dump in class Node_c