Skip to content

Commit

Permalink
addresses issue #31 (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Nov 12, 2019
1 parent b9c7594 commit 437c402
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/eu/mihosoft/vmf/core/DelegationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ public static DelegationInfo newInstance(Model model, Method m) {
List<String> paramTypes = new ArrayList<>(m.getParameters().length);
List<String> paramNames = new ArrayList<>(m.getParameters().length);

boolean delegated = !m.getName().startsWith("get") && !m.getName().startsWith("is");
boolean varargs = m.isVarArgs();

for(Parameter p : m.getParameters()) {
paramTypes.add(TypeUtil.getTypeAsString(model,p.getType()));
paramTypes.add(TypeUtil.getTypeAsString(model,p.getType(),delegated,varargs));
paramNames.add(p.getName());
}

Expand Down Expand Up @@ -117,11 +120,10 @@ public static DelegationInfo newInstance(Model model, Class<?> clazz) {
List<String> paramTypes = new ArrayList<>();
List<String> paramNames = new ArrayList<>();


return newInstance(
delegation.className(),
"on"+clazz.getSimpleName()+"Instantiated",
TypeUtil.getTypeAsString(model,clazz),
TypeUtil.getTypeAsString(model,clazz,false,false),
paramTypes, paramNames, true,
"" /*constructors are not documented because there's no public API for them*/);
}
Expand Down
59 changes: 44 additions & 15 deletions core/src/main/java/eu/mihosoft/vmf/core/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.List;
import java.util.StringJoiner;

/**
* Created by miho on 21.03.2017.
Expand All @@ -49,7 +51,7 @@ private TypeUtil() {
* @param cls class object to convert
* @return the specified type as string
*/
public static String getTypeAsString(Model model, Class<?> cls) {
public static String getTypeAsString(Model model, Class<?> cls, boolean delegated, boolean vararg) {
String packageName;
String typeName;

Expand All @@ -58,14 +60,32 @@ public static String getTypeAsString(Model model, Class<?> cls) {
packageName = "";

} else if (Collection.class.isAssignableFrom(cls)) {
throw new RuntimeException(
"Collections can only be specified with array syntax, i.e., '<Type>[]'");
if(delegated) {
throw new RuntimeException(
"Collections can currently not be used as params in delegated methods. This will be fixed.");
} else {
throw new RuntimeException(
"Collections can only be specified with array syntax, i.e., '<Type>[]'");
}
} else if (cls.isArray()) {
Class<?> containedClazz = cls.getComponentType();
typeName = "VList<" + ModelType.primitiveToBoxedType(
model.convertModelTypeToDestination(containedClazz)) + ">";
if(delegated) {
Class<?> containedClazz = cls.getComponentType();
typeName = containedClazz.getSimpleName();
packageName = model.
convertModelPackageToDestination(TypeUtil.getPackageName(containedClazz));
if(vararg) {
typeName +="...";
} else {
typeName +="[]";
}
packageName = "";
} else {
Class<?> containedClazz = cls.getComponentType();
typeName = "VList<" + ModelType.primitiveToBoxedType(
model.convertModelTypeToDestination(containedClazz)) + ">";

packageName = "eu.mihosoft.vcollections";
packageName = "eu.mihosoft.vcollections";
}

} else {
typeName = cls.getSimpleName();
Expand Down Expand Up @@ -137,18 +157,27 @@ public static String getReturnTypeAsString(Model model, Method m) {
packageName = "eu.mihosoft.vcollections";

} else if (propClass.isArray()) {
Class<?> containedClazz = propClass.getComponentType();
typeName = "VList<" + ModelType.primitiveToBoxedType(
model.
convertModelTypeToDestination(containedClazz)) + ">";
// System.out.println("TYPENAME: " + typeName);
if(m.getName().startsWith("get") || m.getName().startsWith("is")) {
Class<?> containedClazz = propClass.getComponentType();
typeName = "VList<" + ModelType.primitiveToBoxedType(
model.
convertModelTypeToDestination(containedClazz)) + ">";
// System.out.println("TYPENAME: " + typeName);

packageName = "eu.mihosoft.vcollections";
packageName = "eu.mihosoft.vcollections";

genericPackageName = model.
convertModelPackageToDestination(TypeUtil.getPackageName(containedClazz));

genericTypeName = containedClazz.getSimpleName();
} else {
Class<?> containedClazz = propClass.getComponentType();
typeName =
model.convertModelTypeToDestination(containedClazz) + "[]";
packageName = "";
genericPackageName = model.
convertModelPackageToDestination(TypeUtil.getPackageName(containedClazz));

genericTypeName = containedClazz.getSimpleName();
}
} else if (m.getGenericReturnType() != null) {

ParameterizedType retType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,14 @@ class VMFPlugin implements Plugin<Project> {
// potentially other dependencies needed to compile the model definitions

String configName = sourceSet.getTaskName("vmfCompile", "");
Dependency dep = project.dependencies.create(
Dependency dep1 = project.dependencies.create(
"eu.mihosoft.vmf:vmf:$VMF_VERSION")
Dependency dep2 = project.dependencies.create(
"eu.mihosoft.vmf:vmf-runtime:$VMF_VERSION")
def conf = project.configurations.maybeCreate(configName)
conf.defaultDependencies { deps ->
deps.add(dep)
deps.add(dep1)
deps.add(dep2)
}

// 1) Add a new 'vmf' virtual directory mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,8 @@ interface IntLiteral extends CodeElement {
@InterfaceOnly
interface ControlFlowChildNode {
@DelegateTo(className="eu.mihosoft.vmftest.complex.vmf_text.generated.miniclang.ControlFlowChildNodeDelegate")
ControlFlowScope[] parentScopes();
//ControlFlowScope[] parentScopes();
eu.mihosoft.vcollections.VList<ControlFlowScope> parentScopes();
}

@InterfaceOnly
Expand Down

0 comments on commit 437c402

Please sign in to comment.