mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
use strict equality for core types (more generic + utility functions)
This commit is contained in:
parent
0fb29d765a
commit
f91c0cf37a
@ -72,6 +72,7 @@ import javax.lang.model.element.ElementKind;
|
|||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.type.PrimitiveType;
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
|
||||||
@ -1285,9 +1286,9 @@ public class Java2TypeScriptAdapter extends PrinterAdapter {
|
|||||||
} else {
|
} else {
|
||||||
switch (targetMethodName) {
|
switch (targetMethodName) {
|
||||||
case "equals":
|
case "equals":
|
||||||
if (types().isSameType(invocationElement.getTargetExpression().getType(),
|
TypeMirror t1 = util().toPrimitiveTypeOrType(invocationElement.getTargetExpression().getType());
|
||||||
util().getType(String.class))
|
TypeMirror t2 = util().toPrimitiveTypeOrType(invocationElement.getArgument(0).getType());
|
||||||
|| util().isNumber(invocationElement.getTargetExpression().getType())) {
|
if (types().isSameType(t1, t2) && util().isCoreType(t1)) {
|
||||||
if(isInlinedExpression(invocationElement)) {
|
if(isInlinedExpression(invocationElement)) {
|
||||||
print("(");
|
print("(");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,11 @@ public interface Util {
|
|||||||
*/
|
*/
|
||||||
boolean isNumber(TypeMirror type);
|
boolean isNumber(TypeMirror type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells if the given type is a boolean.
|
||||||
|
*/
|
||||||
|
boolean isBoolean(TypeMirror type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the given element is deprecated.
|
* Tells if the given element is deprecated.
|
||||||
*/
|
*/
|
||||||
@ -125,5 +130,13 @@ public interface Util {
|
|||||||
* @return a list of all the members
|
* @return a list of all the members
|
||||||
*/
|
*/
|
||||||
List<Element> getAllMembers(TypeElement typeElement);
|
List<Element> getAllMembers(TypeElement typeElement);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the type as a primitive type (by unboxing it) when possible.
|
||||||
|
*
|
||||||
|
* @param type the origin type
|
||||||
|
* @return the origin type or the corresponding primitive type if possible
|
||||||
|
*/
|
||||||
|
TypeMirror toPrimitiveTypeOrType(TypeMirror type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,6 +157,11 @@ public class UtilSupport implements Util {
|
|||||||
return org.jsweet.transpiler.util.Util.isNumber(type);
|
return org.jsweet.transpiler.util.Util.isNumber(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBoolean(TypeMirror type) {
|
||||||
|
return org.jsweet.transpiler.util.Util.isBoolean(type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDeprecated(Element element) {
|
public boolean isDeprecated(Element element) {
|
||||||
return org.jsweet.transpiler.util.Util.isDeprecated(element);
|
return org.jsweet.transpiler.util.Util.isDeprecated(element);
|
||||||
@ -231,4 +236,12 @@ public class UtilSupport implements Util {
|
|||||||
return getAllMembers((TypeElement)context.modelTypes.asElement(type));
|
return getAllMembers((TypeElement)context.modelTypes.asElement(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeMirror toPrimitiveTypeOrType(TypeMirror type) {
|
||||||
|
try {
|
||||||
|
return context.types.unboxedTypeOrType((Type)type);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1059,6 +1059,21 @@ public class Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true is the type is a boolean.
|
||||||
|
*/
|
||||||
|
public static boolean isBoolean(TypeMirror type) {
|
||||||
|
if (type == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (type.getKind()) {
|
||||||
|
case BOOLEAN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true is the type is a core.
|
* Returns true is the type is a core.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user