This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Create a new property pattern: [x] Bound [x] Constrained [x] Generate Field [x] Generate Return Statement [x] Generate Set Statement [x] Generate Property Change Support following methd is generated: public void setAsdf(String asdf) { String oldAsdf = this.asdf; vetoableChangeSupport.fireVetoableChange("asdf", oldAsdf, asdf); this.asdf = asdf; propertyChangeSupport.firePropertyChange ("asdf", oldAsdf, asdf); } but method header should contain "throws PropertyVetoException". Otherwise the method is not compilable.
Reproducible but not a bug of the beans module. I have debugged adding a property and the exception WAS added to the method element but not to the source file. Here is what the beans module does: JavaClass declaringClass = getDeclaringClass(); JavaModelPackage jmodel = JavaMetamodel.getManager().getJavaExtent(declaringClass); Method newSetter = jmodel.getMethod().createMethod(); newSetter.setName( "set" + capitalizeFirstLetter( getName() ) ); // NOI18N newSetter.setType( patternAnalyser.findType("void") ); // NOI18N newSetter.setModifiers( Modifier.PUBLIC ); Parameter param = jmodel.getParameter().createParameter(); param.setName(name); param.setType(type); newSetter.getParameters().add(param); JavaClass exception = patternAnalyser.findClassElement("java.beans.PropertyVetoException"); newSetter.getExceptions().add(exception); newSetter.setBodyText( body ); newSetter.setJavadocText( comment ); declaringClass.getFeatures().add(newSetter);
reassigning to proper component
Problem is, that Exceptions <-> ExceptionNames and Interfaces <-> InterfaceNames are not synchronized. Easy workaround is to use newSetter.getExceptionNames().add(...) instead of newSetter.getExceptions().add(...);
Reassigning to Honza to implement the suggested workaround in beans module for 4.1. Please assign back to javacore and update the target milestone to future once you are done.
I would like to implement the workaround but it seems it does not work in all cases. 1. I replaced code in org/netbeans/modules/beans/beaninfo/BiSuperClass.java - m.getExceptions().addAll(orig.getExceptions()); + m.getExceptionNames().addAll(orig.getExceptionNames()); but then I get javax.jmi.reflect.CompositionViolationException. How can I simply duplicate MultipartIds? 2. I replaced code in org.netbeans.modules.beans.EventSetPattern.setIsUnicast List/*<JavaClass>*/ exs = addListenerMethod.getExceptions(); for (Iterator it = exs.iterator(); it.hasNext();) { JavaClass ex = (JavaClass) it.next(); if (tooMany.isSubTypeOf(ex)) { MultipartId exId = jmodel.getMultipartId().createMultipartId(ex.getName(), null, null); remove.add(exId); } } addListenerMethod.getExceptionNames().removeAll(remove); After that the exception (tooMany) still remains in source file. Any idea what is wrong now?
> How can I simply duplicate MultipartIds? duplicate() does not work for you? > but then I get javax.jmi.reflect.CompositionViolationException It is probably thrown, because you are trying to add Elements from one extend to different one. > Any idea what is wrong now? You are trying to remove different instances of MultipartID than those, which are in getExceptionNames(). Try to do something like this: List/*<JavaClass>*/ exs = addListenerMethod.getExceptions(); Iterator namesIt = addListenerMethod.getExceptionNames().iterator(); for (Iterator it = exs.iterator(); it.hasNext();) { JavaClass ex = (JavaClass) it.next(); namesIt.next(); if (tooMany.isSubTypeOf(ex)) { namesIt.remove(); } }
You can use Element.duplicate() method to duplicate elements. (You can write a simple helper method to duplicate lists of elements). Alternatively you could make MetadataElement.duplicateList() method public (currently it is package private) and use that. If you want to duplicate elements into a different extent, you can use MetadataElement.duplicate(targetExtent) to do that (MultipartId can be cast to MetadataElement). The code in setIsUnicast() does not work because the newly created MultipartId is not in the list of multipart ids in exception names. You should do the following: List/*<MultipartId>*/ exs = addListenerMethod.getExceptionNames(); for (Iterator it = exs.iterator(); it.hasNext();) { MultipartId exId = (MultipartId) it.next(); JavaClass ex = (JavaClass) exId.getElement(); if (tooMany.isSubTypeOf(ex)) { remove.add(exId); } } addListenerMethod.getExceptionNames().removeAll(remove);
I know about .duplicate but I need .duplicate(JavaModelPackage). Thanks Martine I have not been aware of it. It should be part of API IMO. One more question. If I have to create new MultipartId in order to add exception/interface it means that there can be several ids representing the same exception after several iterations. How will they be removed from mdr? In other words I am missing mapping Element -> MultipartId.
The duplicate(targetExtent) was added quite recently, so we did not want to change API that late in the release cycle. It should be a regular API in the next release. MultipartIds are transient elements (so regular Java garbage collection applies to them) that represent the identifier in the source code - i.e. for each occurrence of a given exception in the source code there should be a MultipartId corresponding to it. There is one more complication that you should be careful about (sorry, we should really fix the synchronization issue for the next release). InterfaceNames and ExceptionNames are not available for classes read from class file. So if you need to be able to read these also from the class-files, you should rather read them from getExceptions() and getInterfaces() and create multipart ids from those rather than trying to duplicate the IDs returned (in fact not returned :)) from getExceptionNames().
Thanks for clarification. To XXXNames() methods and class files I hope you are joking. Is it documented somewhere? I need it to generate the beaninfo since some involved classes may come from rt.jar. Uff, I am going to rewrite duplicate methods again :-(
workarounded in /cvs/beans/src/org/netbeans/modules/beans/EventSetPattern.java new revision: 1.28; previous revision: 1.27 /cvs/beans/src/org/netbeans/modules/beans/IdxPropertyPattern.java new revision: 1.28; previous revision: 1.27 /cvs/beans/src/org/netbeans/modules/beans/PropertyPattern.java new revision: 1.36; previous revision: 1.35 /cvs/beans/src/org/netbeans/modules/beans/beaninfo/BiSuperClass.java new revision: 1.17; previous revision: 1.16
reassigning back to the javacore to fix the root of the problem
Honzo, thanks for your fix and for your patience.
Javacore module was replaced by Retouche infrastructure. This bug is not valid in trunk any more.
Reorganization of java component