Dresden OCL Toolkit

tudresden.ocl.injection
Class JavaFile

java.lang.Object
  extended bytudresden.ocl.injection.JavaFile

public final class JavaFile
extends Object

Represents a parsed java file. Manages the mapping of type names and types. This depends on the current package and all imported packages/classes.


Field Summary
private  boolean buildStage
          Distiguishes two stages in life cycle of this object: getting imports via addImport and finding types via findType.
private  HashSet import_demand
          Contains all imported packages of this source file with a trailing dot.
private  HashMap import_single
          Contains all imported classes of this source file.
private static HashMap nativeTypes
           
private  String packagename
           
 
Constructor Summary
JavaFile()
           
 
Method Summary
 void addImport(String importname)
          Adds the value of an import statement.
static String extractClassName(String fullclassname)
          Extracts the class name from a fully qualified class name (including package path.)
static String extractPackageName(String fullclassname)
          Extracts the package path (without trailing dot) from a fully qualified class name.
 Class findType(String typename)
          Maps type names to types.
 String getPackageName()
          Gets the value of the package statement encountered in this java file.
 void setPackage(String packagename)
          Sets the package of this file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packagename

private String packagename

import_single

private HashMap import_single
Contains all imported classes of this source file. More formally it contains the TypeName's imported by a SingleTypeImportDeclaration as defined in Java Language Specification 7.5.1 as values, and the their corresponding simple names as key.


import_demand

private HashSet import_demand
Contains all imported packages of this source file with a trailing dot. More formally it contains the PackageName's imported by a TypeImportOnDemandDeclaration as defined in Java Language Specification 7.5.2 suffixed by a single dot. This implies, that the package names dont have the trailing '*' anymore, but the dot before '*' is still present. Additionally contains "java.lang." to implement Java Language Specification 7.5.3. "Automatic Imports".


buildStage

private boolean buildStage
Distiguishes two stages in life cycle of this object: getting imports via addImport and finding types via findType.

See Also:
addImport(java.lang.String), findType(java.lang.String)

nativeTypes

private static HashMap nativeTypes
Constructor Detail

JavaFile

public JavaFile()
Method Detail

setPackage

public final void setPackage(String packagename)
                      throws InjectorParseException
Sets the package of this file. Necessary, since the package is not known at construction time.

Throws:
InjectorParseException - if called more than once.

getPackageName

public final String getPackageName()
Gets the value of the package statement encountered in this java file. Is null, if no package statement found.


addImport

public final void addImport(String importname)
                     throws InjectorParseException
Adds the value of an import statement.

Throws:
InjectorParseException

findType

public final Class findType(String typename)
                     throws InjectorParseException
Maps type names to types. This mapping depends on the import statements encountered in this java file. Nearly (TODO) implements Java Language Specification 6.5.4 "Meaning of Type Names" and Java Language Specification 7.5 "Import Declarations" Note, that the result depends also on the classes that are available (in the CLASSPATH) when running this method. Using this method in the ocl injector assumes, that at injection time the same classes are available as at compile time of the modified user code.

Throws:
InjectorParseException - if no type could be found. Never returns null.

extractClassName

public static String extractClassName(String fullclassname)
Extracts the class name from a fully qualified class name (including package path.)


extractPackageName

public static String extractPackageName(String fullclassname)
Extracts the package path (without trailing dot) from a fully qualified class name.


Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.