001: package spoon.reflect.cu;
002:
003: import java.io.File;
004: import java.util.List;
005: import java.util.Set;
006:
007: import spoon.processing.FactoryAccessor;
008: import spoon.reflect.declaration.CtSimpleType;
009:
010: /**
011: * Defines a compilation unit. In Java, a compilation unit can contain only one
012: * public type declaration and other secondary types declarations (not public).
013: */
014: public interface CompilationUnit extends FactoryAccessor {
015:
016: /**
017: * Gets the file that corresponds to this compilation unit if any (contains
018: * the source code).
019: */
020: File getFile();
021:
022: /**
023: * Sets the file that corresponds to this compilation unit.
024: */
025: void setFile(File file);
026:
027: /**
028: * Gets all the types declared in this compilation unit.
029: */
030: List<CtSimpleType<?>> getDeclaredTypes();
031:
032: /**
033: * Sets the types declared in this compilation unit.
034: */
035: void setDeclaredTypes(List<CtSimpleType<?>> types);
036:
037: /**
038: * Searches and returns the main type (the type which has the same name as
039: * the file).
040: */
041: CtSimpleType<?> getMainType();
042:
043: /**
044: * Add a source code fragment to this compilation unit.
045: */
046: void addSourceCodeFragment(SourceCodeFragment fragment);
047:
048: /**
049: * Gets the source code fragments for this compilation unit.
050: */
051: List<SourceCodeFragment> getSourceCodeFraments();
052:
053: /**
054: * Gets the original source code as a string.
055: */
056: String getOriginalSourceCode();
057:
058: /**
059: * Helper method to get the begin index of the line that corresponds to the
060: * given index.
061: *
062: * @param index
063: * an arbitrary index in the source code
064: * @return the index where the line starts
065: */
066: int beginOfLineIndex(int index);
067:
068: /**
069: * Helper method to get the begin index of the line that corresponds to the
070: * next line of the given index.
071: *
072: * @param index
073: * an arbitrary index in the source code
074: * @return the index where the next line starts
075: */
076: int nextLineIndex(int index);
077:
078: /**
079: * Gets the number of tabulations for a given line.
080: *
081: * @param index
082: * the index where the line starts in the source code
083: * @return the number of tabs for this line
084: */
085: int getTabCount(int index);
086:
087: /**
088: * Sets this compilation unit auto-import feature on or off (default is on).
089: * Note that setting off auto-import is not recommended as it can lead to
090: * unresolved references in the generated code.
091: *
092: * @see #getManualImports()
093: * @see #setManualImports(Set)
094: */
095: void setAutoImport(boolean autoImport);
096:
097: /**
098: * Tells if this compilation unit auto-import feature is on or off (default
099: * is on).
100: *
101: * @see #getManualImports()
102: * @see #setManualImports(Set)
103: */
104: boolean isAutoImport();
105:
106: /**
107: * Gets the imports to be forced by this compilation unit when the
108: * auto-import is off. This set can be modified and will impact the imports.
109: *
110: * @see #isAutoImport()
111: * @see #setAutoImport(boolean)
112: */
113: Set<Import> getManualImports();
114:
115: /**
116: * Sets the imports to be forced by this compilation unit when the
117: * auto-import is off.
118: *
119: * @see #isAutoImport()
120: * @see #setAutoImport(boolean)
121: */
122: void setManualImports(Set<Import> manualImports);
123:
124: }
|