CompilationUnitTree.java revision 2571:10fc81ac75b4
178189Sbrian/*
278189Sbrian * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
378189Sbrian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
478189Sbrian *
578189Sbrian * This code is free software; you can redistribute it and/or modify it
66756Samurai * under the terms of the GNU General Public License version 2 only, as
778189Sbrian * published by the Free Software Foundation.  Oracle designates this
878189Sbrian * particular file as subject to the "Classpath" exception as provided
978189Sbrian * by Oracle in the LICENSE file that accompanied this code.
1078189Sbrian *
1178189Sbrian * This code is distributed in the hope that it will be useful, but WITHOUT
1278189Sbrian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1378189Sbrian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1478189Sbrian * version 2 for more details (a copy is included in the LICENSE file that
156756Samurai * accompanied this code).
1678189Sbrian *
1778189Sbrian * You should have received a copy of the GNU General Public License version
1878189Sbrian * 2 along with this work; if not, write to the Free Software Foundation,
1978189Sbrian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2078189Sbrian *
2178189Sbrian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2278189Sbrian * or visit www.oracle.com if you need additional information or have any
2378189Sbrian * questions.
2478189Sbrian */
2578189Sbrian
2678189Sbrianpackage com.sun.source.tree;
276756Samurai
2850479Speterimport java.util.List;
296756Samuraiimport javax.tools.JavaFileObject;
306756Samurai
3136285Sbrian/**
3236285Sbrian * Represents the abstract syntax tree for compilation units (source
3343693Sbrian * files) and package declarations (package-info.java).
3443693Sbrian *
356756Samurai * @jls sections 7.3, and 7.4
366756Samurai *
3743693Sbrian * @author Peter von der Ahé
3843693Sbrian * @since 1.6
3943693Sbrian */
4043693Sbrian@jdk.Exported
4143693Sbrianpublic interface CompilationUnitTree extends Tree {
4243693Sbrian    /**
4343693Sbrian     * Returns the annotations listed on any package declaration
4443693Sbrian     * at the head of this compilation unit, or {@code null} if there
4543693Sbrian     * is no package declaration.
466756Samurai     * @return the package annotations
476756Samurai     */
486756Samurai    List<? extends AnnotationTree> getPackageAnnotations();
4936285Sbrian
5036285Sbrian    /**
5144305Sbrian     * Returns the name contained in any package declaration
5236285Sbrian     * at the head of this compilation unit, or {@code null} if there
536756Samurai     * is no package declaration.
546756Samurai     * @return the package name
5543693Sbrian     */
5643693Sbrian    ExpressionTree getPackageName();
5743693Sbrian
5844106Sbrian    /**
5943693Sbrian     * Returns the package tree associated with this compilation unit,
6043693Sbrian     * or {@code null} if there is no package declaration.
6136285Sbrian     * @return the package tree
6243693Sbrian     * @since 1.9
6336285Sbrian     */
6436285Sbrian    PackageTree getPackage();
6536285Sbrian
6636285Sbrian    /**
6738174Sbrian     * Returns the import declarations appearing in this compilation unit.
6838174Sbrian     * @return the import declarations
6943693Sbrian     */
7043693Sbrian    List<? extends ImportTree> getImports();
71
72    /**
73     * Returns the type declarations appearing in this compilation unit.
74     * The list may also include empty statements resulting from
75     * extraneous semicolons.
76     * @return the type declarations
77     */
78    List<? extends Tree> getTypeDecls();
79
80    /**
81     * Returns the file object containing the source for this compilation unit.
82     * @return the file object
83     */
84    JavaFileObject getSourceFile();
85
86    /**
87     * Returns the line map for this compilation unit, if available.
88     * Returns {@code null} if the line map is not available.
89     * @return the line map for this compilation unit
90     */
91    LineMap getLineMap();
92}
93