List of usage examples for javax.lang.model.element Modifier DEFAULT
Modifier DEFAULT
To view the source code for javax.lang.model.element Modifier DEFAULT.
Click Source Link
From source file:org.jsweet.transpiler.Java2TypeScriptTranslator.java
@Override public void visitMethodDef(JCMethodDecl methodDecl) { if (context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_ERASED)) { // erased elements are ignored return;/*from w w w . java2s.com*/ } JCClassDecl parent = (JCClassDecl) getParent(); if (parent != null && methodDecl.pos == parent.pos && !getScope().enumWrapperClassScope) { return; } if (JSweetConfig.INDEXED_GET_FUCTION_NAME.equals(methodDecl.getName().toString()) && methodDecl.getParameters().size() == 1) { print("[").print(methodDecl.getParameters().head).print("]: "); substituteAndPrintType(methodDecl.restype).print(";"); return; } constructor = methodDecl.sym.isConstructor(); if (getScope().enumScope) { if (constructor) { if (parent != null && parent.pos != methodDecl.pos) { getScope().isComplexEnum = true; } } else { getScope().isComplexEnum = true; } return; } Overload overload = null; boolean inOverload = false; boolean inCoreWrongOverload = false; if (parent != null) { overload = context.getOverload(parent.sym, methodDecl.sym); inOverload = overload != null && overload.methods.size() > 1; if (inOverload) { if (!overload.isValid) { if (!printCoreMethodDelegate) { if (overload.coreMethod.equals(methodDecl)) { inCoreWrongOverload = true; if (!context.isInterface(parent.sym) && !methodDecl.sym.isConstructor() && parent.sym.equals(overload.coreMethod.sym.getEnclosingElement())) { printCoreMethodDelegate = true; visitMethodDef(overload.coreMethod); println().println().printIndent(); printCoreMethodDelegate = false; } } else { if (methodDecl.sym.isConstructor()) { return; } if (!overload.printed && overload.coreMethod.sym.getEnclosingElement() != parent.sym && !overload.coreMethod.sym.getModifiers().contains(Modifier.ABSTRACT)) { visitMethodDef(overload.coreMethod); overload.printed = true; if (!context.isInterface(parent.sym)) { println().println().printIndent(); } } if (context.isInterface(parent.sym)) { return; } } } } else { if (!overload.coreMethod.equals(methodDecl)) { return; } } } } boolean ambient = context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_AMBIENT); if (inOverload && !inCoreWrongOverload && (ambient || isDefinitionScope)) { // do not generate method stubs for definitions return; } if (isDebugMode(methodDecl)) { printMethodModifiers(methodDecl, parent, constructor, inOverload, overload); print(getTSMethodName(methodDecl)).print("("); printArgList(null, methodDecl.params); print(") : "); substituteAndPrintType(methodDecl.getReturnType()); print(" {").println(); startIndent().printIndent(); if (!context.types.isSameType(context.symtab.voidType, methodDecl.sym.getReturnType())) { print("return "); } print("__debug_exec('" + parent.sym.getQualifiedName() + "', '" + methodDecl.getName() + "', "); if (!methodDecl.params.isEmpty()) { print("["); for (JCVariableDecl param : methodDecl.params) { print("'" + param.getName() + "', "); } removeLastChars(2); print("]"); } else { print("undefined"); } print(", this, arguments, "); if (methodDecl.sym.isStatic()) { print(methodDecl.sym.getEnclosingElement().getSimpleName().toString()); } else { print("this"); } print("." + GENERATOR_PREFIX + getTSMethodName(methodDecl) + "("); for (JCVariableDecl param : methodDecl.params) { print(context.getActualName(param.sym) + ", "); } if (!methodDecl.params.isEmpty()) { removeLastChars(2); } print("));"); println().endIndent().printIndent(); print("}").println().println().printIndent(); } int jsniLine = -1; String[] content = null; if (methodDecl.mods.getFlags().contains(Modifier.NATIVE)) { if (!getScope().declareClassScope && !ambient && !getScope().interfaceScope) { content = getGetSource(getCompilationUnit()); if (content != null) { int line = 0; if (methodDecl.getParameters() != null && !methodDecl.getParameters().isEmpty()) { line = diagnosticSource.getLineNumber(methodDecl.getParameters().last().getStartPosition()) - 1; } else { line = diagnosticSource.getLineNumber(methodDecl.getStartPosition()) - 1; } if (content[line].contains("/*-{")) { jsniLine = line; } else { if (content[line + 1].contains("/*-{")) { jsniLine = line + 1; } } } if (jsniLine == -1) { report(methodDecl, methodDecl.name, JSweetProblem.NATIVE_MODIFIER_IS_NOT_ALLOWED, methodDecl.name); } } } else { if (getScope().declareClassScope && !constructor && !getScope().interfaceScope && !methodDecl.mods.getFlags().contains(Modifier.DEFAULT)) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } } if (methodDecl.name.toString().equals("constructor")) { report(methodDecl, methodDecl.name, JSweetProblem.CONSTRUCTOR_MEMBER); } if (parent != null) { VarSymbol v = Util.findFieldDeclaration(parent.sym, methodDecl.name); if (v != null && context.getFieldNameMapping(v) == null) { if (isDefinitionScope) { return; } else { report(methodDecl, methodDecl.name, JSweetProblem.METHOD_CONFLICTS_FIELD, methodDecl.name, v.owner); } } } if (JSweetConfig.MAIN_FUNCTION_NAME.equals(methodDecl.name.toString()) && methodDecl.mods.getFlags().contains(Modifier.STATIC) && !context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_DISABLED)) { // ignore main methods in inner classes if (scope.size() == 1) { mainMethod = methodDecl; } } boolean globals = parent == null ? false : JSweetConfig.GLOBALS_CLASS_NAME.equals(parent.name.toString()); globals = globals || (getScope().interfaceScope && methodDecl.mods.getFlags().contains(Modifier.STATIC)); printDocComment(methodDecl, false); if (parent == null) { print("function "); } else if (globals) { if (constructor && methodDecl.sym.isPrivate() && methodDecl.getParameters().isEmpty()) { return; } if (constructor) { report(methodDecl, methodDecl.name, JSweetProblem.GLOBAL_CONSTRUCTOR_DEF); return; } if (!methodDecl.mods.getFlags().contains(Modifier.STATIC)) { report(methodDecl, methodDecl.name, JSweetProblem.GLOBALS_CAN_ONLY_HAVE_STATIC_MEMBERS); return; } if (context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_MODULE)) { getContext().addExportedElement( context.getAnnotationValue(methodDecl.sym, JSweetConfig.ANNOTATION_MODULE, null), methodDecl.sym, getCompilationUnit()); } if (context.useModules) { if (!methodDecl.mods.getFlags().contains(Modifier.PRIVATE)) { print("export "); } } else { if (!isTopLevelScope()) { print("export "); } } if (ambient || (getIndent() == 0 && isDefinitionScope)) { print("declare "); } print("function "); } else { printMethodModifiers(methodDecl, parent, constructor, inOverload, overload); if (ambient) { report(methodDecl, methodDecl.name, JSweetProblem.WRONG_USE_OF_AMBIENT, methodDecl.name); } } if (parent == null || !context.isFunctionalType(parent.sym)) { if (isDebugMode(methodDecl)) { print("*").print(GENERATOR_PREFIX); } if (inOverload && !overload.isValid && !inCoreWrongOverload) { print(getOverloadMethodName(methodDecl.sym)); } else { String tsMethodName = getTSMethodName(methodDecl); if (doesMemberNameRequireQuotes(tsMethodName)) { print("'" + tsMethodName + "'"); } else { print(tsMethodName); } } } if ((methodDecl.typarams != null && !methodDecl.typarams.isEmpty()) || (getContext().getWildcards(methodDecl.sym) != null)) { inTypeParameters = true; print("<"); if (methodDecl.typarams != null && !methodDecl.typarams.isEmpty()) { printArgList(null, methodDecl.typarams); if (getContext().getWildcards(methodDecl.sym) != null) { print(", "); } } if (getContext().getWildcards(methodDecl.sym) != null) { printArgList(null, getContext().getWildcards(methodDecl.sym), this::substituteAndPrintType); } print(">"); inTypeParameters = false; } print("("); if (inCoreWrongOverload) { getScope().eraseVariableTypes = true; } boolean paramPrinted = false; if (getScope().innerClassNotStatic && methodDecl.sym.isConstructor()) { print(PARENT_CLASS_FIELD_NAME + ": any, "); paramPrinted = true; } if (constructor && getScope().enumWrapperClassScope) { print((isAnonymousClass() ? "" : "protected ") + ENUM_WRAPPER_CLASS_ORDINAL + " : number, "); print((isAnonymousClass() ? "" : "protected ") + ENUM_WRAPPER_CLASS_NAME + " : string"); if (!methodDecl.getParameters().isEmpty()) { print(", "); } } int i = 0; for (JCVariableDecl param : methodDecl.getParameters()) { print(param); if (inOverload && overload.isValid && overload.defaultValues.get(i) != null) { print(" = ").print(overload.defaultValues.get(i)); } print(", "); i++; paramPrinted = true; } if (inCoreWrongOverload) { getScope().eraseVariableTypes = false; } if (paramPrinted) { removeLastChars(2); } print(")"); if (inCoreWrongOverload && !methodDecl.sym.isConstructor()) { print(" : any"); } else { if (methodDecl.restype != null && methodDecl.restype.type.getTag() != TypeTag.VOID) { print(" : "); substituteAndPrintType(methodDecl.restype); } } if (inCoreWrongOverload && context.isInterface(parent.sym)) { print(";"); return; } if (methodDecl.getBody() == null && !(inCoreWrongOverload && !getScope().declareClassScope) || (methodDecl.mods.getFlags().contains(Modifier.DEFAULT) && !getScope().defaultMethodScope)) { if (!getScope().interfaceScope && methodDecl.getModifiers().getFlags().contains(Modifier.ABSTRACT) && inOverload && !overload.isValid) { print(" {"); // runtime error if we go there... print(" throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)'); "); print("}"); } else if (jsniLine != -1) { int line = jsniLine; print(" {").println().startIndent(); String jsniCode = content[line].substring(content[line].indexOf("/*-{") + 4).trim(); StringBuilder jsni = new StringBuilder(); if (!StringUtils.isEmpty(jsniCode)) { jsni.append(jsniCode); jsni.append("\n"); } line++; while (!content[line].contains("}-*/")) { jsniCode = content[line++].trim(); jsni.append(jsniCode); jsni.append("\n"); } jsniCode = content[line].substring(0, content[line].indexOf("}-*/")).trim(); if (!StringUtils.isEmpty(jsniCode)) { jsni.append(jsniCode); jsni.append("\n"); } if (!StringUtils.isEmpty(jsni)) { jsni.deleteCharAt(jsni.length() - 1); } String mergedCode = parseJSNI(jsni.toString()); for (String s : mergedCode.split("\\n")) { printIndent().print(s).println(); } endIndent().printIndent().print("}"); } else { print(";"); } } else { if (getScope().interfaceScope) { if (!methodDecl.mods.getFlags().contains(Modifier.STATIC)) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } } if (getScope().declareClassScope) { if (!constructor || (methodDecl.getBody() != null && methodDecl.getBody().getStatements().isEmpty())) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } print(";"); } else { if (inCoreWrongOverload) { print(" {").println().startIndent().printIndent(); boolean wasPrinted = false; for (i = 0; i < overload.methods.size(); i++) { JCMethodDecl method = overload.methods.get(i); if (context.isInterface((ClassSymbol) method.sym.getEnclosingElement()) && !method.getModifiers().getFlags().contains(Modifier.DEFAULT)) { continue; } if (!Util.isParent(parent.sym, (ClassSymbol) method.sym.getEnclosingElement())) { continue; } if (wasPrinted) { print(" else "); } wasPrinted = true; print("if("); printMethodParamsTest(overload, method); print(") "); if (method.sym.isConstructor()) { printInlinedMethod(overload, method, methodDecl.getParameters()); } else { if (parent.sym != method.sym.getEnclosingElement() && context.getOverload((ClassSymbol) method.sym.getEnclosingElement(), method.sym).coreMethod == method) { print("{").println().startIndent().printIndent(); String tsMethodAccess = getTSMemberAccess(getTSMethodName(methodDecl), true); print("super" + tsMethodAccess); print("("); for (int j = 0; j < method.getParameters().size(); j++) { print(avoidJSKeyword( overload.coreMethod.getParameters().get(j).name.toString())) .print(", "); } if (!method.getParameters().isEmpty()) { removeLastChars(2); } print(");"); println().endIndent().printIndent().print("}"); } else { print("{").println().startIndent().printIndent(); // temporary cast to any because of Java // generics // bug print("return <any>"); if (method.sym.isStatic()) { print(getQualifiedTypeName(parent.sym, false).toString()); } else { print("this"); } print(".").print(getOverloadMethodName(method.sym)).print("("); for (int j = 0; j < method.getParameters().size(); j++) { print(avoidJSKeyword( overload.coreMethod.getParameters().get(j).name.toString())) .print(", "); } if (!method.getParameters().isEmpty()) { removeLastChars(2); } print(");"); println().endIndent().printIndent().print("}"); } } } print(" else throw new Error('invalid overload');"); endIndent().println().printIndent().print("}"); } else { print(" ").print("{").println().startIndent(); String replacedBody = null; if (context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_REPLACE)) { replacedBody = (String) context.getAnnotationValue(methodDecl.sym, JSweetConfig.ANNOTATION_REPLACE, null); } int position = getCurrentPosition(); if (replacedBody == null || replacedBody.contains(BODY_MARKER)) { enter(methodDecl.getBody()); if (!methodDecl.getBody().stats.isEmpty() && methodDecl.getBody().stats.head.toString().startsWith("super(")) { printBlockStatement(methodDecl.getBody().stats.head); if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); } printBlockStatements(methodDecl.getBody().stats.tail); } else { if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); } printBlockStatements(methodDecl.getBody().stats); } exit(); if (replacedBody != null) { String orgBody = getOutput().substring(position); removeLastChars(getCurrentPosition() - position); replacedBody = replacedBody.replace(BODY_MARKER, orgBody) .replace(BASE_INDENT_MARKER, getIndentString()).replace(INDENT_MARKER, INDENT) .replace(METHOD_NAME_MARKER, methodDecl.getName().toString()) .replace(CLASS_NAME_MARKER, parent.sym.getQualifiedName().toString()); } } if (replacedBody != null) { printIndent().print(replacedBody).println(); } endIndent().printIndent().print("}"); } } } }
From source file:org.jsweet.transpiler.typescript.Java2TypeScriptTranslator.java
@Override public void visitMethodDef(JCMethodDecl methodDecl) { if (context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_ERASED)) { // erased elements are ignored return;/* ww w . ja v a 2s .co m*/ } JCClassDecl parent = (JCClassDecl) getParent(); if (parent != null && methodDecl.pos == parent.pos && !getScope().enumWrapperClassScope) { return; } if (JSweetConfig.INDEXED_GET_FUCTION_NAME.equals(methodDecl.getName().toString()) && methodDecl.getParameters().size() == 1) { print("[").print(methodDecl.getParameters().head).print("]: "); getAdapter().substituteAndPrintType(methodDecl.restype).print(";"); return; } boolean constructor = methodDecl.sym.isConstructor(); if (getScope().enumScope) { if (constructor) { if (parent != null && parent.pos != methodDecl.pos) { getScope().isComplexEnum = true; } } else { getScope().isComplexEnum = true; } return; } Overload overload = null; boolean inOverload = false; boolean inCoreWrongOverload = false; if (parent != null) { overload = context.getOverload(parent.sym, methodDecl.sym); inOverload = overload != null && overload.methods.size() > 1; if (inOverload) { if (!overload.isValid) { if (overload.coreMethod.equals(methodDecl)) { inCoreWrongOverload = true; } else { if (methodDecl.sym.isConstructor()) { return; } if (!overload.printed && overload.coreMethod.sym.getEnclosingElement() != parent.sym && !Util.isParent(parent.sym, (ClassSymbol) overload.coreMethod.sym.getEnclosingElement())) { visitMethodDef(overload.coreMethod); overload.printed = true; if (!context.isInterface(parent.sym)) { println().println().printIndent(); } } if (context.isInterface(parent.sym)) { return; } } } else { if (!overload.coreMethod.equals(methodDecl)) { return; } } } } boolean ambient = context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_AMBIENT); if (inOverload && !inCoreWrongOverload && (ambient || isDefinitionScope)) { // do not generate method stubs for definitions return; } int jsniLine = -1; String[] content = null; if (methodDecl.mods.getFlags().contains(Modifier.NATIVE)) { if (!getScope().declareClassScope && !ambient && !getScope().interfaceScope) { content = getGetSource(getCompilationUnit()); if (content != null) { int line = 0; if (methodDecl.getParameters() != null && !methodDecl.getParameters().isEmpty()) { line = diagnosticSource.getLineNumber(methodDecl.getParameters().last().getStartPosition()) - 1; } else { line = diagnosticSource.getLineNumber(methodDecl.getStartPosition()) - 1; } if (content[line].contains("/*-{")) { jsniLine = line; } else { if (content[line + 1].contains("/*-{")) { jsniLine = line + 1; } } } if (jsniLine == -1) { report(methodDecl, methodDecl.name, JSweetProblem.NATIVE_MODIFIER_IS_NOT_ALLOWED, methodDecl.name); } } } else { if (getScope().declareClassScope && !constructor && !getScope().interfaceScope && !methodDecl.mods.getFlags().contains(Modifier.DEFAULT)) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } } if (methodDecl.name.toString().equals("constructor")) { report(methodDecl, methodDecl.name, JSweetProblem.CONSTRUCTOR_MEMBER); } if (parent != null) { VarSymbol v = Util.findFieldDeclaration(parent.sym, methodDecl.name); if (v != null && context.getFieldNameMapping(v) == null) { if (isDefinitionScope) { return; } else { report(methodDecl, methodDecl.name, JSweetProblem.METHOD_CONFLICTS_FIELD, methodDecl.name, v.owner); } } } if (JSweetConfig.MAIN_FUNCTION_NAME.equals(methodDecl.name.toString()) && methodDecl.mods.getFlags().contains(Modifier.STATIC) && !context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_DISABLED)) { // ignore main methods in inner classes if (scope.size() == 1) { mainMethod = methodDecl; } } boolean globals = parent == null ? false : JSweetConfig.GLOBALS_CLASS_NAME.equals(parent.name.toString()); globals = globals || (getScope().interfaceScope && methodDecl.mods.getFlags().contains(Modifier.STATIC)); printDocComment(methodDecl, false); if (parent == null) { print("function "); } else if (globals) { if (constructor && methodDecl.sym.isPrivate() && methodDecl.getParameters().isEmpty()) { return; } if (constructor) { report(methodDecl, methodDecl.name, JSweetProblem.GLOBAL_CONSTRUCTOR_DEF); return; } if (!methodDecl.mods.getFlags().contains(Modifier.STATIC)) { report(methodDecl, methodDecl.name, JSweetProblem.GLOBALS_CAN_ONLY_HAVE_STATIC_MEMBERS); return; } if (context.hasAnnotationType(methodDecl.sym, JSweetConfig.ANNOTATION_MODULE)) { getContext().addExportedElement( context.getAnnotationValue(methodDecl.sym, JSweetConfig.ANNOTATION_MODULE, null), methodDecl.sym); } if (context.useModules) { if (!methodDecl.mods.getFlags().contains(Modifier.PRIVATE)) { print("export "); } } else { if (!globalModule) { print("export "); } } if (ambient || (getIndent() == 0 && isDefinitionScope)) { print("declare "); } print("function "); } else { if (methodDecl.mods.getFlags().contains(Modifier.PUBLIC) || (inOverload && overload.coreMethod.equals(methodDecl))) { if (!getScope().interfaceScope) { print("public "); } } if (methodDecl.mods.getFlags().contains(Modifier.PRIVATE)) { if (!constructor) { if (!getScope().innerClass) { if (!getScope().interfaceScope) { if (!(inOverload && overload.coreMethod.equals(methodDecl) || getScope().hasInnerClass)) { print("private "); } } else { if (!(inOverload && overload.coreMethod.equals(methodDecl))) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_PRIVATE_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } } } } } if (methodDecl.mods.getFlags().contains(Modifier.STATIC)) { if (!getScope().interfaceScope) { print("static "); } } if (methodDecl.mods.getFlags().contains(Modifier.ABSTRACT)) { if (!getScope().interfaceScope && !inOverload) { print("abstract "); } } if (ambient) { report(methodDecl, methodDecl.name, JSweetProblem.WRONG_USE_OF_AMBIENT, methodDecl.name); } } if (parent == null || !context.hasAnnotationType(parent.sym, FunctionalInterface.class.getName())) { if (inOverload && !overload.isValid && !inCoreWrongOverload) { print(getOverloadMethodName(methodDecl)); } else { print(getTSMethodName(methodDecl)); } } if ((methodDecl.typarams != null && !methodDecl.typarams.isEmpty()) || (getContext().getWildcards(methodDecl.sym) != null)) { getAdapter().inTypeParameters = true; print("<"); if (methodDecl.typarams != null && !methodDecl.typarams.isEmpty()) { printArgList(methodDecl.typarams); if (getContext().getWildcards(methodDecl.sym) != null) { print(", "); } } if (getContext().getWildcards(methodDecl.sym) != null) { printArgList(getContext().getWildcards(methodDecl.sym), getAdapter()::substituteAndPrintType); } print(">"); getAdapter().inTypeParameters = false; } print("("); if (inCoreWrongOverload) { getScope().eraseVariableTypes = true; } boolean paramPrinted = false; if (getScope().innerClassNotStatic && methodDecl.sym.isConstructor()) { print(PARENT_CLASS_FIELD_NAME + ": any, "); paramPrinted = true; } if (constructor && getScope().enumWrapperClassScope) { print((isAnonymousClass() ? "" : "protected ") + ENUM_WRAPPER_CLASS_ORDINAL + " : number, "); print((isAnonymousClass() ? "" : "protected ") + ENUM_WRAPPER_CLASS_NAME + " : string"); if (!methodDecl.getParameters().isEmpty()) { print(", "); } } int i = 0; for (JCVariableDecl param : methodDecl.getParameters()) { print(param); if (inOverload && overload.isValid && overload.defaultValues.get(i) != null) { print(" = ").print(overload.defaultValues.get(i)); } print(", "); i++; paramPrinted = true; } if (inCoreWrongOverload) { getScope().eraseVariableTypes = false; } if (paramPrinted) { removeLastChars(2); } print(")"); if (inCoreWrongOverload && !methodDecl.sym.isConstructor()) { print(" : any"); } else { if (methodDecl.restype != null && methodDecl.restype.type.getTag() != TypeTag.VOID) { print(" : "); getAdapter().substituteAndPrintType(methodDecl.restype); } } if (inCoreWrongOverload && context.isInterface(parent.sym)) { print(";"); return; } if (methodDecl.getBody() == null && !(inCoreWrongOverload && !getScope().declareClassScope) || (methodDecl.mods.getFlags().contains(Modifier.DEFAULT) && !getScope().defaultMethodScope)) { if (!getScope().interfaceScope && methodDecl.getModifiers().getFlags().contains(Modifier.ABSTRACT) && inOverload && !overload.isValid) { print(" {"); // runtime error if we go there... print(" throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)'); "); print("}"); } else if (jsniLine != -1) { int line = jsniLine; print(" {").println().startIndent(); String jsniCode = content[line].substring(content[line].indexOf("/*-{") + 4).trim(); StringBuilder jsni = new StringBuilder(); if (!StringUtils.isEmpty(jsniCode)) { jsni.append(jsniCode); jsni.append("\n"); } line++; while (!content[line].contains("}-*/")) { jsniCode = content[line++].trim(); jsni.append(jsniCode); jsni.append("\n"); } jsniCode = content[line].substring(0, content[line].indexOf("}-*/")).trim(); if (!StringUtils.isEmpty(jsniCode)) { jsni.append(jsniCode); jsni.append("\n"); } if (!StringUtils.isEmpty(jsni)) { jsni.deleteCharAt(jsni.length() - 1); } String mergedCode = parseJSNI(jsni.toString()); for (String s : mergedCode.split("\\n")) { printIndent().print(s).println(); } endIndent().printIndent().print("}"); } else { print(";"); } } else { if (getScope().interfaceScope) { if (!methodDecl.mods.getFlags().contains(Modifier.STATIC)) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } } if (getScope().declareClassScope) { if (!constructor || (methodDecl.getBody() != null && methodDecl.getBody().getStatements().isEmpty())) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); } print(";"); } else { if (inCoreWrongOverload) { print(" {").println().startIndent().printIndent(); boolean wasPrinted = false; for (i = 0; i < overload.methods.size(); i++) { JCMethodDecl method = overload.methods.get(i); if (context.isInterface((ClassSymbol) method.sym.getEnclosingElement()) && !method.getModifiers().getFlags().contains(Modifier.DEFAULT)) { continue; } if (!Util.isParent(parent.sym, (ClassSymbol) method.sym.getEnclosingElement())) { continue; } if (parent.sym != method.sym.getEnclosingElement() && context.getOverload((ClassSymbol) method.sym.getEnclosingElement(), method.sym).coreMethod == method) { continue; } if (wasPrinted) { print(" else "); } wasPrinted = true; print("if("); printMethodParamsTest(overload, method); print(") "); if (i == 0 || method.sym.isConstructor()) { printInlinedMethod(overload, method, methodDecl.getParameters()); } else { print("{").println().startIndent().printIndent(); // temporary cast to any because of Java generics // bug print("return <any>"); if (method.sym.isStatic()) { print(getQualifiedTypeName(parent.sym, false).toString()); } else { print("this"); } print(".").print(getOverloadMethodName(method)).print("("); for (int j = 0; j < method.getParameters().size(); j++) { print(avoidJSKeyword(overload.coreMethod.getParameters().get(j).name.toString())) .print(", "); } if (!method.getParameters().isEmpty()) { removeLastChars(2); } print(");"); println().endIndent().printIndent().print("}"); } } print(" else throw new Error('invalid overload');"); endIndent().println().printIndent().print("}"); } else { print(" ").print("{").println().startIndent(); enter(methodDecl.getBody()); if (!methodDecl.getBody().stats.isEmpty() && methodDecl.getBody().stats.head.toString().startsWith("super(")) { printBlockStatement(methodDecl.getBody().stats.head); if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); } printBlockStatements(methodDecl.getBody().stats.tail); } else { if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); } printBlockStatements(methodDecl.getBody().stats); } endIndent().printIndent().print("}"); exit(); } } } }