/** * @return the {@link Constructor} corresponding to the given {@link JvmConstructor} or <code>null</code>. */ public Constructor<?> getConstructor(JvmConstructor constructor) { Class<?> declaringType = getRawType(constructor.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(constructor); try { return declaringType.getDeclaredConstructor(paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
@Inject public void setClassLoader(ClassLoader classLoader) { this.classFinder = new ClassFinder(classLoader); this.classLoader = classLoader; this.javaReflectAccess.setClassLoader(classLoader); }
private Class<?> getRawType(JvmTypeReference ref) { Class<?> result = getRawType(ref.getType()); return result; }
Class<?> componentClass = getRawType(componentType); try { return getClassFinder().forName(componentClass.getName() + "[]"); } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) for (JvmTypeConstraint jvmTypeConstraint : constraints) { if (jvmTypeConstraint instanceof JvmUpperBound) { return getRawType(jvmTypeConstraint.getTypeReference()); return getClassFinder().forName(type.getIdentifier()); } catch (ClassNotFoundException e) { if (log.isDebugEnabled())
Class<?> componentType = null; if (executable instanceof JvmOperation) { Method method = javaReflectAccess.getMethod((JvmOperation) executable); componentType = method.getParameterTypes()[paramCount].getComponentType(); } else { Constructor<?> constructor = javaReflectAccess.getConstructor((JvmConstructor) executable); componentType = constructor.getParameterTypes()[paramCount].getComponentType();
protected Object featureCallField(JvmField jvmField, Object receiver) { Field field = javaReflectAccess.getField(jvmField); try { if (field == null) { throw new NoSuchFieldException("Could not find field " + jvmField.getIdentifier()); } if(!Modifier.isStatic(field.getModifiers()) && receiver == null) { throw new EvaluationException(new NullPointerException("cannot access field " + field + " on null")); } field.setAccessible(true); Object result = field.get(receiver); return result; } catch(EvaluationException ee) { throw ee; } catch (Exception e) { throw new IllegalStateException("Could not access field: " + jvmField.getIdentifier() + " on instance: " + receiver, e); } }
protected Object _doEvaluate(XConstructorCall constructorCall, IEvaluationContext context, CancelIndicator indicator) { JvmConstructor jvmConstructor = constructorCall.getConstructor(); List<Object> arguments = evaluateArgumentExpressions(jvmConstructor, constructorCall.getArguments(), context, indicator); Constructor<?> constructor = javaReflectAccess.getConstructor(jvmConstructor); try { if (constructor == null) throw new NoSuchMethodException("Could not find constructor " + jvmConstructor.getIdentifier()); constructor.setAccessible(true); Object result = constructor.newInstance(arguments.toArray(new Object[arguments.size()])); return result; } catch (InvocationTargetException targetException) { throw new EvaluationException(targetException.getTargetException()); } catch (Exception e) { throw new IllegalStateException("Could not invoke constructor: " + jvmConstructor.getIdentifier(), e); } }
protected Object invokeOperation(JvmOperation operation, Object receiver, List<Object> argumentValues) { Method method = javaReflectAccess.getMethod(operation); try { if (method == null) {
private Class<?> getRawType(JvmTypeReference ref) { Class<?> result = getRawType(ref.getType()); return result; }
Class<?> componentClass = getRawType(componentType); try { return getClassFinder().forName(componentClass.getName() + "[]"); } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) for (JvmTypeConstraint jvmTypeConstraint : constraints) { if (jvmTypeConstraint instanceof JvmUpperBound) { return getRawType(jvmTypeConstraint.getTypeReference()); return getClassFinder().forName(type.getIdentifier()); } catch (ClassNotFoundException e) { if (log.isDebugEnabled())
protected Object _assignValueTo(JvmField jvmField, XAbstractFeatureCall assignment, Object value, IEvaluationContext context, CancelIndicator indicator) { Object receiver = getReceiver(assignment, context, indicator); Field field = javaReflectAccess.getField(jvmField); try { if (field == null) { throw new NoSuchFieldException("Could not find field " + jvmField.getIdentifier()); } if (!Modifier.isStatic(field.getModifiers()) && receiver == null) throw new EvaluationException(new NullPointerException("Cannot assign value to field: " + jvmField.getIdentifier() + " on null instance")); JvmTypeReference type = jvmField.getType(); Object coerced = coerceArgumentType(value, type); field.setAccessible(true); field.set(receiver, coerced); return value; } catch (Exception e) { throw new IllegalStateException("Could not access field: " + jvmField.getIdentifier() + " on instance: " + receiver, e); } }
/** * @return the {@link Constructor} corresponding to the given {@link JvmConstructor} or <code>null</code>. */ public Constructor<?> getConstructor(JvmConstructor constructor) { Class<?> declaringType = getRawType(constructor.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(constructor); try { return declaringType.getDeclaredConstructor(paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
protected Class<?>[] getParamTypes(JvmExecutable exe) { List<JvmFormalParameter> parameters = exe.getParameters(); List<Class<?>> result = Lists.newArrayList(); for (JvmFormalParameter p : parameters) { result.add(getRawType(p.getParameterType())); } return result.toArray(new Class<?>[result.size()]); }
/** * @return the {@link Method} corresponding to the given {@link JvmOperation} or <code>null</code>. */ public Method getMethod(JvmOperation operation) { Class<?> declaringType = getRawType(operation.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(operation); try { return declaringType.getDeclaredMethod(operation.getSimpleName(), paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
protected Class<?>[] getParamTypes(JvmExecutable exe) { List<JvmFormalParameter> parameters = exe.getParameters(); List<Class<?>> result = Lists.newArrayList(); for (JvmFormalParameter p : parameters) { result.add(getRawType(p.getParameterType())); } return result.toArray(new Class<?>[result.size()]); }
/** * @return the {@link Method} corresponding to the given {@link JvmOperation} or <code>null</code>. */ public Method getMethod(JvmOperation operation) { Class<?> declaringType = getRawType(operation.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(operation); try { return declaringType.getDeclaredMethod(operation.getSimpleName(), paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
protected Object create(JvmType jvmType) { Class<?> class1 = reflectAccess.getRawType(jvmType); if (class1==null) throw new IllegalStateException("Couldn't find java.lang.Class for name '"+jvmType.getIdentifier()+"'"); try { return class1.newInstance(); } catch (Exception e) { throw new WrappedException(e); } }
/** * @return the {@link java.lang.reflect.Field} corresponding to the given {@link JvmField} or <code>null</code>. */ public Field getField(JvmField field) { Class<?> class1 = getRawType(field.getDeclaringType()); if (class1 == null) return null; try { return class1.getDeclaredField(field.getSimpleName()); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
/** * @return the {@link java.lang.reflect.Field} corresponding to the given {@link JvmField} or <code>null</code>. */ public Field getField(JvmField field) { Class<?> class1 = getRawType(field.getDeclaringType()); if (class1 == null) return null; try { return class1.getDeclaredField(field.getSimpleName()); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }