/** * Generates indexed getter method with body and optionaly with Javadoc comment. * * @param body Body of the method * @param javadoc Generate Javadoc comment? * @throws SourceException If modification of source code is impossible. */ void generateIndexedGetterMethod(String body, boolean javadoc) throws SourceException { ClassElement declaringClass = getDeclaringClass(); MethodElement newGetter = new MethodElement(); MethodParameter[] newParameters = {new MethodParameter("index", Type.INT, false)}; // NOI18N newGetter.setName(Identifier.create("get" + capitalizeFirstLetter(getName()))); // NOI18N newGetter.setReturn(indexedType); newGetter.setModifiers(Modifier.PUBLIC); newGetter.setParameters(newParameters); if (declaringClass.isInterface()) { newGetter.setBody(null); } else if (body != null) newGetter.setBody(body); if (javadoc) { String comment = MessageFormat.format( bundle.getString("COMMENT_IdxPropertyGetter"), new Object[] {getName()}); newGetter.getJavaDoc().setRawText(comment); } // System.out.println ("Generating getter" ); // NOI18N if (declaringClass == null) throw new SourceException(); else { // System.out.println ( "Adding getter method" ); // NOI18N declaringClass.addMethod(newGetter); indexedGetterMethod = declaringClass.getMethod(newGetter.getName(), getParameterTypes(newGetter)); } }
/** * Deletes the indexed setter method in source * * @throws SourceException If modification of source code is impossible. */ void deleteIndexedSetterMethod() throws SourceException { if (indexedSetterMethod == null) return; ClassElement declaringClass = getDeclaringClass(); if (declaringClass == null) { throw new SourceException(); } else { declaringClass.removeMethod(indexedSetterMethod); indexedSetterMethod = null; } }
/** * Generates indexed setter method with body and optionaly with Javadoc comment. * * @param body Body of the method * @param javadoc Generate Javadoc comment? * @param constrained Is the property constrained? * @throws SourceException If modification of source code is impossible. */ void generateIndexedSetterMethod(String body, boolean constrained, boolean javadoc) throws SourceException { ClassElement declaringClass = getDeclaringClass(); MethodElement newSetter = new MethodElement(); MethodParameter[] newParameters = { new MethodParameter("index", Type.INT, false), // NOI18N new MethodParameter(name, indexedType, false) }; newSetter.setName(Identifier.create("set" + capitalizeFirstLetter(getName()))); // NOI18N newSetter.setReturn(Type.VOID); newSetter.setModifiers(Modifier.PUBLIC); newSetter.setParameters(newParameters); if (constrained) newSetter.setExceptions( (new Identifier[] {Identifier.create("java.beans.PropertyVetoException")})); // NOI18N if (declaringClass.isInterface()) { newSetter.setBody(null); } else if (body != null) { newSetter.setBody(body); } if (javadoc) { String comment = MessageFormat.format( bundle.getString("COMMENT_IdxPropertySetter"), new Object[] {getName(), name}); if (constrained) comment = comment + bundle.getString("COMMENT_Tag_ThrowsPropertyVeto"); newSetter.getJavaDoc().setRawText(comment); } if (declaringClass == null) throw new SourceException(); else { declaringClass.addMethod(newSetter); indexedSetterMethod = declaringClass.getMethod(newSetter.getName(), getParameterTypes(newSetter)); } }
protected Node[] createNodes(Object key) { ClassElement ce = ClassElement.forClass((Class) key); InterfaceNode inode = new InterfaceNode((Class) key, ce); return new Node[] {inode}; }