public Class<?> getReturnedClass() { if (returnedType != null) { return returnedType.getClassType(); } try { Method accessor = classObjectType.getClassType().getMethod(field); return iterate ? getItemClass(accessor) : accessor.getReturnType(); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
protected void findConstructor(Declaration[] declarations) throws NoSuchMethodException { int N = this.abducibleArgs.length; cachedConstructor = null; List<Class> availableArgs = N > 0 ? new ArrayList<Class>(N) : Collections.<Class>emptyList(); for (int j = 0; j < N; j++) { // during the initial build (KieBuilder), the declarations are provided on the fly and use for // type checking // when building the KieBase, the internal declarations are set and can be used Declaration decl = declarations != null ? declarations[mapArgToParam(j)] : getDeclaration(abducibleArgs[j]); if (decl != null) { availableArgs.add(decl.getExtractor().getExtractToClass()); } } Class klass = returnType.getClassType(); while (cachedConstructor == null) { try { cachedConstructor = klass.getConstructor(availableArgs.toArray(new Class[availableArgs.size()])); } catch (NoSuchMethodException nsme) { if (klass == Object.class) { throw nsme; } else { klass = klass.getSuperclass(); } } } }
private Method getAccessor() { if (accessor == null) { try { accessor = classObjectType.getClassType().getMethod(field); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } } return accessor; }
private Constructor getConstructor() { if (cachedConstructor == null || cachedConstructor.getDeclaringClass() != returnType.getClassType()) { try { findConstructor(null); } catch (NoSuchMethodException e) { e.printStackTrace(); cachedConstructor = null; returnType = null; } } return cachedConstructor; }
@Override public String toString() { StringBuilder sb = new StringBuilder((lazy ? "?" : "") + classObjectType.getClassType().getSimpleName()); if (iterate) { sb.append("/"); } else { sb.append("."); } sb.append(field); if (index >= 0) { sb.append("[").append(index).append("]"); } if (constraints != null && !constraints.isEmpty()) { sb.append("{"); sb.append(constraints.get(0)); for (int i = 1; i < constraints.size(); i++) { sb.append(", ").append(constraints.get(i)); } sb.append("}"); } return sb.toString(); }
public void setClassObjectType(ClassObjectType objectType) { this.objectType = objectType; setIndex(-1); setFieldType(((ClassObjectType) objectType).getClassType()); setValueType(objectType.getValueType()); }