当前位置: 首页>>代码示例>>Java>>正文


Java SourceWriter.indentln方法代码示例

本文整理汇总了Java中com.google.gwt.user.rebind.SourceWriter.indentln方法的典型用法代码示例。如果您正苦于以下问题:Java SourceWriter.indentln方法的具体用法?Java SourceWriter.indentln怎么用?Java SourceWriter.indentln使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gwt.user.rebind.SourceWriter的用法示例。


在下文中一共展示了SourceWriter.indentln方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateClass

import com.google.gwt.user.rebind.SourceWriter; //导入方法依赖的package包/类
private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className,
        List<JClassType> componentExtensionClasses) {
    PrintWriter pw = context.tryCreate(logger, packageName, className);
    if (pw == null) {
        return;
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

    // imports
    composerFactory.addImport(HashMap.class.getCanonicalName());
    composerFactory.addImport(Map.class.getCanonicalName());
    composerFactory.addImport(ComponentProvider.class.getCanonicalName());
    composerFactory.addImport(ComponentExtensionManager.class.getCanonicalName());
    composerFactory.addImport(ComponentProviderProxyImpl.class.getCanonicalName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    composerFactory.addImport(Inject.class.getCanonicalName());

    // interface
    composerFactory.addImplementedInterface(ComponentExtensionManager.class.getCanonicalName());

    SourceWriter sw = composerFactory.createSourceWriter(context, pw);

    // fields
    sw.println("private Map<String, ComponentProviderProxy> _providers = new HashMap<String, ComponentProviderProxy>();");
    sw.println("private Map<String, String> _typeToName = new HashMap<String, String>();");

    // constructor
    sw.println("public " + className + "() {");
    sw.indent();
    for (JClassType extensionClass : componentExtensionClasses) {
        ComponentExtension extensionAnnotation = extensionClass.getAnnotation(ComponentExtension.class);
        sw.println("_providers.put(\"" + extensionAnnotation.componentName()
                + "\", new ComponentProviderProxyImpl(\"" + extensionAnnotation.displayName() + "\") {");
        sw.indent();
        sw.println("public ComponentProvider instantiate() {");
        sw.indentln("return GWT.create(" + extensionClass.getQualifiedSourceName() + ".class);");
        sw.println("}");
        sw.outdent();
        sw.println("});");
        for (String type : extensionAnnotation.activationTypes()) {
            sw.println("_typeToName.put(\"" + type + "\", \"" + extensionAnnotation.componentName() + "\");");
        }
    }
    sw.outdent();
    sw.println("}");

    // methods
    // getExtensionProviders
    sw.println("public Map<String, ComponentProviderProxy> getExtensionProviders() {");
    sw.indentln("return _providers;");
    sw.println("}");

    // getExtensionProviderByComponentName
    sw.println("public ComponentProviderProxy getExtensionProviderByComponentName(String componentName) {");
    sw.indent();
    sw.println("if (_providers.containsKey(componentName)) {");
    sw.indentln("return _providers.get(componentName);");
    sw.println("}");
    sw.println("return null;");
    sw.outdent();
    sw.println("}");

    // getExtensionProviderByTypeName
    sw.println("public ComponentProviderProxy getExtensionProviderByTypeName(String typeName) {");
    sw.indent();
    sw.println("if (_typeToName.containsKey(typeName)) {");
    sw.indentln("return getExtensionProviderByComponentName(_typeToName.get(typeName));");
    sw.println("}");
    sw.println("return null;");
    sw.outdent();
    sw.println("}");

    // close it out
    sw.outdent();
    sw.println("}");

    context.commit(logger, pw);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:80,代码来源:ComponentExtensionManagerGenerator.java

示例2: generate

import com.google.gwt.user.rebind.SourceWriter; //导入方法依赖的package包/类
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
	oracle = context.getTypeOracle();
	beanModelMarkerType = oracle.findType(BeanMarker.class.getName());
	beanModelTagType = oracle.findType(BeanTag.class.getName());

	try {
		// final all beans and bean markers
		beans = new ArrayList<JClassType>();
		JClassType[] types = oracle.getTypes();
		for (JClassType type : types) {
			if (isBeanMarker(type)) {
				beans.add(getMarkerBean(type));
			} else if (isBean(type)) {
				beans.add(type);
			}
		}

		final String genPackageName = BeanLookup.class.getPackage().getName();
		final String genClassName = "BeanLookupImpl";

		ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(genPackageName, genClassName);
		composer.setSuperclass(BeanLookup.class.getCanonicalName());
		composer.addImport(BeanFactory.class.getName());
		composer.addImport(Map.class.getName());
		composer.addImport(FastMap.class.getName());

		PrintWriter pw = context.tryCreate(logger, genPackageName, genClassName);

		if (pw != null) {
			SourceWriter sw = composer.createSourceWriter(context, pw);

			sw.println("private Map<String, BeanFactory> m;");

			sw.println("public BeanFactory getFactory(Class b) {");
			sw.indent();
			sw.println("String n = b.getName();");
			sw.println("if (m == null) {");
			sw.indentln("m = new FastMap<BeanFactory>();");
			sw.println("}");
			sw.println("if (m.get(n) == null) {");
			sw.indent();
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < beans.size(); i++) {
				JClassType bean = beans.get(i);
				String name = createBean(bean, logger, context);
				String factory = createFactory(bean, name, logger, context);

				if (i > 0) {
					sw.print(" else ");
				}
				sw.println("if (" + bean.getQualifiedSourceName() + ".class.getName().equals(n)) {");
				sw.indentln("m" + i + "();");

				sb.append("private void m" + i + "() {\n");
				sb.append("  m.put(" + bean.getQualifiedSourceName() + ".class.getName(), new " + factory + "());\n");
				sb.append("}\n");

				sw.print("}");
			}
			sw.outdent();
			sw.println("}");
			sw.println("return m.get(n);");
			sw.outdent();
			sw.println("}");

			sw.println(sb.toString());
			sw.commit(logger);
		}

		return composer.getCreatedClassName();

	} catch (Exception e) {
		logger.log(TreeLogger.ERROR, "Class " + typeName + " not found.", e);
		throw new UnableToCompleteException();
	}

}
 
开发者ID:ahome-it,项目名称:ahome-core,代码行数:79,代码来源:BeanModelGenerator.java

示例3: createGetMethods

import com.google.gwt.user.rebind.SourceWriter; //导入方法依赖的package包/类
protected void createGetMethods(List<JMethod> getters, SourceWriter sw, String typeName) {
	sw.println("public <X> X getPropertyAsString(String s) {");

	sw.println("if (allowNestedValues && NestedModelUtil.isNestedProperty(s)) {");
	sw.indentln("return (X)NestedModelUtil.getNestedValue(this, s);");
	sw.println("}");

	for (JMethod method : getters) {
		JClassType returnType = method.getReturnType().isClassOrInterface();
		String s = method.getName();
		String p = lowerFirst(s.substring(s.startsWith("g") ? 3 : 2)); // get
																		// or

		sw.println("if (s.equals(\"" + p + "\")) {");
		sw.println("Object value = ((" + typeName + ")bean)." + s + "();");

		try {
			if (returnType != null && returnType.isAssignableTo(oracle.getType(List.class.getName())) && returnType.isParameterized() != null) {
				JParameterizedType type = returnType.isParameterized();
				JClassType[] params = type.getTypeArgs();
				if (beans.contains(params[0])) {
					sw.println("if (value != null) {");
					sw.indent();
					sw.println("java.util.List list = (java.util.List)value;");
					sw.println("java.util.List list2 = " + BeanLookup.class.getCanonicalName() + ".get().getFactory(" + params[0].getQualifiedSourceName()
							+ ".class).createModel((java.util.Collection) list);");
					sw.outdent();
					sw.println("return (X) list2;");
					sw.println("}");
				}
			} else {
				// swap returnType as generic types were not matching
				// (beans.contains(returnType))
				if (returnType != null) {
					String t = returnType.getQualifiedSourceName();
					if (t.indexOf("extends") == -1) {
						returnType = oracle.getType(t);
					}
				}
				if (beans.contains(returnType)) {
					sw.println("if (value != null) {");
					sw.println("    Bean nestedModel = nestedModels.get(s);");
					sw.println("    if (nestedModel != null) {");
					sw.println("      Object bean = nestedModel.getBean();");
					sw.println("      if (!bean.equals(value)){");
					sw.println("        nestedModel = null;");
					sw.println("      }");
					sw.println("    }");
					sw.println("    if (nestedModel == null) {");
					sw.println("        nestedModel = " + BeanLookup.class.getCanonicalName() + ".get().getFactory(" + returnType.getQualifiedSourceName()
							+ ".class).createModel(value);");
					sw.println("        nestedModels.put(s, nestedModel);");
					sw.println("    }");
					sw.println("    return (X)processValue(nestedModel);");
					sw.println("}");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		sw.println("return (X)processValue(value);");
		sw.println("}");
	}
	sw.println("return super.getFromCache(s);");
	sw.println("}");
}
 
开发者ID:ahome-it,项目名称:ahome-core,代码行数:68,代码来源:BeanModelGenerator.java


注:本文中的com.google.gwt.user.rebind.SourceWriter.indentln方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。