use of javassist.NotFoundException in project hibernate-orm by hibernate.
the class PersistentAttributesHelper method getTargetEntityClass.
public static CtClass getTargetEntityClass(CtClass managedCtClass, CtField persistentField) throws NotFoundException {
// get targetEntity defined in the annotation
try {
OneToOne oto = PersistentAttributesHelper.getAnnotation(persistentField, OneToOne.class);
OneToMany otm = PersistentAttributesHelper.getAnnotation(persistentField, OneToMany.class);
ManyToOne mto = PersistentAttributesHelper.getAnnotation(persistentField, ManyToOne.class);
ManyToMany mtm = PersistentAttributesHelper.getAnnotation(persistentField, ManyToMany.class);
Class<?> targetClass = null;
if (oto != null) {
targetClass = oto.targetEntity();
}
if (otm != null) {
targetClass = otm.targetEntity();
}
if (mto != null) {
targetClass = mto.targetEntity();
}
if (mtm != null) {
targetClass = mtm.targetEntity();
}
if (targetClass != null && targetClass != void.class) {
return managedCtClass.getClassPool().get(targetClass.getName());
}
} catch (NotFoundException ignore) {
}
// infer targetEntity from generic type signature
String inferredTypeName = inferTypeName(managedCtClass, persistentField.getName());
return inferredTypeName == null ? null : managedCtClass.getClassPool().get(inferredTypeName);
}
use of javassist.NotFoundException in project incubator-systemml by apache.
the class GenerateClassesForMLContext method addPackageConvenienceMethodsToMLContext.
/**
* Add methods to MLContext to allow tab-completion to packages contained
* within the source directory (such as {@code ml.nn()}).
*
* @param dirPath
* path to source directory (typically, the scripts directory)
* @param ctMLContext
* javassist compile-time class representation of MLContext
*/
public static void addPackageConvenienceMethodsToMLContext(String dirPath, CtClass ctMLContext) {
try {
if (!SOURCE.equalsIgnoreCase(dirPath)) {
return;
}
File dir = new File(dirPath);
File[] subdirs = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory();
}
});
for (File subdir : subdirs) {
String subDirPath = dirPath + File.separator + subdir.getName();
if (skipDir(subdir, false)) {
continue;
}
String fullSubDirClassName = dirPathToFullDirClassName(subDirPath);
ClassPool pool = ClassPool.getDefault();
CtClass subDirClass = pool.get(fullSubDirClassName);
String subDirName = subdir.getName();
subDirName = subDirName.replaceAll("-", "_");
subDirName = subDirName.toLowerCase();
System.out.println("Adding " + subDirName + "() to " + ctMLContext.getName());
String methodBody = "{ " + fullSubDirClassName + " z = new " + fullSubDirClassName + "(); return z; }";
CtMethod ctMethod = CtNewMethod.make(Modifier.PUBLIC, subDirClass, subDirName, null, null, methodBody, ctMLContext);
ctMLContext.addMethod(ctMethod);
}
} catch (NotFoundException e) {
e.printStackTrace();
} catch (CannotCompileException e) {
e.printStackTrace();
}
}
use of javassist.NotFoundException in project incubator-systemml by apache.
the class GenerateClassesForMLContext method addConvenienceMethodsToMLContext.
/**
* Add methods to MLContext to allow tab-completion to folders/packages
* (such as {@code ml.scripts()} and {@code ml.nn()}).
*
* @param source
* path to source directory (typically, the scripts directory)
* @param fullDirClassName
* the full name of the class representing the source (scripts)
* directory
*/
public static void addConvenienceMethodsToMLContext(String source, String fullDirClassName) {
try {
ClassPool pool = ClassPool.getDefault();
CtClass ctMLContext = pool.get(MLContext.class.getName());
CtClass dirClass = pool.get(fullDirClassName);
String methodName = convertFullClassNameToConvenienceMethodName(fullDirClassName);
System.out.println("Adding " + methodName + "() to " + ctMLContext.getName());
String methodBody = "{ " + fullDirClassName + " z = new " + fullDirClassName + "(); return z; }";
CtMethod ctMethod = CtNewMethod.make(Modifier.PUBLIC, dirClass, methodName, null, null, methodBody, ctMLContext);
ctMLContext.addMethod(ctMethod);
addPackageConvenienceMethodsToMLContext(source, ctMLContext);
ctMLContext.writeFile(destination);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
} catch (CannotCompileException e) {
e.printStackTrace();
}
}
use of javassist.NotFoundException in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getInitMethod.
private CtMethod getInitMethod(Set<CtClass> patchClasses) {
List<CtMethod> initMethods = new ArrayList<CtMethod>();
for (CtClass patchClass : patchClasses) {
for (CtMethod ctMethod : patchClass.getDeclaredMethods()) {
if (ctMethod.hasAnnotation(InitMethod.class)) {
if (!Modifier.isStatic(ctMethod.getModifiers())) {
throw new GwtTestPatchException("@" + InitMethod.class.getSimpleName() + " has to be static : '" + ctMethod.getLongName() + "'");
}
try {
if (ctMethod.getParameterTypes().length != 1 || ctMethod.getParameterTypes()[0] != GwtClassPool.getCtClass(CtClass.class)) {
throw new GwtTestPatchException("@" + InitMethod.class.getName() + " method must have one and only one parameter of type '" + CtClass.class.getName() + "'");
}
} catch (NotFoundException e) {
// should never happen
throw new GwtTestPatchException(e);
}
initMethods.add(ctMethod);
}
}
}
CtMethod initMethod = getMethodToUse(initMethods, InitMethod.class);
if (initMethod != null) {
initMethod.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
}
return initMethod;
}
use of javassist.NotFoundException in project gwt-test-utils by gwt-test-utils.
the class ClassesScanner method visitClass.
private void visitClass(String classFileName, ClassVisitor classVisitor) {
try {
CtClass current = GwtClassPool.getClass(classFileName.substring(0, classFileName.length() - ".class".length()));
classVisitor.visit(current);
for (CtClass innerClass : current.getNestedClasses()) {
classVisitor.visit(innerClass);
}
} catch (NotFoundException e) {
// do nothing
}
}
Aggregations