private void writeCreateDelegate(SourceWriter sw) throws UnableToCompleteException { String editorDelegateName = getEditorDelegate(model.getRootData()); sw.println("@Override public void accept(%s visitor) {", EditorVisitor.class.getCanonicalName()); sw.indent(); sw.println("%1$s ctx = new %1$s(getDelegate(), %2$s.class, getObject());", RootEditorContext.class.getCanonicalName(), model.getProxyType().getQualifiedSourceName()); sw.println("ctx.traverse(visitor, getDelegate());"); sw.outdent(); sw.println("}"); sw.println("@Override protected %s createDelegate() {", Name.getSourceNameForClass(getEditorDelegateType()), model.getProxyType().getQualifiedSourceName(), model.getEditorType().getQualifiedSourceName()); sw.indent(); sw.println("return new %1$s();", editorDelegateName); sw.outdent(); sw.println("}"); } }
/** * @param accumulator * @param data * @throws UnableToCompleteException */ private void descendIntoSubEditor(List<EditorData> accumulator, EditorData data) throws UnableToCompleteException { EditorModel superModel = parentModel; while (superModel != null) { if (superModel.editorType.isAssignableFrom(data.getEditorType()) || data.getEditorType().isAssignableFrom(superModel.editorType)) { poison(cycleErrorMessage(data.getEditorType(), superModel.getPath(), data.getPath())); return; } superModel = superModel.parentModel; } if (data.isDelegateRequired()) { EditorModel subModel = new EditorModel(this, data.getEditorType(), data, calculateEditedType(logger, data.getEditorType())); accumulator.addAll(accumulator.indexOf(data) + 1, Arrays.asList(subModel.getEditorData())); poisoned |= subModel.poisoned; } }
if (shouldExamine(fieldClassType)) { List<EditorData> data = createEditorData(EditorAccess.via(field)); accumulateEditorData(data, flatData, toReturn); if (shouldExamine(methodReturnType) && method.getParameters().length == 0) { EditorAccess access = EditorAccess.via(method); List<EditorData> data = createEditorData(access); accumulateEditorData(data, flatData, toReturn); JClassType subEditorType = calculateCompositeTypes(editorType)[1]; EditorAccess access = EditorAccess.root(subEditorType); EditorData subEditor = new EditorData.Builder(logger).access(access).parent( editorSoFar).build(); List<EditorData> accumulator = new ArrayList<EditorData>(); descendIntoSubEditor(accumulator, subEditor); EditorModel subModel = new EditorModel(this, subEditor.getEditorType(), subEditor, subEditor.getEditedType()); poisoned |= subModel.poisoned;
private Set<String> getModelCleanupExpressions() { Set<String> result = new LinkedHashSet<>(); // top-level Model if (model.getProxyType().isAssignableTo(hasCleanupType)) { result.add("getObject()"); //$NON-NLS-1$ } // all Models edited through the top-level Model for (EditorData editorData : model.getEditorData()) { if (editorData.getPropertyOwnerType().isAssignableTo(hasCleanupType)) { result.add(String.format( "getObject()%s", //$NON-NLS-1$ editorData.getBeanOwnerExpression())); } } return result; }
die(unexpectedInputTypeMessage(driverType, intf)); } else if (intf.equals(driverType)) { die(mustExtendMessage(driverType)); die(tooManyInterfacesMessage(intf)); proxyType = parameters[0]; editorType = parameters[1]; editorData = calculateEditorData(); die(poisonedMessage());
model = new EditorModel(logger, toGenerate, oracle.findType(getDriverInterfaceType().getName())); packageName, simpleSourceName); factory.setSuperclass(Name.getSourceNameForClass(getDriverSuperclassType()) + "<" + model.getProxyType().getParameterizedQualifiedSourceName() + ", " + model.getEditorType().getParameterizedQualifiedSourceName() + ">"); factory.addImplementedInterface(typeName);
private List<EditorData> createEditorData(EditorAccess access) throws UnableToCompleteException { TreeLogger subLogger = logger.branch(TreeLogger.DEBUG, "Examining " + access.toString()); List<EditorData> toReturn = new ArrayList<EditorData>(); // Are we looking at a view that implements IsEditor? if (access.isEditor()) { EditorAccess subAccess = EditorAccess.via(access, calculateIsEditedType(subLogger, access.getEditorType())); toReturn = createEditorData(subAccess); // If an object only implements IsEditor, return now if (!editorIntf.isAssignableFrom(access.getEditorType())) { return toReturn; } } // Determine the Foo in Editor<Foo> JClassType expectedToEdit = calculateEditedType(subLogger, access.getEditorType()); EditorData.Builder builder = new EditorData.Builder(subLogger); builder.access(access); builder.parent(editorSoFar); // Find the bean methods on the proxy interface findBeanPropertyMethods(access.getPath(), expectedToEdit, builder); toReturn.add(builder.build()); return toReturn; }
for (EditorData editorData : model.getEditorData()) { logger.log(Type.DEBUG, "Going over Field: " + editorData); //$NON-NLS-1$ String path = editorData.getPath();
public EditorData getRootData() throws UnableToCompleteException { TreeLogger rootLogger = logger.branch(TreeLogger.DEBUG, "Calculating root data for " + getEditorType().getParameterizedQualifiedSourceName()); return new EditorData.Builder(rootLogger).access( EditorAccess.root(getEditorType())).build(); }
super.writeAdditionalContent(logger, context, model, sw); final BeanHelper beanHelper = cache.createHelper(model.getProxyType(), logger, context);
private EditorModel(EditorModel parent, JClassType editorType, EditorData subEditor, JClassType proxyType) throws UnableToCompleteException { logger = parent.logger.branch(TreeLogger.DEBUG, "Descending into " + subEditor.getPath()); this.compositeEditorIntf = parent.compositeEditorIntf; this.editorIntf = parent.editorIntf; this.editorType = editorType; this.editorSoFar = subEditor; this.isEditorIntf = parent.isEditorIntf; this.leafValueEditorIntf = parent.leafValueEditorIntf; this.oracle = parent.oracle; this.parentModel = parent; this.proxyType = proxyType; this.typeData = parent.typeData; editorData = calculateEditorData(); }
public Builder access(EditorAccess access) throws UnableToCompleteException { this.access = access; data.declaredPath = access.getPath(); data.editorType = access.getEditorType(); data.editedType = EditorModel.calculateEditedType(logger, data.editorType); data.simpleExpression = access.getExpresson(); TypeOracle oracle = data.editorType.getOracle(); JClassType leafType = oracle.findType(LeafValueEditor.class.getName()); data.isLeaf = leafType.isAssignableFrom(data.editorType); JClassType composedType = oracle.findType(CompositeEditor.class.getName()); data.isCompositeEditor = composedType.isAssignableFrom(data.editorType); JClassType hasDelegateType = oracle.findType(HasEditorDelegate.class.getName()); JClassType hasEditorErrorsType = oracle.findType(HasEditorErrors.class.getName()); data.isDelegateRequired = hasDelegateType.isAssignableFrom(data.editorType) || hasEditorErrorsType.isAssignableFrom(data.editorType) || !ModelUtils.isValueType(oracle, data.editedType); JClassType valueAwareType = oracle.findType(ValueAwareEditor.class.getName()); data.isValueAware = valueAwareType.isAssignableFrom(data.editorType); return this; }
public EditorData build() throws UnableToCompleteException { if (data == null) { throw new IllegalStateException(); } try { data.editorExpression = (parent == null ? "" : (parent.getExpression() + ".")) + access.getExpresson(); data.path = (parent == null ? "" : (parent.getPath() + ".")) + access.getPath(); if (data.isCompositeEditor) { TreeLogger compositeLogger = logger.branch(TreeLogger.DEBUG, "Examining composite editor at " + data.path); JClassType subEditorType = EditorModel.calculateCompositeTypes(data.editorType)[1]; data.composedData = new Builder(compositeLogger).access( EditorAccess.root(subEditorType)).parent(data).build(); } return data; } finally { data = null; } }
die(unexpectedInputTypeMessage(driverType, intf)); } else if (intf.equals(driverType)) { die(mustExtendMessage(driverType)); die(tooManyInterfacesMessage(intf)); proxyType = parameters[0]; editorType = parameters[1]; editorData = calculateEditorData(); die(poisonedMessage());
model = new EditorModel(logger, toGenerate, oracle.findType(getDriverInterfaceType().getName())); packageName, simpleSourceName); factory.setSuperclass(Name.getSourceNameForClass(getDriverSuperclassType()) + "<" + model.getProxyType().getParameterizedQualifiedSourceName() + ", " + model.getEditorType().getParameterizedQualifiedSourceName() + ">"); factory.addImplementedInterface(typeName);
private List<EditorData> createEditorData(EditorAccess access) throws UnableToCompleteException { TreeLogger subLogger = logger.branch(TreeLogger.DEBUG, "Examining " + access.toString()); List<EditorData> toReturn = new ArrayList<EditorData>(); // Are we looking at a view that implements IsEditor? if (access.isEditor()) { EditorAccess subAccess = EditorAccess.via(access, calculateIsEditedType(subLogger, access.getEditorType())); toReturn = createEditorData(subAccess); // If an object only implements IsEditor, return now if (!editorIntf.isAssignableFrom(access.getEditorType())) { return toReturn; } } // Determine the Foo in Editor<Foo> JClassType expectedToEdit = calculateEditedType(subLogger, access.getEditorType()); EditorData.Builder builder = new EditorData.Builder(subLogger); builder.access(access); builder.parent(editorSoFar); // Find the bean methods on the proxy interface findBeanPropertyMethods(access.getPath(), expectedToEdit, builder); toReturn.add(builder.build()); return toReturn; }
for (EditorData editorData : model.getEditorData()) { logger.log(Type.DEBUG, "Going over Field: " + editorData); //$NON-NLS-1$
public EditorData getRootData() throws UnableToCompleteException { TreeLogger rootLogger = logger.branch(TreeLogger.DEBUG, "Calculating root data for " + getEditorType().getParameterizedQualifiedSourceName()); return new EditorData.Builder(rootLogger).access( EditorAccess.root(getEditorType())).build(); }
private EditorModel(EditorModel parent, JClassType editorType, EditorData subEditor, JClassType proxyType) throws UnableToCompleteException { logger = parent.logger.branch(TreeLogger.DEBUG, "Descending into " + subEditor.getPath()); this.compositeEditorIntf = parent.compositeEditorIntf; this.editorIntf = parent.editorIntf; this.editorType = editorType; this.editorSoFar = subEditor; this.isEditorIntf = parent.isEditorIntf; this.leafValueEditorIntf = parent.leafValueEditorIntf; this.oracle = parent.oracle; this.parentModel = parent; this.proxyType = proxyType; this.typeData = parent.typeData; editorData = calculateEditorData(); }
public Builder access(EditorAccess access) throws UnableToCompleteException { this.access = access; data.declaredPath = access.getPath(); data.editorType = access.getEditorType(); data.editedType = EditorModel.calculateEditedType(logger, data.editorType); data.simpleExpression = access.getExpresson(); TypeOracle oracle = data.editorType.getOracle(); JClassType leafType = oracle.findType(LeafValueEditor.class.getName()); data.isLeaf = leafType.isAssignableFrom(data.editorType); JClassType composedType = oracle.findType(CompositeEditor.class.getName()); data.isCompositeEditor = composedType.isAssignableFrom(data.editorType); JClassType hasDelegateType = oracle.findType(HasEditorDelegate.class.getName()); JClassType hasEditorErrorsType = oracle.findType(HasEditorErrors.class.getName()); data.isDelegateRequired = hasDelegateType.isAssignableFrom(data.editorType) || hasEditorErrorsType.isAssignableFrom(data.editorType) || !ModelUtils.isValueType(oracle, data.editedType); JClassType valueAwareType = oracle.findType(ValueAwareEditor.class.getName()); data.isValueAware = valueAwareType.isAssignableFrom(data.editorType); return this; }