Skip to content

Commit

Permalink
fix suffix support
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldradi committed Mar 9, 2015
1 parent f9e5ab6 commit f29e3c3
Show file tree
Hide file tree
Showing 74 changed files with 537 additions and 464 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'cc.catalysts'
version = '2.1.3'
version = '2.1.4'

sourceCompatibility = '1.6'
targetCompatibility = '1.6'
Expand Down
82 changes: 47 additions & 35 deletions src/main/java/cc/catalysts/cdoclet/generator/AsGenerator.java
Expand Up @@ -16,6 +16,8 @@
import java.lang.reflect.Modifier;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

import static cc.catalysts.cdoclet.generator.Languages.ACTIONSCRIPT;
Expand All @@ -37,6 +39,7 @@ public class AsGenerator implements Generator {
private ASMethod method;
private ASMethod proxyMethod;

private final Map<String, String> classMap = new HashMap<String, String>();
private final TypeMap annotationMap;
private final TypeMap annotationTypeMap;
private final TypeMap packageMap;
Expand Down Expand Up @@ -119,9 +122,9 @@ public TypeMap getTypeMap() {

public void addAnnotation(Type tag) {
if (method != null) {
method.newMetaTag(tag.getName());
method.newMetaTag(tag.getQualifiedTypeName());
} else {
type.newMetaTag(tag.getName());
type.newMetaTag(tag.getQualifiedTypeName());
}
}

Expand All @@ -135,7 +138,7 @@ public void addBody(String body) {
public void addConstant(Type classType, Type constantType, String name, String initializer, String comment) {
if (type instanceof ASClassType) {
// actionscript/metaas doesn't support constants in interfaces
createConst((ASClassType) type, name, initializer, constantType.getName(), comment);
createConst((ASClassType) type, name, initializer, constantType.getQualifiedTypeName(), comment);
}
}

Expand All @@ -152,44 +155,48 @@ public void addField(Type classType, int modifier, Type fieldType, String fieldN

ASClassType asClassType = (ASClassType) type;
if (asClassType.getField(fieldName) == null)
asClassType.newField(fieldName, getVisibility(modifier), fieldType.getName());
asClassType.newField(fieldName, getVisibility(modifier), fieldType.getQualifiedTypeName());
}


public void addInterface(Type name) {
if (type instanceof ASInterfaceType) {
ASInterfaceType interfaceType = (ASInterfaceType) type;
interfaceType.addSuperInterface(name.getName());
interfaceType.addSuperInterface(name.getQualifiedTypeName());
} else {
ASClassType classType = (ASClassType) type;
classType.addImplementedInterface(name.getName());
classType.addImplementedInterface(name.getQualifiedTypeName());
}
addImport(name.getName());
addImport(name.getQualifiedTypeName());
}


public void addParameter(Type classType, Type methodType, Type type, String name) {
type = resolveTypeArguments(classType, methodType, type);

if (method != null) method.addParam(name, type.getName());
if (proxyMethod != null) proxyMethod.addParam(name, type.getName());
if (method != null) method.addParam(name, type.getQualifiedTypeName());
if (proxyMethod != null) proxyMethod.addParam(name, type.getQualifiedTypeName());

addImport(type.getName());
addImport(type.getQualifiedTypeName());
}


public void beginClass(Type classType) {
logger.info("Creating ActionScript class {}", classType);

newClass(classType.getName() + suffix, false);
addAnnotation(GeneratorUtils.getType("RemoteClass(alias=\"" + classType.getName() + "\")", this));
if (suffix != null) {
getClassMap().put(classType.getName(), classType.getName() + suffix);
}

newClass(classType.getQualifiedTypeName(), false);
addAnnotation(GeneratorUtils.getType("RemoteClass(alias=\"" + classType.getQualifiedTypeName() + "\")", this));
}


public void beginEnum(Type name) {
logger.info("Creating ActionScript enumeration {}", name);

newClass(name.getName(), true);
newClass(name.getQualifiedTypeName(), true);
}


Expand All @@ -211,7 +218,7 @@ public void beginGetter(Type classType, Type methodType, int modifier, Type fiel
public void beginInterface(Type name) {
logger.info("Creating ActionScript interface {}", name);

unit = project.newInterface(name.getName());
unit = project.newInterface(name.getQualifiedTypeName());
type = unit.getType();
imports = new TreeSet<String>();
}
Expand All @@ -225,7 +232,7 @@ public void beginMethod(Type classType, Type methodType, int modifier, Type retu
returnType = resolveTypeArguments(classType, methodType, returnType);

if (unit != null) {
method = type.newMethod(methodName, getVisibility(modifier), returnType.getName());
method = type.newMethod(methodName, getVisibility(modifier), returnType.getQualifiedTypeName());
method.setOverride(override);
}

Expand All @@ -243,42 +250,42 @@ public void beginMethod(Type classType, Type methodType, int modifier, Type retu

if (!hasField) {
createConst(eventType, proxyMethodName, MessageFormat.format("\"{0}\"", methodName), "String", null);
proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType.getName());
proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType.getQualifiedTypeName());
}
}

addImport(returnType.getName());
addImport(returnType.getQualifiedTypeName());
}


public void beginProxy(Type proxy, Type baseType, Type interfaceType) {
logger.info("Creating ActionScript proxy {}", proxy.getName());
logger.info("Creating ActionScript proxy {}", proxy.getQualifiedTypeName());

ASCompilationUnit eventUnit = project.newClass(proxy.getName() + "Events");
proxyUnit = project.newClass(proxy.getName());
ASCompilationUnit eventUnit = project.newClass(proxy.getQualifiedTypeName() + "Events");
proxyUnit = project.newClass(proxy.getQualifiedTypeName());

eventType = (ASClassType) eventUnit.getType();
proxyType = (ASClassType) proxyUnit.getType();

proxyType.addImplementedInterface(interfaceType.getName());
proxyType.addImplementedInterface(interfaceType.getQualifiedTypeName());

proxyImports = new TreeSet<String>();
proxyImports.add(interfaceType.getName());
proxyImports.add(interfaceType.getQualifiedTypeName());

if (baseType != Type.NULL) {
proxyType.setSuperclass(baseType.getName());
proxyImports.add(baseType.getName());
proxyType.setSuperclass(baseType.getQualifiedTypeName());
proxyImports.add(baseType.getQualifiedTypeName());
}

ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, "Object");
callMethod.addParam("name", "String");
callMethod.addParam("...args", null);
callMethod.addStmt("throw new Error(\"Not Implemented\");");

ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Type.VOID.getName());
ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Type.VOID.getQualifiedTypeName());
resultMethod.addParam("result", "Object");

ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Type.VOID.getName());
ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Type.VOID.getQualifiedTypeName());
statusMethod.addParam("status", "Object");
}

Expand All @@ -289,11 +296,11 @@ public void beginSetter(Type classType, Type methodType, int modifier, Type fiel
if (type instanceof ASClassType) {
addField(classType, Modifier.PRIVATE, fieldType, "_" + propertyName, null, null);
beginMethod(classType, Type.EMPTY, modifier, Type.VOID, "set " + propertyName, false, override);
method.addParam("value", fieldType.getName());
method.addParam("value", fieldType.getQualifiedTypeName());
method.addStmt("_" + propertyName + "=value;");
} else {
beginMethod(classType, Type.EMPTY, modifier, Type.VOID, "set " + propertyName, false, override);
method.addParam("value", fieldType.getName());
method.addParam("value", fieldType.getQualifiedTypeName());
}

setMethodDescription(comment);
Expand Down Expand Up @@ -359,6 +366,11 @@ public void generate() throws IOException {
project.writeAll();
}

@Override
public Map<String, String> getClassMap() {
return classMap;
}


public String getName() {
return ACTIONSCRIPT;
Expand All @@ -382,8 +394,8 @@ public void setMethodDescription(String description) {


public void setSuperclass(Type name, boolean exception) {
((ASClassType) type).setSuperclass(name.getName());
addImport(name.getName());
((ASClassType) type).setSuperclass(name.getQualifiedTypeName());
addImport(name.getQualifiedTypeName());
}


Expand Down Expand Up @@ -448,20 +460,20 @@ private void newClass(String name, boolean isFinal) {
private Type resolveTypeArguments(Type classType, Type methodType, Type type) {
if (!type.isGeneric()) return type;

String name = type.getName();
String name = type.getQualifiedTypeName();
if (methodType != null && methodType.getBounds() != null && methodType.getBounds().containsKey(name)) {
Type returnType = methodType.getBounds().get(type.getName());
Type returnType = methodType.getBounds().get(type.getQualifiedTypeName());
if (returnType != null) {
name = type.getName();
name = type.getQualifiedTypeName();
addImport(name);
return returnType;
}
}

if (classType != null && classType.getBounds() != null && classType.getBounds().containsKey(name)) {
Type returnType = classType.getBounds().get(type.getName());
Type returnType = classType.getBounds().get(type.getQualifiedTypeName());
if (returnType != null) {
name = type.getName();
name = type.getQualifiedTypeName();
addImport(name);
return returnType;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/cc/catalysts/cdoclet/generator/Generator.java
Expand Up @@ -4,6 +4,7 @@
import com.sun.javadoc.ClassDoc;

import java.lang.annotation.Annotation;
import java.util.Map;

public interface Generator {
void addAnnotation(Type annotation);
Expand Down Expand Up @@ -54,6 +55,8 @@ public interface Generator {

void generate() throws Exception;

Map<String, String> getClassMap();

TypeMap getAnnotationMap();

TypeMap getAnnotationTypeMap();
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/cc/catalysts/cdoclet/generator/TemplateGenerator.java
Expand Up @@ -16,8 +16,11 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class TemplateGenerator implements Generator {
private static final Map<String, String> classMap = new HashMap<String, String>();

private Collection<TypeDescriptor> typeDescriptors = new ArrayList<TypeDescriptor>();

Expand Down Expand Up @@ -118,6 +121,10 @@ private void initCsTypeMap() {
typeMap.addGenericTypeMapping("java.util.Set", "System.Collections.Generic.ICollection");
}

public Map<String, String> getClassMap() {
return classMap;
}

public TypeMap getAnnotationMap() {
return annotationMap;
}
Expand Down Expand Up @@ -180,7 +187,7 @@ public void addEnumField(Type classType, Type fieldType, String name, Object val


public void addField(Type classType, int modifier, Type fieldType, String propertyName, Object value, String comment) {
fieldDescriptor = new FieldDescriptor(modifier, fieldType, propertyName, value);
fieldDescriptor = new FieldDescriptor(modifier, fieldType, propertyName, value, getClassMap());
setFieldDescription(comment);

typeDescriptor.addFieldDescriptor(fieldDescriptor);
Expand All @@ -194,16 +201,13 @@ public void addInterface(Type name) {

public void addParameter(Type classType, Type methodType, Type type, String name) {
if (methodDescriptor != null) {
ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name);
ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name, getClassMap());
methodDescriptor.addParameterDescriptor(parameterDescriptor);
}
if (proxyMethodDescriptor != null) {


type = replaceType(type);


ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name);
ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name, getClassMap());
proxyMethodDescriptor.addParameterDescriptor(parameterDescriptor);
}
}
Expand All @@ -219,22 +223,24 @@ private Type replaceType(Type type) {
}
}

return new Type(type.getName(), arguments, type.getBounds(), type.getDimensions(), type.isGeneric());
return new Type(type.getName(), arguments, type.getBounds(), type.getDimensions(), type.isGeneric(), getClassMap());
}


public void beginClass(Type type) {
beginType(new ClassDescriptor(type, type.getName() + suffix));
getClassMap().put(type.getName(), type.getName() + suffix);

beginType(new ClassDescriptor(type, getClassMap()));
}


public void beginEnum(Type type) {
beginType(new EnumDescriptor(type));
beginType(new EnumDescriptor(type, getClassMap()));
}


public void beginGetter(Type classType, Type methodType, int modifier, Type returnType, String propertyName, String description, boolean override) {
propertyDescriptor = new PropertyDescriptor(modifier, returnType, methodType, propertyName);
propertyDescriptor = new PropertyDescriptor(modifier, returnType, methodType, propertyName, getClassMap());
propertyDescriptor.setGetter(true);
propertyDescriptor.setOverride(override);
propertyDescriptor.setDescription(description);
Expand All @@ -247,7 +253,7 @@ public void beginGetter(Type classType, Type methodType, int modifier, Type retu


public void beginInterface(Type type) {
beginType(new InterfaceDescriptor(type));
beginType(new InterfaceDescriptor(type, getClassMap()));
}


Expand All @@ -257,19 +263,19 @@ public void beginMethod(Type classType, Type methodType, int modifier, Type retu

public void beginMethod(Type classType, Type methodType, int modifier, Type returnType, String methodName, boolean asnyc, boolean override, String verb) {
if (typeDescriptor != null) {
methodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc);
methodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc, this);
methodDescriptor.setOverride(override);
typeDescriptor.addMethodDescriptor(methodDescriptor);
}
if (proxyTypeDescriptor != null) {
proxyMethodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc, verb);
proxyMethodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc, this, verb);
proxyTypeDescriptor.addMethodDescriptor(proxyMethodDescriptor);
}
}


public void beginProxy(Type proxy, Type baseType, Type interfaceType) {
proxyTypeDescriptor = new ProxyDescriptor(proxy);
proxyTypeDescriptor = new ProxyDescriptor(proxy, getClassMap());
proxyTypeDescriptor.addInterface(interfaceType);

if (baseType != Type.NULL) proxyTypeDescriptor.setSuperclass(baseType);
Expand All @@ -279,7 +285,7 @@ public void beginProxy(Type proxy, Type baseType, Type interfaceType) {


public void beginSetter(Type classType, Type methodType, int modifier, Type returnType, String propertyName, String description, boolean override) {
propertyDescriptor = new PropertyDescriptor(modifier, returnType, methodType, propertyName);
propertyDescriptor = new PropertyDescriptor(modifier, returnType, methodType, propertyName, getClassMap());
propertyDescriptor.setSetter(true);
propertyDescriptor.setOverride(override);
propertyDescriptor.setDescription(description);
Expand Down

0 comments on commit f29e3c3

Please sign in to comment.