mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
added test
This commit is contained in:
parent
e017835bea
commit
dd37b94ff9
@ -151,8 +151,9 @@ public class ECJEvaluatorFactory extends AbstractEvaluatorFactory {
|
||||
}
|
||||
|
||||
private boolean isClass(String result) {
|
||||
if (Strings.isNullOrEmpty(result))
|
||||
if (Strings.isNullOrEmpty(result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if it's the class we're compiling, then of course it's a class
|
||||
if (result.equals(targetName)) {
|
||||
@ -171,11 +172,7 @@ public class ECJEvaluatorFactory extends AbstractEvaluatorFactory {
|
||||
is = parentClassLoader.getResourceAsStream("java/lang/" + resourceName);
|
||||
}
|
||||
}
|
||||
if (is == null) {
|
||||
return false; // if it's a class, we sure couldn't load it
|
||||
} else {
|
||||
return true; // we actually loaded the class, so it must be one
|
||||
}
|
||||
return is != null;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
@ -285,10 +282,11 @@ public class ECJEvaluatorFactory extends AbstractEvaluatorFactory {
|
||||
// not one of our checked exceptions boxed as unchecked; just rethrow
|
||||
Throwable cause = ex.getCause();
|
||||
if (cause != null) {
|
||||
if (cause instanceof IOException)
|
||||
if (cause instanceof IOException) {
|
||||
throw (IOException)cause;
|
||||
else if (cause instanceof ClassFormatException)
|
||||
} else if (cause instanceof ClassFormatException) {
|
||||
throw new IOException(cause);
|
||||
}
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@ -23,6 +23,8 @@ import java.net.URI;
|
||||
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
* MemJavaFileObject defines an in memory compiled Java file
|
||||
*
|
||||
@ -45,7 +47,7 @@ public class MemJavaFileObject extends SimpleJavaFileObject {
|
||||
if (baos == null) {
|
||||
throw new FileNotFoundException(name);
|
||||
}
|
||||
return new String(baos.toByteArray());
|
||||
return new String(baos.toByteArray(), Charsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -25,7 +25,7 @@ public final class StringUtils {
|
||||
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, str);
|
||||
}
|
||||
|
||||
public static String escapeJava(String str) {
|
||||
public static String escapeJava(String str) {
|
||||
str = str.replace("\\", "\\\\");
|
||||
str = str.replace("\"", "\\\"");
|
||||
str = str.replace("\r", "\\\r");
|
||||
|
||||
@ -32,7 +32,6 @@ public final class ClassUtils {
|
||||
}
|
||||
|
||||
public static String getFullName(Class<?> cl) {
|
||||
// return cl.getCanonicalName();
|
||||
if (cl.isArray()) {
|
||||
return getFullName(cl.getComponentType()) + "[]";
|
||||
}
|
||||
@ -69,10 +68,8 @@ public final class ClassUtils {
|
||||
return canonicalName;
|
||||
} else {
|
||||
final String packageName = canonicalName.substring(0, i);
|
||||
if (packages.contains(packageName)
|
||||
|| classes.contains(canonicalName)
|
||||
|| classes.contains(canonicalName.substring(0, canonicalName.lastIndexOf('.')))) {
|
||||
return canonicalName.substring(packageName.length() + 1);
|
||||
if (packages.contains(packageName) || classes.contains(canonicalName)) {
|
||||
return cl.getSimpleName();
|
||||
} else {
|
||||
return canonicalName;
|
||||
}
|
||||
|
||||
@ -35,6 +35,14 @@ public class ClassUtilsTest {
|
||||
assertEquals("java.util.Locale", ClassUtils.getName(Locale.class));
|
||||
assertEquals("java.util.Locale[]", ClassUtils.getName(Locale[].class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GetName_Packge() {
|
||||
assertEquals("Locale", ClassUtils.getName(Locale.class,
|
||||
Collections.singleton("java.util"), Collections.<String>emptySet()));
|
||||
assertEquals("java.util.Locale", ClassUtils.getName(Locale.class,
|
||||
Collections.singleton("java.util.gen"), Collections.<String>emptySet()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Normalize() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user