Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly replace fully qualified class names #80

Merged
merged 2 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/main/java/org/fulib/builder/ReflectiveClassBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class ReflectiveClassBuilder
{
private static final String ID_PATTERN = "\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*";
private static final Pattern CLASS_PATTERN = Pattern.compile("class (" + ID_PATTERN + "(?:\\." + ID_PATTERN + ")*)");
private static final Pattern CLASS_PATTERN = Pattern.compile(ID_PATTERN + "(?:\\." + ID_PATTERN + ")*");

static Clazz load(Class<?> classDef, ClassModelManager manager)
{
Expand Down Expand Up @@ -101,13 +101,13 @@ private static String getType(Field field, CollectionType collectionType)

private static String toSource(Class<?> base, Type type)
{
final String input = type.toString();
final String input = type.getTypeName();
final Matcher matcher = CLASS_PATTERN.matcher(input);
final StringBuilder sb = new StringBuilder();
int prev = 0;
while (matcher.find())
{
final String className = matcher.group(1);
final String className = matcher.group();
sb.append(input, prev, matcher.start());
toSource(base, className, sb);
prev = matcher.end();
Expand All @@ -116,7 +116,23 @@ private static String toSource(Class<?> base, Type type)
return sb.toString();
}

private static void toSource(Class<?> base, String className, StringBuilder out) {
private static void toSource(Class<?> base, String className, StringBuilder out)
{
switch (className)
{
case "void":
case "boolean":
case "byte":
case "short":
case "char":
case "int":
case "long":
case "float":
case "double":
out.append(className);
return;
}

try
{
final Class<?> resolved = Class.forName(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Predicate;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -46,6 +47,8 @@ class Employee extends Person

@Link("manager")
List<Employee> subordinates;

Predicate<?> predicate;
}

class University
Expand Down Expand Up @@ -103,6 +106,9 @@ public void test()

final Clazz employee = model.getClazz("Employee");

final Attribute predicate = employee.getAttribute("predicate");
assertThat(predicate.getType(), equalTo("import(java.util.function.Predicate)<?>"));

final AssocRole manager = employee.getRole("manager");
final AssocRole subordinates = employee.getRole("subordinates");

Expand Down