mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
Merge branch 'master' of https://github.com/cincheo/jsweet
This commit is contained in:
commit
3b106e86e2
@ -987,10 +987,14 @@ public class JSweetContext extends Context {
|
||||
* Gets the first value of the 'value' property for the given annotation
|
||||
* type if found on the given symbol.
|
||||
*/
|
||||
public String getAnnotationValue(Symbol symbol, String annotationType, String defaultValue) {
|
||||
public final String getAnnotationValue(Symbol symbol, String annotationType, String defaultValue) {
|
||||
return getAnnotationValue(symbol, annotationType, null, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first value of the given property for the given annotation type
|
||||
* if found on the given symbol.
|
||||
*/
|
||||
public String getAnnotationValue(Symbol symbol, String annotationType, String propertyName, String defaultValue) {
|
||||
if (hasAnnotationFilters()) {
|
||||
String signature = symbol.toString();
|
||||
|
||||
@ -95,14 +95,14 @@ public class RemoveJavaDependenciesAdapter<C extends JSweetContext> extends Java
|
||||
extTypesMapping.put(Calendar.class.getName(), "Date");
|
||||
extTypesMapping.put(GregorianCalendar.class.getName(), "Date");
|
||||
extTypesMapping.put(TimeZone.class.getName(), "string");
|
||||
typesMapping.putAll(extTypesMapping);
|
||||
complexTypesMapping
|
||||
.add((typeTree,
|
||||
addTypeMappings(extTypesMapping);
|
||||
addTypeMapping(
|
||||
(typeTree,
|
||||
name) -> name.startsWith("java.")
|
||||
&& context.types.isSubtype(typeTree.type, context.symtab.throwableType) ? "Error"
|
||||
: null);
|
||||
complexTypesMapping
|
||||
.add((typeTree,
|
||||
addTypeMapping(
|
||||
(typeTree,
|
||||
name) -> typeTree instanceof JCTypeApply && WeakReference.class.getName()
|
||||
.equals(typeTree.type.tsym.getQualifiedName().toString())
|
||||
? ((JCTypeApply) typeTree).arguments.head : null);
|
||||
@ -541,8 +541,8 @@ public class RemoveJavaDependenciesAdapter<C extends JSweetContext> extends Java
|
||||
|
||||
@Override
|
||||
protected boolean substituteFieldAccess(JCFieldAccess fieldAccess, TypeSymbol targetType, String accessedType) {
|
||||
if (fieldAccess.sym.isStatic() && typesMapping.containsKey(accessedType)
|
||||
&& accessedType.startsWith("java.lang.") && !"class".equals(fieldAccess.name.toString())) {
|
||||
if (fieldAccess.sym.isStatic() && isMappedType(accessedType) && accessedType.startsWith("java.lang.")
|
||||
&& !"class".equals(fieldAccess.name.toString())) {
|
||||
|
||||
switch (accessedType) {
|
||||
case "java.lang.Float":
|
||||
|
||||
@ -125,8 +125,8 @@ public class Java2TypeScriptAdapter<C extends JSweetContext> extends AbstractPri
|
||||
|
||||
private final static String VAR_DECL_KEYWORD = Java2TypeScriptTranslator.VAR_DECL_KEYWORD;
|
||||
|
||||
protected Map<String, String> typesMapping = new HashMap<String, String>();
|
||||
protected List<BiFunction<JCTree, String, Object>> complexTypesMapping = new ArrayList<>();
|
||||
private Map<String, String> typesMapping = new HashMap<String, String>();
|
||||
private List<BiFunction<JCTree, String, Object>> complexTypesMapping = new ArrayList<>();
|
||||
protected Map<String, String> langTypesMapping = new HashMap<String, String>();
|
||||
protected Set<String> langTypesSimpleNames = new HashSet<String>();
|
||||
protected Set<String> baseThrowables = new HashSet<String>();
|
||||
@ -230,6 +230,51 @@ public class Java2TypeScriptAdapter<C extends JSweetContext> extends AbstractPri
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a type mapping so that this adapter substitutes the source type with
|
||||
* the target type during the transpilation process.
|
||||
*
|
||||
* @param sourceTypeName
|
||||
* the fully qualified name of the type to be substituted
|
||||
* @param targetTypeName
|
||||
* the fully Qualified name of the type the source type is mapped
|
||||
* to
|
||||
*/
|
||||
public void addTypeMapping(String sourceTypeName, String targetTypeName) {
|
||||
typesMapping.put(sourceTypeName, targetTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of name-based type mappings. This method is equivalent to
|
||||
* calling {@link #addTypeMapping(String, String)} for each entry of the
|
||||
* given map.
|
||||
*/
|
||||
public void addTypeMappings(Map<String, String> nameMappings) {
|
||||
typesMapping.putAll(nameMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given type name is mapped through the
|
||||
* {@link #addTypeMapping(String, String)} or
|
||||
* {@link #addTypeMapping(String, String)} function.
|
||||
*/
|
||||
public boolean isMappedType(String sourceTypeName) {
|
||||
return typesMapping.containsKey(sourceTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a type mapping so that this adapter substitutes the source type tree
|
||||
* with a target type during the transpilation process.
|
||||
*
|
||||
* @param mappingFunction
|
||||
* a function that takes the type tree, the type name, and
|
||||
* returns a substitution (either under the form of a string, or
|
||||
* of a string, or of another type tree).
|
||||
*/
|
||||
public void addTypeMapping(BiFunction<JCTree, String, Object> mappingFunction) {
|
||||
complexTypesMapping.add(mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String needsImport(JCImport importDecl, String qualifiedName) {
|
||||
if (isJSweetPath(qualifiedName) || typesMapping.containsKey(qualifiedName)
|
||||
|
||||
@ -440,7 +440,7 @@ public abstract class AbstractPrinterAdapter<C extends JSweetContext> {
|
||||
* @return the adapted comment (null will remove the JavaDoc comment)
|
||||
*/
|
||||
public String adaptDocComment(JCTree element, String commentText) {
|
||||
return commentText;
|
||||
return parentAdapter == null ? commentText : parentAdapter.adaptDocComment(element, commentText);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user