/** * Add a class to this package. * * @param sName * Name of class to be added to this package * @return Newly generated class * @exception JSNameAlreadyExistsException * When the specified class/interface was already created. */ @Nonnull public JSDefinedClass _class (@Nonnull @Nonempty final String sName) throws JSNameAlreadyExistsException { final JSDefinedClass aDefinedClass = new JSDefinedClass (sName); return addDeclaration (aDefinedClass); }
@Nonnull @Override public JSFieldVar name (@Nonnull @Nonempty final String sNewName) throws JSNameAlreadyExistsException { final String sOldName = name (); if (!sOldName.equals (sNewName)) { // make sure that the new name is available final JSFieldVar aExistingField = m_aOwnerClass.getFieldOfName (sNewName); if (aExistingField != null) throw new JSNameAlreadyExistsException (aExistingField); m_aOwnerClass.removeField (this); super.name (sNewName); m_aOwnerClass.addField (this); } return this; }
/** * Adds a field to the list of field members of this defined class. * * @param sName * Name of this field * @return Newly generated field */ @Nonnull public JSFieldVar field (@Nonnull @Nonempty final String sName) { return field (sName, null); }
/** * Constructor constructor * * @param aClass * Class containing this constructor */ public JSConstructor (@Nonnull final JSDefinedClass aClass) { super (aClass.name ()); m_aClass = aClass; }
public void declare (@Nonnull final JSFormatter aFormatter) { if (m_aJSDoc != null) aFormatter.nl ().generatable (m_aJSDoc); // Emit the constructor first (a function) aFormatter.decl (constructor ()); final JSAssocArray aPrototypefields = new JSAssocArray (); // Add all fields for (final JSFieldVar aField : m_aFields.values ()) aPrototypefields.add (aField.name (), aField.hasInit () ? aField.init () : JSExpr.NULL); // Add all methods for (final JSMethod aMethod : m_aMethods) aPrototypefields.add (aMethod.name (), aMethod.getAsAnonymousFunction ()); // Start with the prototype methods JSExpr.assign (prototype (), aPrototypefields).generate (aFormatter); }
/** * Update the chart with new datasets. This destroys the old chart. * * @param aJSDataVar * The data parameter used to draw the graph. * @return The JS code needed to do so. */ @Nonnull public IHasJSCode getJSUpdateCode (@Nonnull final IJSExpression aJSDataVar) { final JSPackage ret = new JSPackage (); // Cleanup old chart ret.invoke (JSExpr.ref (getJSChartVar ()), "destroy"); // Use new chart ret.assign (JSExpr.ref (getJSChartVar ()), new JSDefinedClass ("Chart")._new () .arg (JSExpr.ref (getCanvasID ()) .invoke ("getContext") .arg ("2d")) .invoke (m_aChart.getJSMethodName ()) .arg (aJSDataVar) .arg (getJSOptions ())); return ret; } }
@Nonnull public JSFieldRef prototype () { return staticRef ("prototype"); }
@Nonnull public JSFieldVar addField (@Nonnull final JSFieldVar aField) throws JSNameAlreadyExistsException { ValueEnforcer.notNull (aField, "Field"); final String sName = aField.name (); final JSFieldVar aOldField = getFieldOfName (sName); if (aOldField != null) throw new JSNameAlreadyExistsException (aOldField); m_aFields.put (sName, aField); return aField; }
/** * Adds a field to the list of field members of this defined class. * * @param sName * Name of this field. * @param aInit * Initial value of this field. * @return Newly generated field */ @Nonnull public JSFieldVar field (@Nonnull @Nonempty final String sName, @Nullable final IJSExpression aInit) { final JSFieldVar aField = new JSFieldVar (this, sName, aInit); return addField (aField); }
/** * Constructor constructor * * @param aClass * Class containing this constructor */ public JSConstructor (@Nonnull final JSDefinedClass aClass) { super (aClass.name ()); m_aClass = aClass; }
public void declare (@Nonnull final JSFormatter aFormatter) { if (m_aJSDoc != null) aFormatter.nl ().generatable (m_aJSDoc); // Emit the constructor first (a function) aFormatter.decl (constructor ()); final JSAssocArray aPrototypefields = new JSAssocArray (); // Add all fields for (final JSFieldVar aField : m_aFields.values ()) aPrototypefields.add (aField.name (), aField.hasInit () ? aField.init () : JSExpr.NULL); // Add all methods for (final JSMethod aMethod : m_aMethods) aPrototypefields.add (aMethod.name (), aMethod.getAsAnonymousFunction ()); // Start with the prototype methods JSExpr.assign (prototype (), aPrototypefields).generate (aFormatter); }
new JSDefinedClass ("Chart")._new () .arg (aJSCanvas.invoke ("getContext").arg ("2d")) .invoke (m_aChart.getJSMethodName ())
@Nonnull public JSFieldRef prototype () { return staticRef ("prototype"); }
@Nonnull public JSFieldVar addField (@Nonnull final JSFieldVar aField) throws JSNameAlreadyExistsException { ValueEnforcer.notNull (aField, "Field"); final String sName = aField.name (); final JSFieldVar aOldField = getFieldOfName (sName); if (aOldField != null) throw new JSNameAlreadyExistsException (aOldField); m_aFields.put (sName, aField); return aField; }
/** * Adds a field to the list of field members of this defined class. * * @param sName * Name of this field. * @param aInit * Initial value of this field. * @return Newly generated field */ @Nonnull public JSFieldVar field (@Nonnull @Nonempty final String sName, @Nullable final IJSExpression aInit) { final JSFieldVar aField = new JSFieldVar (this, sName, aInit); return addField (aField); }
@Nonnull @Override public JSFieldVar name (@Nonnull @Nonempty final String sNewName) throws JSNameAlreadyExistsException { final String sOldName = name (); if (!sOldName.equals (sNewName)) { // make sure that the new name is available final JSFieldVar aExistingField = m_aOwnerClass.getFieldOfName (sNewName); if (aExistingField != null) throw new JSNameAlreadyExistsException (aExistingField); m_aOwnerClass.removeField (this); super.name (sNewName); m_aOwnerClass.addField (this); } return this; }
/** * Add a class to this package. * * @param sName * Name of class to be added to this package * @return Newly generated class * @exception JSNameAlreadyExistsException * When the specified class/interface was already created. */ @Nonnull public JSDefinedClass _class (@Nonnull @Nonempty final String sName) throws JSNameAlreadyExistsException { final JSDefinedClass aDefinedClass = new JSDefinedClass (sName); return addDeclaration (aDefinedClass); }
/** * Adds a field to the list of field members of this defined class. * * @param sName * Name of this field * @return Newly generated field */ @Nonnull public JSFieldVar field (@Nonnull @Nonempty final String sName) { return field (sName, null); }