RECODER 0.92

recoder.kit
Class UnitKit

java.lang.Object
  extended by recoder.kit.UnitKit

public class UnitKit
extends java.lang.Object


Method Summary
static Import appendImport(ChangeHistory ch, CompilationUnit cu, ClassType ct)
          Transformation that appends an import specification for the given class type.
static Import appendImport(ChangeHistory ch, CompilationUnit cu, java.lang.String typeName)
          Deprecated. should become a fully grown transformation.
static void assertPartOf(ProgramElement pe, java.util.List<CompilationUnit> cu)
          Query that checks if pe is reachable in the AST of CompilationUnit cu.
static Import ensureImport(ChangeHistory ch, SourceInfo si, java.lang.String typeName, ProgramElement context)
          Deprecated. needs further testing - use at your own risks
static void ensureImports(ChangeHistory ch, SourceInfo si, ProgramElement root)
          Deprecated. needs further testing - use at your own risks
static CompilationUnit getCompilationUnit(ProgramElement p)
          Query that returns the compilation unit which the given program element is located in.
static java.util.List<Import> getUnnecessaryImports(CrossReferenceSourceInfo xrsi, CompilationUnit cu)
          Query that finds all unnecessary import specifications in a compilation unit.
static void normalizeImports(ChangeHistory ch, CrossReferenceSourceInfo xrsi, CompilationUnit cu, boolean removeMultiTypeImports, boolean removeSingleTypeImports, boolean addJavaLangImports, boolean addDefaultPackageImports)
          Deprecated. should become a fully grown transformation.
static void removeUnusedImports(ChangeHistory ch, CrossReferenceSourceInfo xrsi, CompilationUnit cu)
          Deprecated. should become a first class transformation.
static void sortImports(ChangeHistory ch, CompilationUnit cu)
          sort imports lexically and insert one blank line between different top level names !!!!!!!!!!!!!!!!!!!!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCompilationUnit

public static CompilationUnit getCompilationUnit(ProgramElement p)
Query that returns the compilation unit which the given program element is located in. Returns null, if the element is null or not a part of a compilation unit. If the element is already a compilation unit, the element is returned.

Parameters:
p - a program element.
Returns:
the compilation unit of the given element, or null.

assertPartOf

public static void assertPartOf(ProgramElement pe,
                                java.util.List<CompilationUnit> cu)
Query that checks if pe is reachable in the AST of CompilationUnit cu. Useful, e.g., for debugging, to ensure that links are set correctly during transformations.

Parameters:
p -
cu -
Since:
0.90 TODO 0.90 update doc

getUnnecessaryImports

public static java.util.List<Import> getUnnecessaryImports(CrossReferenceSourceInfo xrsi,
                                                           CompilationUnit cu)
Query that finds all unnecessary import specifications in a compilation unit. Single type imports are considered unnecessary if no reference to the imported type occurs in the unit. There might be fully qualified references only, such that the import would be unused in fact, but this does not seem worthwhile to check. A wildcarded import is considered unused if the only types with the given prefixes are imported by corresponding single type imports. Static imports are not considered yet, which is a TODO

Parameters:
xrsi - the cross reference source info to use.
cu - the compilation unit to find unnecessary imports in.
Returns:
a list of unnecessary imports in the unit.

removeUnusedImports

public static void removeUnusedImports(ChangeHistory ch,
                                       CrossReferenceSourceInfo xrsi,
                                       CompilationUnit cu)
Deprecated. should become a first class transformation.


normalizeImports

public static void normalizeImports(ChangeHistory ch,
                                    CrossReferenceSourceInfo xrsi,
                                    CompilationUnit cu,
                                    boolean removeMultiTypeImports,
                                    boolean removeSingleTypeImports,
                                    boolean addJavaLangImports,
                                    boolean addDefaultPackageImports)
Deprecated. should become a fully grown transformation.


appendImport

public static Import appendImport(ChangeHistory ch,
                                  CompilationUnit cu,
                                  ClassType ct)
Transformation that appends an import specification for the given class type. This method does not check whether the import is needed or redundant.

Parameters:
ch - the change history to notify (may be null).
cu - the unit to create the import for.
ct - the class type to create the import for.
Returns:
the new import.

appendImport

public static Import appendImport(ChangeHistory ch,
                                  CompilationUnit cu,
                                  java.lang.String typeName)
Deprecated. should become a fully grown transformation.

Transformation that appends an import specification for the given class type. This method does not check whether the import is needed or redundant.

Parameters:
ch - the change history to notify (may be null).
cu - the unit to create the import for.
typeName - the class type name to create the import for.
Returns:
the new import.

ensureImport

public static Import ensureImport(ChangeHistory ch,
                                  SourceInfo si,
                                  java.lang.String typeName,
                                  ProgramElement context)
Deprecated. needs further testing - use at your own risks

Transformation that ensures that the given class type is known at the given location by importing it on demand. If the type is already known, null is returned, otherwise the new import specification that imports the type directly.

Parameters:
ch - the change history to report to (may be null).
si - the source info service.
typeName - the fully qualified name of the type to be known at the unit level.
context - the context in which the type should be known.
Returns:
a new import specification as added to the compilation unit, or null if no new import was needed.

ensureImports

public static void ensureImports(ChangeHistory ch,
                                 SourceInfo si,
                                 ProgramElement root)
Deprecated. needs further testing - use at your own risks

Transformation that ensures that all type references in the given subtree are resolvable by importing the corresponding types on demand.

Parameters:
ch - the change history to report to (may be null).
si - the source info service.
root - the root element in a subtree containing type references to check.

sortImports

public static void sortImports(ChangeHistory ch,
                               CompilationUnit cu)
sort imports lexically and insert one blank line between different top level names !!!!!!!!!!!!!!!!!!!! untested !!!!!!!!!!!!!!!


RECODER 0.92