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


Java JClassAlreadyExistsException类代码示例

本文整理汇总了Java中com.sun.codemodel.JClassAlreadyExistsException的典型用法代码示例。如果您正苦于以下问题:Java JClassAlreadyExistsException类的具体用法?Java JClassAlreadyExistsException怎么用?Java JClassAlreadyExistsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: buildTemplateConstraint

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
private JDefinedClass buildTemplateConstraint(String name) {
    try {
        JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
        tplConstraint.annotate(Documented.class);
        tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
        tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
        
        // Using direct as I don't know how to build default { } with code model
        tplConstraint.direct("\n" + "    Class<?>[] groups() default {};\n" + "    String message() default \"Invalid value\";\n" + "    Class<? extends Payload>[] payload() default {};\n");
        
        // Hack to force the import of javax.validation.Payload
        tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
        
        return tplConstraint;
    } catch (JClassAlreadyExistsException e) {
        throw new RuntimeException("Tried to create an already existing class: " + name, e);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:19,代码来源:Jsr303Annotator.java

示例2: ClassGenerator

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
ClassGenerator(CodeGenerator<T> codeGenerator, MappingSet mappingSet, SignatureHolder signature, EvaluationVisitor eval, JDefinedClass clazz, JCodeModel model) throws JClassAlreadyExistsException {
  this.codeGenerator = codeGenerator;
  this.clazz = clazz;
  this.mappings = mappingSet;
  this.sig = signature;
  this.evaluationVisitor = eval;
  this.model = model;
  blocks = (LinkedList<JBlock>[]) new LinkedList[sig.size()];
  for (int i =0; i < sig.size(); i++) {
    blocks[i] = Lists.newLinkedList();
  }
  rotateBlock();

  for (SignatureHolder child : signature.getChildHolders()) {
    String innerClassName = child.getSignatureClass().getSimpleName();
    JDefinedClass innerClazz = clazz._class(Modifier.FINAL + Modifier.PRIVATE, innerClassName);
    innerClasses.put(innerClassName, new ClassGenerator<>(codeGenerator, mappingSet, child, eval, innerClazz, model));
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:ClassGenerator.java

示例3: CodeGenerator

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
CodeGenerator(MappingSet mappingSet, TemplateClassDefinition<T> definition,
    FunctionImplementationRegistry funcRegistry) {
  Preconditions.checkNotNull(definition.getSignature(),
      "The signature for defintion %s was incorrectly initialized.", definition);
  this.definition = definition;
  this.className = definition.getExternalInterface().getSimpleName() + "Gen" + definition.getNextClassNumber();
  this.fqcn = PACKAGE_NAME + "." + className;
  try {
    this.model = new JCodeModel();
    JDefinedClass clazz = model._package(PACKAGE_NAME)._class(className);
    rootGenerator = new ClassGenerator<>(this, mappingSet, definition.getSignature(), new EvaluationVisitor(
        funcRegistry), clazz, model);
  } catch (JClassAlreadyExistsException e) {
    throw new IllegalStateException(e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:CodeGenerator.java

示例4: CodeGenerator

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
CodeGenerator(CodeCompiler compiler, MappingSet mappingSet, TemplateClassDefinition<T> definition) {
  Preconditions.checkNotNull(definition.getSignature(),
      "The signature for defintion %s was incorrectly initialized.", definition);
  this.definition = definition;
  this.compiler = compiler;
  this.className = definition.getExternalInterface().getSimpleName() + "Gen" + definition.getNextClassNumber();
  this.fqcn = PACKAGE_NAME + "." + className;
  try {
    this.model = new JCodeModel();
    JDefinedClass clazz = model._package(PACKAGE_NAME)._class(className);
    clazz = clazz._extends(model.directClass(definition.getTemplateClassName()));
    clazz.constructor(JMod.PUBLIC).body().invoke(SignatureHolder.INIT_METHOD);
    rootGenerator = new ClassGenerator<>(this, mappingSet, definition.getSignature(), new EvaluationVisitor(), clazz, model);
  } catch (JClassAlreadyExistsException e) {
    throw new IllegalStateException(e);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:CodeGenerator.java

示例5: defineClass

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
public JDefinedClass defineClass(AbstractType t, ClassType type) {
	String fullyQualifiedName = nameGenerator.fullyQualifiedName(t);
	try {
		JDefinedClass _class = mdl._class(fullyQualifiedName, type);
		if (config.addGenerated) {
			_class.annotate(Generated.class).param("value", JavaWriter.class.getPackage().getName()).param("date",
					new Date().toString());
		}
		if (t.hasDirectMeta(Description.class)) {
			String description = t.oneMeta(Description.class).value();
			_class.javadoc().add(description);
		}
		return _class;
	} catch (JClassAlreadyExistsException e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:18,代码来源:JavaWriter.java

示例6: visitResourceStart

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
@Override
public void visitResourceStart(Resource resource) {
    try {
        if (outerResource == null) {
            outerResource = resource;

            createResourceInterface(resource);
            addMediaTypes();
        }
        else if (innerResource == null) {
            innerResource = resource;
        }
        else {
            throw new GeneratorException("cannot handle resources nested more than two levels");
        }
    }
    catch (JClassAlreadyExistsException exc) {
        throw Exceptions.unchecked(exc);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:21,代码来源:ResourceGeneratingApiVisitor.java

示例7: createNestedClass

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
/**
 * Creates {@link #innerClassGenerator} with inner class
 * if {@link #hasMaxIndexValue()} returns {@code true}.
 *
 * @return true if splitting happened.
 */
private boolean createNestedClass() {
  if (hasMaxIndexValue()) {
    // all new fields will be declared in the class from innerClassGenerator
    if (innerClassGenerator == null) {
      try {
        JDefinedClass innerClazz = clazz._class(JMod.PRIVATE, clazz.name() + "0");
        innerClassGenerator = new ClassGenerator<>(codeGenerator, mappings, sig, evaluationVisitor, innerClazz, model, optionManager);
      } catch (JClassAlreadyExistsException e) {
        throw new DrillRuntimeException(e);
      }
      oldBlocks = blocks;
      innerClassGenerator.index = index;
      innerClassGenerator.maxIndex += index;
      // blocks from the inner class should be used
      setupInnerClassBlocks();
      return true;
    }
    return innerClassGenerator.createNestedClass();
  }
  return false;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:28,代码来源:ClassGenerator.java

示例8: CodeGenerator

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
CodeGenerator(MappingSet mappingSet, TemplateClassDefinition<T> definition, OptionSet optionManager) {
  Preconditions.checkNotNull(definition.getSignature(),
      "The signature for defintion %s was incorrectly initialized.", definition);
  this.definition = definition;
  this.className = definition.getExternalInterface().getSimpleName() + "Gen" + definition.getNextClassNumber();
  this.fqcn = PACKAGE_NAME + "." + className;
  try {
    this.model = new JCodeModel();
    JDefinedClass clazz = model._package(PACKAGE_NAME)._class(className);
    rootGenerator = new ClassGenerator<>(this, mappingSet,
      definition.getSignature(), new EvaluationVisitor(),
      clazz, model, optionManager);
  } catch (JClassAlreadyExistsException e) {
    throw new IllegalStateException(e);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:17,代码来源:CodeGenerator.java

示例9: getNamespaceClass

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
public JDefinedClass getNamespaceClass(String namespace, ParsingContext context) {
	if (namespace == null) {
		return null;
	}
	
	JDefinedClass ret = namespaceClasses.get(namespace);
	if (ret == null) {
		try {
			ret = context.getCm()._class("generated." + namespace);
			ret.init().add(context.getCm().ref(BridJ.class).staticInvoke("register"));
			Map<String, String> nsToLib =
					(Map<String, String>) context.getExtra(Constants.CONTEXT_EXTRA_NAMESPACE_TO_LIB);
			String libName = nsToLib.get(namespace);
			if (libName != null) {
				ret.annotate(Library.class).param("value", libName);
			}
			namespaceClasses.put(namespace, ret);
		} catch (JClassAlreadyExistsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	return ret;
}
 
开发者ID:gstreamer-java,项目名称:gir2java,代码行数:25,代码来源:TypeRegistry.java

示例10: applySpringMethodBodyRule_shouldCreate_valid_body

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
@Test
public void applySpringMethodBodyRule_shouldCreate_valid_body() throws JClassAlreadyExistsException {
    SpringRestClientMethodBodyRule rule = new SpringRestClientMethodBodyRule("restTemplate", "baseUrl");
    
    JPackage jPackage = jCodeModel.rootPackage();
    JDefinedClass jClass = jPackage._class(JMod.PUBLIC, "MyClass");
    JMethod jMethod = jClass.method(JMod.PUBLIC, Object.class, "getBase");                
    jMethod.param(jCodeModel._ref(String.class), "id");
    rule.apply(getEndpointMetadata(2), CodeModelHelper.ext(jMethod, jCodeModel));

    String serializeModel = serializeModel();        
    //ensure that we are adding the ACCEPT headers
    assertThat(serializeModel, containsString("httpHeaders.setAccept(acceptsList);"));
    //ensure that we are concatinating the base URL with the request URI to form the full url 
    assertThat(serializeModel, containsString("String url = baseUrl.concat(\"/base/{id}\""));
    //ensure that we are setting url paths vars in the uri
    assertThat(serializeModel, containsString("uriComponents = uriComponents.expand(uriParamMap)"));
    //ensure that the exchange invocation is as expected 
    assertThat(serializeModel, containsString("return this.restTemplate.exchange(uriComponents.encode().toUri(), HttpMethod.GET, httpEntity, NamedResponseType.class);"));
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:21,代码来源:SpringRulesTest.java

示例11: declare

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
JDefinedClass declare(int mods, TIdentifier identifier, ClassType ctype, Optional<String> name) {
    if (current instanceof Scope.Typey) {
        try {
            Scope.Typey typeyScope = (Scope.Typey) current;
            Type t = typeyScope.declare(mods, identifier, ctype, name);
            global.addType(t);
            current = t.scope;
            scopeStack.push(current);
            //System.out.println("Pushing scope " + current);
            return t.definition;
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException(ex);
        }
    } else {
        Logger.error("Cannot add a type (" + identifier.getText() + ") to a Scope (" + current.getClass().getName() + ") that doesn't allow types!");
        throw new RuntimeException("Invalid Scope for operation!");
    }
}
 
开发者ID:kompics,项目名称:kola,代码行数:19,代码来源:ResolutionContext.java

示例12: createRetrieveClass

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
private static void createRetrieveClass(Retrieve retrieve, String packageName, File destinationDir) throws JClassAlreadyExistsException, IOException {
	JCodeModel codeModel = new JCodeModel();

	JClass mapClass = codeModel.ref(String.format("%s.%sMap", packageName, retrieve.getId()));

	JDefinedClass retrieveClass = codeModel._class(String.format("%s.%sRetrieve", packageName, retrieve.getId()));
	retrieveClass.javadoc().append("Auto generated class. Do not modify!");
	retrieveClass._extends(codeModel.ref(AbstractRetrieve.class).narrow(mapClass));

	// Constructor
	JMethod constructor = retrieveClass.constructor(JMod.PUBLIC);
	constructor.param(String.class, "id");
	constructor.body().invoke("super").arg(JExpr.ref("id"));

	// Implemented method
	JMethod getMapMethod = retrieveClass.method(JMod.PUBLIC, mapClass, "getMap");
	getMapMethod.annotate(Override.class);
	getMapMethod.param(codeModel.ref(Map.class).narrow(String.class, Object.class), "data");
	getMapMethod.body()._return(JExpr._new(mapClass).arg(JExpr.ref("data")));

	codeModel.build(destinationDir);
}
 
开发者ID:vincenzomazzeo,项目名称:map-engine,代码行数:23,代码来源:MapperEngineCodeGenerator.java

示例13: createServicesInterface

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
private JDefinedClass createServicesInterface(Service service,
		JDefinedClass jServiceClass) throws JClassAlreadyExistsException {
	// JDefinedClass _interface =
	// jServiceClass._interface(jServiceClass.name() + SUFIX_SERVICE_IFACE);
	JDefinedClass _interface = jServiceClass._interface(JMod.PUBLIC,
			SUFIX_SERVICE_IFACE);

	if (service.getParent() != null && service.getParent().isPresent()) {
		JClass jClassParent = (JClass) resolvName(service.getParent().get());
		_interface._extends((JClass) resolvName(jClassParent.fullName()
				+ "." + SUFIX_SERVICE_IFACE));
	}

	for (ThriftMethod function : service.getMethods()) {
		createServicesMethod(function, _interface);
	}

	return _interface;
}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:20,代码来源:ServiceCodeGenerator.java

示例14: createServicesAsyncInterface

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
private JDefinedClass createServicesAsyncInterface(Service service,
		JDefinedClass jServiceClass) throws JClassAlreadyExistsException {
	// JDefinedClass _interface = jServiceClass._interface(JMod.PUBLIC,
	// jServiceClass.name() + SUFIX_SERVICE_ASYNC_IFACE);
	JDefinedClass _interface = jServiceClass._interface(JMod.PUBLIC,
			SUFIX_SERVICE_ASYNC_IFACE);

	if (service.getParent().isPresent()) {
		JClass jClassParent = (JClass) resolvName(service.getParent().get());
		_interface._extends((JClass) resolvName(jClassParent.fullName()
				+ "." + SUFIX_SERVICE_ASYNC_IFACE));
	}

	createServicesAsyncInterfaceMethod(service, _interface);

	return _interface;
}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:18,代码来源:ServiceCodeGenerator.java

示例15: defineClass

import com.sun.codemodel.JClassAlreadyExistsException; //导入依赖的package包/类
private JDefinedClass defineClass(String pckg, JCodeModel model, Framework f)
		throws JClassAlreadyExistsException{
	String name = pckg == null ? NAME : pckg + "." + NAME;
	JDefinedClass c = CodeGenerator.appendJDocHeader(
			model._class(JMod.PUBLIC, name, ClassType.ENUM));
	
	JVar str = c.field(JMod.PRIVATE+JMod.FINAL, String.class, "name");
	JMethod cons = c.constructor(JMod.PRIVATE);
	cons.body().assign(JExpr._this().ref(str), cons.param(String.class, "name"));
	JMethod defCons = c.constructor(JMod.PRIVATE);
	defCons.body().assign(JExpr._this().ref(str), JExpr._null());
	
	JMethod toString = c.method(JMod.PUBLIC, String.class, "toString");
	toString.annotate(Override.class);
	toString.body()._if(str.eq(JExpr._null()))._then()._return(JExpr.invoke(JExpr._super(), "toString"));
	toString.body()._return(str);
	
	c._implements(f.getSymbolInterface());
	JMethod type = c.method(JMod.PUBLIC, int.class, "type");
	type.annotate(Override.class);
	type.body()._return(JExpr.invoke(JExpr._this(), "ordinal"));
	
	return c;
}
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:25,代码来源:SymbolsGenerator.java


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