List of usage examples for com.google.gwt.user.rebind SourceWriter indent
void indent();
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 w ww . jav a 2s . c om * @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. * /* 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}. */ 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)}. * //from w w w . j a va 2s . 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 w ww . j a v a 2s. 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 av a2 s . com*/ 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(); body.println("return 'largeDisplay'+(supportsTouch?'Touch':'Arrows');"); body.outdent();// www .j a va 2s .co m 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
/** * //from w w w. j a va 2s . c om * @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// ww w. j a v a 2 s . c om */ 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/*from ww w. j a v a 2 s .c om*/ * @param asyncMethod * @param asyncReturnType * @param parameters * @throws UnableToCompleteException */ private void generateProxyWrapperMethodCall(SourceWriter srcWriter, JMethod syncMethod, JMethod asyncMethod, JType asyncReturnType, List<JParameter> parameters) throws UnableToCompleteException { if (asyncReturnType != JPrimitiveType.VOID) { logger.log(TreeLogger.ERROR, "UseSynchronizer Token only can be used with void return type on Async interface."); throw new UnableToCompleteException(); } UseSynchronizerToken synchronizerTokenAnnot = syncMethod.getAnnotation(UseSynchronizerToken.class); boolean blocksScreen = synchronizerTokenAnnot.blocksUserInteraction(); JParameter parameter = parameters.get(parameters.size() - 1); srcWriter.println("final String methodDesc = \"" + JClassUtils.getMethodDescription(syncMethod) + "\";"); srcWriter.println("if (__startMethodCall(methodDesc, " + blocksScreen + ")){"); srcWriter.indent(); srcWriter.println("__syncTokenService.getSynchronizerToken(methodDesc,"); srcWriter.println("new AsyncCallback<String>(){"); srcWriter.indent(); srcWriter.println("public void onSuccess(String result){"); srcWriter.indent(); srcWriter.println("__updateMethodToken(methodDesc, result);"); generateProxyMethodCall(srcWriter, asyncMethod, parameters, "methodDesc", blocksScreen); 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(methodDesc, " + blocksScreen + ");"); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("});"); srcWriter.outdent(); srcWriter.println("}"); if (synchronizerTokenAnnot.notifyCallsWhenProcessing()) { srcWriter.println("else{"); srcWriter.indent(); String sensitiveErrMsg = Crux.class.getName() + ".getMessages().methodIsAlreadyBeingProcessed()"; srcWriter.println(Crux.class.getName() + ".getErrorHandler().handleError(" + sensitiveErrMsg + ", new " + SensitiveMethodAlreadyBeingProcessedException.class.getName() + "(" + sensitiveErrMsg + ")" + ");"); srcWriter.outdent(); srcWriter.println("}"); } }
From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java
License:Apache License
/** * @param srcWriter/*from ww w . j ava 2 s .c o m*/ * @param asyncMethod * @param asyncReturnType * @return */ private List<JParameter> generateProxyWrapperMethodDeclaration(SourceWriter srcWriter, JMethod asyncMethod, JType asyncReturnType) { srcWriter.println(); srcWriter.print("public "); srcWriter.print(asyncReturnType.getQualifiedSourceName()); srcWriter.print(" "); srcWriter.print(asyncMethod.getName() + "("); boolean needsComma = false; List<JParameter> parameters = new ArrayList<JParameter>(); JParameter[] asyncParams = asyncMethod.getParameters(); for (int i = 0; i < asyncParams.length; ++i) { JParameter param = asyncParams[i]; if (needsComma) { srcWriter.print(", "); } else { needsComma = true; } JType paramType = param.getType(); if (i == (asyncParams.length - 1)) { srcWriter.print("final "); } srcWriter.print(paramType.getQualifiedSourceName()); srcWriter.print(" "); String paramName = param.getName(); parameters.add(param); srcWriter.print(paramName); } srcWriter.println(") {"); srcWriter.indent(); return parameters; }