private static JSAPResult parseArgs(JSAP jsapSpec, String[] commandLineArgs) { OUTPUT_LOGGER.info("JSweet transpiler version " + JSweetConfig.getVersionNumber() + " (build date: " + JSweetConfig.getBuildDate() + ")"); if (jsapSpec == null) { throw new IllegalStateException("no args, please call setArgs before"); } JSAPResult arguments = jsapSpec.parse(commandLineArgs); if (!arguments.success()) { // print out specific error messages describing the problems for (java.util.Iterator<?> errs = arguments.getErrorMessageIterator(); errs.hasNext();) { System.out.println("Error: " + errs.next()); } } if (!arguments.success() || arguments.getBoolean("help")) { } return arguments; }
@Override public String needsImport(ImportElement importElement, String qualifiedName) { if (isJDKPath(qualifiedName)) { return null; } return super.needsImport(importElement, qualifiedName); }
/** * Checks that the given field access conforms to JSweet contraints. */ public boolean checkSelect(JCFieldAccess select) { if (!JSweetConfig.isJDKReplacementMode()) { if (select.selected.type instanceof ClassType) { String type = select.selected.type.tsym.toString(); if (type.startsWith("java.")) { if (!jdkAllowed && !(AUTHORIZED_ACCESSED_TYPES.contains(type) || type.startsWith("java.util.function"))) { translator.report(select, JSweetProblem.JDK_TYPE, type); return false; } } } } return true; }
JSweetConfig.initClassPath(jsapArgs.getString("jdkHome"));
private String normalizeVersion(String version) { if (version == null) { return null; } String[] v = JSweetConfig.getVersionNumber().split("\\."); if (v.length == 2) { return version; } else if (v.length == 1) { return v[0] + ".0"; } else { return v[0] + "." + v[1]; } }
@Override public String needsImport(ImportElement importElement, String qualifiedName) { JCImport importDecl = ((ImportElementSupport) importElement).getTree(); if (isJSweetPath(qualifiedName) || isMappedType(qualifiedName) || context.getLangTypeMappings().containsKey(qualifiedName) || qualifiedName.startsWith("java.util.function.")
keywordHandled = true; if (JSweetConfig.isLibPath(methSym.getEnclosingElement().getQualifiedName().toString())) { methodName = methName.toLowerCase();
JSweetConfig.initClassPath(jdkHome.getAbsolutePath());
private void checkCandyVersion(CandyDescriptor candy, TranspilationHandler transpilationHandler) { String actualTranspilerVersion = normalizeVersion(JSweetConfig.getVersionNumber().split("-")[0]); String candyTranspilerVersion = normalizeVersion( candy.transpilerVersion == null ? null : candy.transpilerVersion.split("-")[0]); if (candyTranspilerVersion == null || !candyTranspilerVersion.equals(actualTranspilerVersion)) { transpilationHandler.report(JSweetProblem.CANDY_VERSION_DISCREPANCY, null, JSweetProblem.CANDY_VERSION_DISCREPANCY.getMessage(candy.name, candy.version, actualTranspilerVersion, candyTranspilerVersion)); } }
this.classPath = classPath; logger.info("creating transpiler version " + JSweetConfig.getVersionNumber() + " (build date: " + JSweetConfig.getBuildDate() + ")"); logger.info("current dir: " + new File(".").getAbsolutePath()); logger.info("base directory: " + this.baseDirectory.getAbsolutePath());
/** * Checks that the given type is JSweet compatible. */ public boolean checkType(JCTree declaringElement, Name declaringElementName, JCExpression typeExpression) { if (!JSweetConfig.isJDKReplacementMode()) { if (typeExpression instanceof JCArrayTypeTree) { return checkType(declaringElement, declaringElementName, ((JCArrayTypeTree) typeExpression).elemtype); } String type = typeExpression.type.tsym.toString(); if (!jdkAllowed && !translator.getContext().strictMode && type.startsWith("java.")) { if (!(AUTHORIZED_DECLARED_TYPES.contains(type) || NUMBER_TYPES.contains(type) || type.startsWith("java.util.function"))) { translator.report(declaringElement, declaringElementName, JSweetProblem.JDK_TYPE, type); return false; } } } return true; }
private String[] getHeaderLines() { String[] headerLines = null; if (getHeaderFile() != null) { try { headerLines = FileUtils.readLines(getHeaderFile(), getEncoding()).toArray(new String[0]); } catch (Exception e) { logger.error("cannot read header file: " + getHeaderFile() + " - using default header"); } } if (headerLines == null) { headerLines = new String[] { "/* Generated from Java with JSweet " + JSweetConfig.getVersionNumber() + " - http://www.jsweet.org */" }; } if (context.options.isDebugMode()) { headerLines = ArrayUtils.add(headerLines, "declare function __debug_exec(className, functionName, argNames, target, args, generator);"); headerLines = ArrayUtils.add(headerLines, "declare function __debug_result(expression);"); } return headerLines; }
@Override public boolean substituteForEachLoop(ForeachLoopElement foreachLoop, boolean targetHasLength, String indexVarName) { JCEnhancedForLoop loop = ((ForeachLoopElementSupport) foreachLoop).getTree(); if (!targetHasLength && !isJDKPath(loop.expr.type.toString()) && types().isSubtype(loop.expr.type, types().erasure(util().getType(Iterable.class)))) { printForEachLoop(loop, indexVarName); return true; } // return super.substituteForEachLoop(foreachLoop, targetHasLength, // indexVarName); return false; }
/** * Checks that the given invocation conforms to JSweet contraints. */ public boolean checkApply(JCMethodInvocation invocation, MethodSymbol methSym) { // if (Util.hasAnnotationType(methSym, JSweetConfig.ANNOTATION_ERASED)) // { // translator.report(invocation, JSweetProblem.ERASED_METHOD, methSym); // } if (!JSweetConfig.isJDKReplacementMode() && !jdkAllowed) { if (methSym.owner.toString().startsWith("java.")) { if (invocation.meth instanceof JCFieldAccess && "super".equals(((JCFieldAccess) invocation.meth).selected.toString())) { translator.report(invocation, JSweetProblem.JDK_METHOD, methSym); return false; } if (translator.getContext().strictMode || AUTHORIZED_OBJECT_METHODS.contains(methSym.name.toString())) { return true; } if (methSym.owner.toString().equals(String.class.getName()) && AUTHORIZED_STRING_METHODS.contains(methSym.toString())) { return true; } translator.report(invocation, JSweetProblem.JDK_METHOD, methSym); return false; } } return true; }
if (!removeIterable && !JSweetConfig.isJDKReplacementMode() && !(JSweetConfig.OBJECT_CLASSNAME.equals(classdecl.extending.type.toString()) || Object.class.getName().equals(classdecl.extending.type.toString()))