Skip to content

Commit

Permalink
Fix series<xxx>
Browse files Browse the repository at this point in the history
  • Loading branch information
ronanquillevere committed May 24, 2015
1 parent 699074d commit 86ea8fe
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ private void exploreSubTree(Option option, OptionsData optionsData) throws IOExc
OptionTree tree = optionsData.findTree(option);

List<Option> children = tree.getChildren(option);
if (children == null)
if (children == null && !option.getFullname().equals("series"))
throw new RuntimeException("No children whereas isParent" + ";" + option);

for (Option child : children)
if (children != null) //series case
{
exploreChild(child, optionsData);
for (Option child : children)
{
exploreChild(child, optionsData);
}
}

writeOptionClasses(option, tree);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ public boolean isArray()
{
return false;
}
}, Series {

@Override
@CheckForNull
public <IN, OUT> OUT accept(FieldTypeVisitor<IN, OUT> visitor, IN in)
{
return visitor.visitSeries(in);
}

@Override
public boolean isArray()
{
return true;
}
};

@CheckForNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public interface FieldTypeVisitor<IN, OUT>
OUT visitEvent(IN in);

OUT visitElement(IN in);

OUT visitSeries(IN in);

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ public List<FieldType> visitArray(ObjectOrOption in)
String matching = matcher.group(0);

List<FieldType> out = Lists.newArrayList();
if (matching.equals(ARRAY))
if (in.getFullname().equals("series"))
{
out.add(FieldType.Series);
}
else if (matching.equals(ARRAY))
{
if (in.getFullname().equals("xAxis.categories") || in.getFullname().equals("yAxis.categories"))
out.add(FieldType.ArrayString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ public Void visitEvent(OutputType in)
// TODO Auto-generated method stub
return null;
}

@Override
public Void visitSeries(OutputType in)
{
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public static String extractParentFullName(Option option)
if (lastIndexOf == -1)
return null;

String parentFullName = fullname.substring(0, lastIndexOf); //to support series<xxx>.child
String parentFullName = fullname.substring(0, lastIndexOf);

if (parentFullName.matches("\\w+<\\w+>\\.\\w+"))
parentFullName.replaceAll("<\\w+", "");
return parentFullName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.highcharts4gwt.generator.option.field;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -64,24 +63,36 @@ public static String getEventNamePrefix(Option option)

// GaugeClickEvent
String eventName = v2 + option.getTitle().substring(0, 1).toUpperCase() + option.getTitle().substring(1);
eventName = removeLt(eventName);
eventName = removeGt(eventName);
eventName = removeLtGt(eventName, true);
return eventName;
}

public static String removeLt(String name)

public static String removeLtGt(String name, boolean camelCase)
{
String out = removeLt(name, camelCase);
out = removeGt(out);
return out;
};

private static String removeLt(String name, boolean camelCase)
{
int lt = name.indexOf("<");
if (lt > -1)
name = name.substring(0,lt) + name.substring(lt+1,lt+2).toUpperCase() + name.substring(lt+2, name.length());
{
String typeFirstLetter = name.substring(lt + 1, lt + 2);
if (camelCase)
typeFirstLetter = typeFirstLetter.toUpperCase();

name = name.substring(0, lt) + typeFirstLetter + name.substring(lt + 2, name.length());
}
return name;
}

public static String removeGt(String name)
private static String removeGt(String name)
{
int lt = name.indexOf(">");
if (lt > -1)
name = name.substring(0,lt) + name.substring(lt+1, name.length());
name = name.substring(0, lt) + name.substring(lt + 1, name.length());
return name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.github.highcharts4gwt.generator.option.field;

import javax.annotation.CheckForNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.highcharts4gwt.generator.common.ClassRegistry;
import com.github.highcharts4gwt.generator.common.OutputType;
import com.github.highcharts4gwt.generator.common.OutputTypeVisitor;
import com.github.highcharts4gwt.generator.option.Option;
import com.github.highcharts4gwt.model.array.api.Array;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;

public class FieldSeriesWriter extends AbstractFieldWriter implements OutputTypeVisitor<Void, Void>
{
private static final Logger logger = LoggerFactory.getLogger(FieldSeriesWriter.class);

private final String defaultValue;
private final Option option;

public FieldSeriesWriter(JDefinedClass jClass, Option option, boolean pipe, String fieldName)
{
super(jClass, pipe, fieldName, option.getDescription());
this.option = option;
this.defaultValue = option.getDefaults();
}

@Override
@CheckForNull
public Void visitInterface(Void in)
{
JClass fieldClazz = getNarrowedArrayClass();
if (fieldClazz == null)
return null;

InterfaceFieldHelper.addGetterSetterDeclaration(getNames(), fieldClazz, getJclass());
return null;
}

@Override
@CheckForNull
public Void visitJso(Void in)
{
return null;
}

@Override
@CheckForNull
public Void visitMock(Void in)
{
return null;
}

private JClass getNarrowedArrayClass()
{
// use interface type
JClass jClass = ClassRegistry.INSTANCE.getRegistry().get(new ClassRegistry.RegistryKey(option, OutputType.Interface));

if (jClass == null)
{
logger.error("Could not create Array<Object> for type " + option.getFullname());
return null;
}

JClass genericArray = new JCodeModel().ref(Array.class);
JClass arrayOfSpecializedType = genericArray.narrow(jClass);
return arrayOfSpecializedType;
}

@Override
protected String getNameExtension()
{
return "AsArrayObject";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ public Void visitElement(OutputType in)
{
throw new RuntimeException("Element type is not supported by options");
}

@Override
public Void visitSeries(OutputType in)
{
return in.accept(new FieldSeriesWriter(jClass, option, pipe, fieldName), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static OptionsData parse(String optionsAsString)
for (Option option : options)
{
//TODO remove when dump fixed,
if (option.getFullname().equals("series"))
option.setIsParent(false);
// if (option.getFullname().equals("series"))
// option.setIsParent(false);
if (option.getFullname().equals("series.data") ||
option.getFullname().equals("series.dataParser") ||
option.getFullname().equals("series.dataURL") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public BaseClassWriter(String rootDirectory) throws JClassAlreadyExistsException
fieldWriter = new BaseFieldWriter();
genericFieldWritter = new GenericFieldWriter();
}

@Override
public void write() throws IOException, JClassAlreadyExistsException
{
Expand All @@ -74,14 +74,14 @@ public void write() throws IOException, JClassAlreadyExistsException

if (tree == null)
throw new RuntimeException("Need to set the tree to build a class");

JDocComment javadoc = jClass.javadoc();
javadoc.append(option.getDescription());

addFieldsToJClass();

addGenericSetterGetters();

writeJClassToFileSystem();

ClassRegistry.INSTANCE.put(option, getOutputType(), jClass);
Expand All @@ -106,10 +106,15 @@ private void addFieldsToJClass()
throw new RuntimeException("tree/option should not be null");

List<Option> fieldToAdd = tree.getChildren(option);

for (Option option : fieldToAdd)
if (fieldToAdd != null) //series case
{
fieldWriter.writeField(option, getOutputType(), rootDirectory);
for (Option option : fieldToAdd)
{
if (option.getFullname().matches("series<\\w+>")) // do not write the series<area> etc. inside the chartOption class
continue;
fieldWriter.writeField(option, getOutputType(), rootDirectory);
}
}
}

Expand Down Expand Up @@ -141,13 +146,17 @@ public OptionClassWriter setTree(OptionTree tree)
this.tree = tree;
return this;
}

protected String getFullyQualifiedName()
{
String fullyqualifiedName = getPackageName() + "." + getPrefix() + getShortClassName();

fullyqualifiedName = EventHelper.removeLt(fullyqualifiedName);
fullyqualifiedName = EventHelper.removeGt(fullyqualifiedName);
String p = getPackageName();
p = EventHelper.removeLtGt(p, false);

String s = getShortClassName();
s = EventHelper.removeLtGt(s, true);

String fullyqualifiedName = p + "." + getPrefix() + s;

return fullyqualifiedName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.github.highcharts4gwt.generator.option.klass;

import com.github.highcharts4gwt.generator.common.ClassRegistry;
import com.github.highcharts4gwt.generator.common.OutputType;
import com.github.highcharts4gwt.generator.option.Option;
import com.sun.codemodel.ClassType;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JDefinedClass;

Expand All @@ -25,7 +28,14 @@ protected JDefinedClass createJClass() throws JClassAlreadyExistsException
{
String fullyqualifiedName = getFullyQualifiedName();

return getCodeModel()._class(fullyqualifiedName, getClassType());
JDefinedClass _class = getCodeModel()._class(fullyqualifiedName, getClassType());
if (getOption().getFullname().matches("series<\\w+>"))
{
ClassRegistry.RegistryKey interfaceKey = new ClassRegistry.RegistryKey(new Option("series", "", ""), OutputType.Interface);
JClass seriesInterface = ClassRegistry.INSTANCE.getRegistry().get(interfaceKey);
_class._implements(seriesInterface);
}
return _class;
}


Expand Down

0 comments on commit 86ea8fe

Please sign in to comment.