List of usage examples for com.google.gwt.user.rebind SourceWriter outdent
void outdent();
From source file:net.sf.mmm.util.gwt.base.rebind.AbstractIncrementalGenerator.java
License:Apache License
/** * This method generates the source code to close a block (method body, if-block, while-block, etc.). * /*w w w . j av a2 s . c om*/ * @param sourceWriter is the {@link SourceWriter}. */ protected final void generateSourceCloseBlock(SourceWriter sourceWriter) { sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println(); }
From source file:net.sf.mmm.util.nls.impl.rebind.AbstractNlsBundleGenerator.java
License:Apache License
/** * Generates the implementation of {@link NlsBundleWithLookup#getMessage(String, Map)}. * //from ww w . j a va 2s. c o m * @param sourceWriter is the {@link SourceWriter}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. * @param method is the {@link NlsBundleWithLookup#getMessage(String, Map)}-method to generate an * implementation for. * @param methods is the list of all declared methods of the bundle. Likely to be ignored but may be used to * generate a switch statement with delegations. */ protected void generateLookupMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context, JMethod method, JMethod[] methods) { generateSourcePublicMethodDeclaration(sourceWriter, method); sourceWriter.print("String "); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.println("= null;"); boolean addElse = false; for (JMethod currentMethod : methods) { if (!isLookupMethod(currentMethod)) { if (addElse) { sourceWriter.print(" else "); } else { addElse = true; } sourceWriter.print("if (methodName.equals(\""); String methodName = currentMethod.getName(); sourceWriter.print(methodName); sourceWriter.println("\")) {"); sourceWriter.indent(); generateMethodMessageBlock(sourceWriter, logger, context, methodName); sourceWriter.outdent(); sourceWriter.print("}"); } else { assert (method == currentMethod); } } // methodName not found/present? sourceWriter.println(); sourceWriter.print("if ("); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.println("== null) {"); sourceWriter.indent(); sourceWriter.println("return null;"); sourceWriter.outdent(); sourceWriter.println("}"); // generate message depending on arguments sourceWriter.print("if (("); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.print(" == null) || ("); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.println(".isEmpty())) {"); sourceWriter.indent(); generateCreateMessageBlock(sourceWriter, false); sourceWriter.outdent(); sourceWriter.println("} else {"); sourceWriter.indent(); generateCreateMessageBlock(sourceWriter, true); sourceWriter.outdent(); sourceWriter.println("}"); generateSourceCloseBlock(sourceWriter); }
From source file:net.sf.mmm.util.nls.impl.rebind.NlsBundleFactoryGenerator.java
License:Apache License
/** * Generates the <code>createBundle</code> method. * /*from w w w . j a v a 2 s.com*/ * @param sourceWriter is the {@link SourceWriter}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. */ protected void generateMethodCreateBundle(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context) { // method declaration sourceWriter.print("public <BUNDLE extends "); sourceWriter.print(NlsBundle.class.getSimpleName()); sourceWriter.println("> BUNDLE createBundle(Class<BUNDLE> bundleInterface) {"); sourceWriter.indent(); // method body sourceWriter.println("BUNDLE bundle = getBundle(bundleInterface);"); sourceWriter.println("if (bundle == null) {"); sourceWriter.indent(); // create and register generateBlockBundleCreation(sourceWriter, logger, context); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("return bundle;"); // end method... sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:net.sf.mmm.util.nls.impl.rebind.NlsBundleFactoryGenerator.java
License:Apache License
/** * Generates the block that creates the {@link NlsBundle} instance lazily via {@link GWT#create(Class)}. * //w w w. j a v a 2 s. c om * @param sourceWriter is the {@link SourceWriter}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. */ protected void generateBlockBundleCreation(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context) { // find all subclasses of NlsBundle TypeOracle typeOracle = context.getTypeOracle(); JClassType bundleClass = typeOracle.findType(NlsBundle.class.getName()); JClassType bundleWithLookupClass = typeOracle.findType(NlsBundleWithLookup.class.getName()); JClassType[] types = typeOracle.getTypes(); int bundleCount = 0; logger.log(Type.INFO, "Checking " + types.length + " types..."); for (JClassType type : types) { if ((type.isAssignableTo(bundleClass)) && (!type.equals(bundleClass) && (!type.equals(bundleWithLookupClass)))) { logger.log(Type.INFO, "Found NlsBundle interface: " + type); sourceWriter.print("if ("); sourceWriter.print(type.getQualifiedSourceName()); sourceWriter.println(".class == bundleInterface) {"); sourceWriter.indent(); sourceWriter.print("bundle = GWT.create("); sourceWriter.print(type.getQualifiedSourceName()); sourceWriter.println(".class);"); sourceWriter.println("register(bundleInterface, bundle);"); sourceWriter.outdent(); sourceWriter.print("} else "); bundleCount++; } } sourceWriter.println("{"); sourceWriter.indent(); sourceWriter.print("throw new "); sourceWriter.print(IllegalStateException.class.getSimpleName()); sourceWriter.println("(\"Undefined NlsBundle \" + bundleInterface.getName());"); sourceWriter.outdent(); sourceWriter.println("}"); logger.log(Type.INFO, "Found " + bundleCount + " NlsBundle interface(s)."); }
From source file:net.sf.mmm.util.pojo.descriptor.impl.rebind.PojoDescriptorBuilderGenerator.java
License:Apache License
/** * Generates the method {@link AbstractPojoDescriptorBuilderLimited#createDescriptor(Class)}. * //from ww w . java 2 s .c o m * @param sourceWriter is the {@link SourceWriter} where to {@link SourceWriter#print(String) write} the * source code to. * @param logger is the {@link TreeLogger}. * @param simpleName is the {@link Class#getSimpleName() simple name} of the {@link Class} to generate. * @param inputType is the {@link JClassType} reflecting the input-type that triggered the generation via * {@link GWT#create(Class)}. * @param context is the {@link GeneratorContext}. */ private void generateMethodCreateDescriptor(SourceWriter sourceWriter, TreeLogger logger, String simpleName, JClassType inputType, GeneratorContext context) { sourceWriter.print("public <POJO> "); sourceWriter.print(AbstractPojoDescriptorImpl.class.getSimpleName()); sourceWriter.println("<POJO> createDescriptor(Class<POJO> pojoType) {"); sourceWriter.indent(); PojoDescriptorGeneratorConfiguration configuration = getConfiguration(); TypeOracle typeOracle = context.getTypeOracle(); int typeCount = 0; JClassType[] types = typeOracle.getTypes(); for (JClassType type : types) { if (configuration.isPojoTypeSupported(type, typeOracle)) { typeCount++; sourceWriter.print("if (pojoType == "); sourceWriter.print(type.getQualifiedSourceName()); sourceWriter.println(".class) {"); sourceWriter.indent(); sourceWriter.print("return GWT.create("); sourceWriter.print(type.getQualifiedSourceName()); sourceWriter.println(".class);"); sourceWriter.outdent(); sourceWriter.print("} else "); } } if (typeCount > 0) { sourceWriter.println("{"); sourceWriter.indent(); if (typeCount <= 3) { logger.log(Type.WARN, "Found only " + typeCount + " supported type(s)"); } else { logger.log(Type.INFO, "Found " + typeCount + " supported types."); } } else { logger.log(Type.ERROR, "No type found for criteria: " + configuration.getPojoTypeDescription()); } sourceWriter.println("return super.createDescriptor(pojoType);"); if (typeCount > 0) { sourceWriter.outdent(); sourceWriter.println("}"); } generateSourceCloseBlock(sourceWriter); }
From source file:org.chromium.distiller.rebind.JsTestEntryGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typename) throws UnableToCompleteException { String packageName = "org.chromium.distiller"; String outputClassname = "JsTestBuilderImpl"; List<TestCase> testCases = getTestCases(logger, context); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, outputClassname); composer.addImplementedInterface("org.chromium.distiller.JsTestSuiteBuilder"); PrintWriter printWriter = context.tryCreate(logger, packageName, outputClassname); if (printWriter != null) { for (TestCase ts : testCases) { String className = ts.classType.getName(); String qualifiedClassName = ts.classType.getPackage().getName() + "." + className; composer.addImport(qualifiedClassName); }/*from w ww. j ava 2 s.co m*/ SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter); sourceWriter.println("JsTestBuilderImpl () {"); sourceWriter.println("}"); sourceWriter.println("public JsTestSuiteBase build() {"); sourceWriter.indent(); sourceWriter.println("JsTestSuiteBase testSuite = new JsTestSuiteBase();"); for (TestCase ts : testCases) { String className = ts.classType.getName(); String qualifiedClassName = ts.classType.getPackage().getName() + "." + className; sourceWriter.println("testSuite.addTestCase("); sourceWriter.println(" new JsTestSuiteBase.TestCaseFactory() {"); sourceWriter.println(" @Override"); sourceWriter.println(" public JsTestCase build() {"); sourceWriter.println(" return new " + className + "();"); sourceWriter.println(" }"); sourceWriter.println(" }, \"" + qualifiedClassName + "\")"); sourceWriter.indent(); for (JMethod test : ts.tests) { String methodName = test.getName(); sourceWriter.println(".addTest("); sourceWriter.println(" new JsTestSuiteBase.TestCaseRunner() {"); sourceWriter.println(" @Override"); sourceWriter.println(" public void run(JsTestCase testCase) throws Throwable {"); sourceWriter.println(" ((" + className + ")testCase)." + methodName + "();"); sourceWriter.println(" }"); sourceWriter.println(" }, \"" + methodName + "\")"); } sourceWriter.println(";"); sourceWriter.outdent(); } sourceWriter.println("return testSuite;"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.commit(logger); } return composer.getCreatedClassName(); }
From source file:org.cruxframework.crux.core.rebind.crossdevice.DeviceFeaturesPropertyGenerator.java
License:Apache License
static void writeDeviceFeaturesPropertyJavaScript(SourceWriter body) { body.println("var ua = navigator.userAgent.toLowerCase();"); body.println("var supportsTouch = ('ontouchstart' in window);"); body.println("if ((ua.indexOf('googletv') != -1) || (ua.indexOf('ipad;') != -1)){"); body.indent();//from w ww. j a v a 2s. c om body.println("return 'largeDisplay'+(supportsTouch?'Touch':'Arrows');"); body.outdent(); body.println( "} else if ((ua.indexOf('opera mini') != -1) || (ua.indexOf('opera mobi') != -1) || (ua.indexOf('mobile') != -1) || " + "(ua.indexOf('iphone') != -1) || (ua.indexOf('ipod;') != -1)){"); body.indent(); body.println("return 'smallDisplay'+(supportsTouch?'Touch':'Arrows');"); body.outdent(); body.println("} else if (ua.indexOf('android') != -1){"); body.indent(); body.println("return 'largeDisplay'+(supportsTouch?'Touch':'Arrows');"); body.outdent(); body.println("} else {"); body.indent(); body.println("return 'largeDisplay'+(supportsTouch?'Touch':'Mouse');"); body.outdent(); body.println("}"); }
From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java
License:Apache License
/** * /* ww w.j a v a 2s .co m*/ * @param parameter * @param methodDescVar * @param blocksScreen */ private void generateAsyncCallbackForSyncTokenMethod(SourceWriter srcWriter, JParameter parameter, String methodDescVar, boolean blocksScreen) { JParameterizedType parameterizedType = parameter.getType().isParameterized(); String typeSourceName = parameterizedType.getParameterizedQualifiedSourceName(); JClassType[] typeArgs = parameterizedType.getTypeArgs(); String typeParameterSourceName = typeArgs[0].getParameterizedQualifiedSourceName(); srcWriter.println("new " + typeSourceName + "(){"); srcWriter.indent(); srcWriter.println("public void onSuccess(" + typeParameterSourceName + " result){"); srcWriter.indent(); srcWriter.println("try{"); srcWriter.println(parameter.getName() + ".onSuccess(result);"); srcWriter.println("}finally{"); srcWriter.println("__endMethodCall(" + methodDescVar + ", " + blocksScreen + ");"); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("public void onFailure(Throwable caught){"); srcWriter.indent(); srcWriter.println("try{"); srcWriter.println(parameter.getName() + ".onFailure(caught);"); srcWriter.println("}finally{"); srcWriter.println("__endMethodCall(" + methodDescVar + ", " + blocksScreen + ");"); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.print("}"); }
From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java
License:Apache License
/** * @param srcWriter//from ww w . java 2 s .c o m */ private void generateProxyWrapperEndMethod(SourceWriter srcWriter) { srcWriter.println(); srcWriter.println("private void __endMethodCall(String methodDesc, boolean unblocksScreen){"); srcWriter.indent(); srcWriter.println("Boolean isProcessing = __syncProcessingMethods.remove(methodDesc);"); srcWriter.println("if (isProcessing != null && !isProcessing){"); srcWriter.indent(); srcWriter.println("if (unblocksScreen) Screen.unblockToUser();"); srcWriter.println("setServiceEntryPoint(__baseEntrypoint);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); }
From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java
License:Apache License
/** * @param srcWriter/* w w w.ja v a 2s. com*/ * @param asyncMethod * @throws UnableToCompleteException */ private void generateProxyWrapperMethod(SourceWriter srcWriter, JMethod asyncMethod) throws UnableToCompleteException { try { JMethod syncMethod = getSyncMethodFromAsync(asyncMethod); if (syncMethod.getAnnotation(UseSynchronizerToken.class) != null) { JType asyncReturnType = asyncMethod.getReturnType().getErasedType(); List<JParameter> parameters = generateProxyWrapperMethodDeclaration(srcWriter, asyncMethod, asyncReturnType); generateProxyWrapperMethodCall(srcWriter, syncMethod, asyncMethod, asyncReturnType, parameters); srcWriter.outdent(); srcWriter.println("}"); } } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "No method found on service interface that matches the async method [" + asyncMethod.getName() + "]."); } }