use of com.jopdesign.common.misc.NamingConflictException in project jop by jop-devel.
the class AppInfo method createClass.
// ////////////////////////////////////////////////////////////////////////////
// Methods to create, load, get and remove ClassInfos
// ////////////////////////////////////////////////////////////////////////////
/**
* Create a new classInfo. If a class with the same name exists, return the existing classInfo.
*
* <p>Note that this does not update the complete class hierarchy. You need to call {@link #reloadClassHierarchy()}
* after you finished creating and loading classes. SuperClass will be set, but nothing more.</p>
*
* @param className the fully qualified name of the class.
* @param superClass the references to the superclass, or null to use java.lang.Object (ignored if the new class is
* java.lang.Object).
* @param isInterface true if this class should be an interface.
* @return a new ClassInfo or the current ClassInfo by the same name if it exists.
* @throws NamingConflictException if a class with the same name exists, but has a different definition.
*/
public ClassInfo createClass(String className, ClassRef superClass, boolean isInterface) throws NamingConflictException {
String superClassName;
if (superClass == null) {
superClassName = "java.lang.Object".equals(className) ? null : "java.lang.Object";
} else {
superClassName = superClass.getClassName();
}
// check for existing class
ClassInfo cls = classes.get(className);
if (cls != null) {
if (isInterface != cls.isInterface() || !cls.getSuperClassName().equals(superClassName)) {
throw new NamingConflictException("Class '" + className + "' already exists but has a different definition.");
}
return cls;
}
// create
cls = createClassInfo(className, superClassName, isInterface);
// do a "partial" class hierarchy update (i.e. set superClass, but not subclasses of the new class)
cls.updateClassHierarchy();
// register class
classes.put(className, cls);
for (AppEventHandler mgr : eventHandlers) {
mgr.onCreateClass(cls, false);
}
return cls;
}
use of com.jopdesign.common.misc.NamingConflictException in project jop by jop-devel.
the class ExampleTool method doSomething.
public void doSomething(Config config) {
AppInfo appInfo = AppInfo.getSingleton();
// access and modify some classes
System.out.println("field of main class: " + manager.getMyField(appInfo.getMainMethod().getClassInfo()));
for (ClassInfo root : appInfo.getRootClasses()) {
System.out.println("field of root: " + manager.getMyField(root));
}
// create a new class and new methods
try {
ClassInfo newCls = appInfo.createClass("MyTest", appInfo.getClassRef("java.lang.Object"), false);
} catch (NamingConflictException e) {
e.printStackTrace();
}
}
Aggregations