本文整理汇总了Java中com.helger.jcodemodel.AbstractJClass类的典型用法代码示例。如果您正苦于以下问题:Java AbstractJClass类的具体用法?Java AbstractJClass怎么用?Java AbstractJClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractJClass类属于com.helger.jcodemodel包,在下文中一共展示了AbstractJClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fullySpecifyClassHeader
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
void fullySpecifyClassHeader() {
for (JTypeVar visitorTypeParameter: configuration.getValueTypeParameters()) {
JTypeVar typeParameter = valueClass.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
for (AbstractJClass iface: configuration.implementsInterfaces()) {
valueClass._implements(iface.typeParams().length == 0 ? iface : iface.narrow(valueClass.typeParams()));
}
AbstractJClass extendsClass = configuration.valueClassExtends();
valueClass._extends(extendsClass.typeParams().length == 0 ? extendsClass : extendsClass.narrow(valueClass.typeParams()));
if (configuration.isValueClassSerializable()) {
valueClass._implements(types._Serializable);
}
if (configuration.isValueClassComparable()) {
valueClass._implements(types._Comparable.narrow(Source.narrowType(configuration.wrapValueClass(valueClass), valueClass.typeParams())));
}
}
示例2: buildFactory
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
JMethod buildFactory(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
JDefinedClass factory = buildFactoryClass(constructorMethods);
JFieldVar factoryField = environment.buildValueClassField(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, factory, "FACTORY");
JAnnotationUse fieldAnnotationUse = factoryField.annotate(SuppressWarnings.class);
JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
paramArray.param("unchecked");
paramArray.param("rawtypes");
factoryField.init(JExpr._new(factory));
JMethod factoryMethod = environment.buildValueClassMethod(Source.toJMod(environment.factoryMethodAccessLevel()) | JMod.STATIC, "factory");
Source.annotateNonnull(factoryMethod);
JAnnotationUse methodAnnotationUse = factoryMethod.annotate(SuppressWarnings.class);
methodAnnotationUse.param("value", "unchecked");
for (JTypeVar visitorTypeParameter: environment.getValueTypeParameters()) {
JTypeVar typeParameter = factoryMethod.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
AbstractJClass usedValueClassType = environment.wrappedValueClassType(factoryMethod.typeParams());
factoryMethod.type(environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException).getVisitorType());
factoryMethod.body()._return(factoryField);
return factoryMethod;
}
示例3: declareAcceptMethod
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
private JMethod declareAcceptMethod(JDefinedClass caseClass, AbstractJClass usedValueClassType) {
JMethod acceptMethod = caseClass.method(JMod.PUBLIC, types._void, environment.acceptMethodName());
acceptMethod.annotate(Override.class);
JTypeVar visitorResultTypeParameter = environment.visitorDefinition().getResultTypeParameter();
AbstractJClass resultType;
if (visitorResultTypeParameter == null)
resultType = types._Object;
else {
JTypeVar resultTypeVar = acceptMethod.generify(visitorResultTypeParameter.name());
resultTypeVar.boundLike(visitorResultTypeParameter);
resultType = resultTypeVar;
}
acceptMethod.type(resultType);
JTypeVar visitorExceptionTypeParameter = environment.visitorDefinition().getExceptionTypeParameter();
JTypeVar exceptionType = null;
if (visitorExceptionTypeParameter != null) {
JTypeVar exceptionTypeParameter = acceptMethod.generify(visitorExceptionTypeParameter.name());
exceptionTypeParameter.boundLike(visitorExceptionTypeParameter);
exceptionType = exceptionTypeParameter;
acceptMethod._throws(exceptionType);
}
VisitorDefinition.VisitorUsage usedVisitorType = environment.visitor(usedValueClassType, resultType, exceptionType);
acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");
return acceptMethod;
}
示例4: buildProtectedConstructor
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
void buildProtectedConstructor(Serialization serialization) {
JMethod constructor = environment.buildValueClassConstructor(JMod.PROTECTED);
JAnnotationUse annotation = constructor.annotate(SuppressWarnings.class);
annotation.paramArray("value", "null");
AbstractJClass unwrappedUsedValueClassType = environment.unwrappedValueClassTypeInsideValueClass();
JVar param = constructor.param(unwrappedUsedValueClassType, "implementation");
Source.annotateNonnull(param);
if (isError) {
constructor.body()._throw(JExpr._new(types._UnsupportedOperationException));
} else {
JConditional nullCheck = constructor.body()._if(JExpr.ref("implementation").eq(JExpr._null()));
JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: 'implementation' argument in class constructor invocation: " + environment.valueClassQualifiedName()));
nullCheck._then()._throw(nullPointerExceptionConstruction);
if (environment.hashCodeCaching().enabled())
constructor.body().assign(JExpr.refthis(hashCodeCachedValueField), param.ref(hashCodeCachedValueField));
constructor.body().assign(JExpr.refthis(acceptorField), param.ref(acceptorField));
}
}
示例5: readGetter
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
GenerationResult<Void> readGetter(MethodUsage interfaceMethod, VariableDeclaration param, AbstractJType paramType, boolean isVarArg) {
GenerationProcess generation = new GenerationProcess();
for (JAnnotationUse annotationUsage: param.annotations()) {
AbstractJClass annotationClass = annotationUsage.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null && annotationClassName.equals(Getter.class.getName())) {
String getterName = annotationUsage.getParam("name", String.class);
if (getterName == null || getterName.equals(":auto"))
getterName = param.name();
MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
boolean isNullable = Source.isNullable(param);
FieldFlags flags = new FieldFlags(isNullable, isVarArg, accessLevel);
FieldConfiguration configuration = new FieldConfiguration(getterName, paramType, flags);
generation.processGenerationResult(read(interfaceMethod, param, configuration));
}
}
}
return generation.<Void>createGenerationResult(null);
}
示例6: readUpdater
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
GenerationResult<Void> readUpdater(MethodUsage interfaceMethod, VariableDeclaration param, AbstractJType paramType, boolean isVarArg) {
GenerationProcess generation = new GenerationProcess();
for (JAnnotationUse annotationUsage: param.annotations()) {
AbstractJClass annotationClass = annotationUsage.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null && annotationClassName.equals(Updater.class.getName())) {
String updaterName = annotationUsage.getParam("name", String.class);
if (updaterName == null || updaterName.equals(":auto"))
updaterName = "with" + Source.capitalize(param.name());
MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
boolean isNullable = Source.isNullable(param);
FieldFlags flags = new FieldFlags(isNullable, isVarArg, accessLevel);
FieldConfiguration configuration = new FieldConfiguration(updaterName, paramType, flags);
generation.processGenerationResult(read(interfaceMethod, param, configuration));
}
}
}
return generation.<Void>createGenerationResult(null);
}
示例7: createInstance
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
public static GenerationResult<ValueClassConfiguration> createInstance(VisitorDefinition visitorDefinition, JAnnotationUse annotation, JDefinedClass valueClass) {
GenerationProcess generation = new GenerationProcess();
String acceptMethodName = annotation.getParam("acceptMethodName", String.class);
MemberAccess acceptMethodAccess = annotation.getParam("acceptMethodAccess", MemberAccess.class);
boolean isPublic = annotation.getParam("isPublic", Boolean.class);
Caching hashCodeCaching = annotation.getParam("hashCodeCaching", Caching.class);
int hashCodeBase = annotation.getParam("hashCodeBase", Integer.class);
boolean isComparable = annotation.getParam("isComparable", Boolean.class);
float floatEpsilon = annotation.getParam("floatEpsilon", Float.class);
double doubleEpsilon = annotation.getParam("doubleEpsilon", Double.class);
FloatCustomization floatCustomization = new FloatCustomization(floatEpsilon, doubleEpsilon);
Serialization serialization = serialization(annotation);
ClassCustomization classCustomization = generation.processGenerationResult(classCustomization(annotation, visitorDefinition, valueClass));
AbstractJClass[] interfaces = annotation.getParam("implementsInterfaces", AbstractJClass[].class);
AcceptMethodCustomization acceptMethodCustomization = new AcceptMethodCustomization(acceptMethodName, acceptMethodAccess);
InterfacesCustomization interfaceCustomization = new InterfacesCustomization(isComparable, serialization, interfaces);
APICustomization apiCustomization = new APICustomization(isPublic, acceptMethodCustomization, interfaceCustomization);
ImplementationCustomization implementationCustomization = new ImplementationCustomization(hashCodeCaching, hashCodeBase, floatCustomization);
Customization customiztion = new Customization(classCustomization, apiCustomization, implementationCustomization);
return generation.createGenerationResult(new ValueClassConfiguration(visitorDefinition, customiztion));
}
示例8: getNullability
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
public static GenerationResult<Boolean> getNullability(AbstractJType type, String name, Collection<? extends JAnnotationUse> annotations) {
boolean hasNonnull = false;
boolean hasNullable = false;
for (JAnnotationUse annotationUse: annotations) {
AbstractJClass annotationClass = annotationUse.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null) {
if (annotationClassName.equals("javax.annotation.Nonnull")) {
hasNonnull = true;
}
if (annotationClassName.equals("javax.annotation.Nullable")) {
hasNullable = true;
}
}
}
}
if (hasNonnull && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is declared as both @Nullable and @Nonnull",
name)));
if (!type.isReference() && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is non-reference, but declared as @Nullable",
name)));
return new GenerationResult<>(hasNullable, Collections.<String>emptyList());
}
示例9: createStage1Model
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
public GenerationResult<Stage1ValueClassModel> createStage1Model(JDefinedClass jVisitorModel, Visitor visitorAnnotation) {
GenerationProcess generation = new GenerationProcess();
if (error != null) {
generation.reportError(error);
return generation.createGenerationResult(null);
} else {
JAnnotationUse annotation = null;
for (JAnnotationUse anyAnnotation: jVisitorModel.annotations()) {
AbstractJClass annotationClass = anyAnnotation.getAnnotationClass();
if (!annotationClass.isError()) {
String fullName = annotationClass.fullName();
if (fullName != null && fullName.equals(GenerateValueClassForVisitor.class.getName()))
annotation = anyAnnotation;
}
}
if (annotation == null)
throw new IllegalStateException("ValueClassModelFactory can't be run for interface without " + GenerateValueClassForVisitor.class + " annotation");
VisitorDefinition visitorModel = generation.processGenerationResult(VisitorDefinition.createInstance(jVisitorModel, visitorAnnotation));
ValueClassConfiguration configuration = generation.processGenerationResult(ValueClassConfiguration.createInstance(visitorModel, annotation, valueClass));
Stage1ValueClassModel result = createStage1Model(configuration);
return generation.createGenerationResult(result);
}
}
示例10: primitiveType
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
private AbstractJClass primitiveType(ProtoTypes type) {
switch ( type ) {
case INT16:
return codeModel.ref( Short.class );
case INT32:
return codeModel.ref( Integer.class );
case INT64:
return codeModel.ref( Long.class );
case DOUBLE:
return codeModel.ref( Double.class );
case FLOAT:
return codeModel.ref( Float.class );
case BYTE:
return codeModel.ref( Byte.class );
case STRING:
return codeModel.ref( String.class );
case BOOLEAN:
return codeModel.ref( Boolean.class );
case BINARY: {
return codeModel.ref( byte[].class );
}
default:
throw new IllegalStateException( type.name() );
}
}
示例11: setOnRequestPermissionsResultDelegateCall
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
public void setOnRequestPermissionsResultDelegateCall(AbstractJClass delegateClass) {
if (onRequestPermissionsResultMethod != null) {
return;
}
setOnRequestPermissionsResultMethod();
onRequestPermissionsResultMethodDelegateBlock.add(delegateClass.staticInvoke("onRequestPermissionsResult")
.arg(JExpr._this())
.arg(onRequestPermissionsResultRequestCodeParam)
.arg(onRequestPermissionsResultGrantResultsParam));
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:13,代码来源:PermissionDispatcherHolder.java
示例12: setOnActivityResultDelegateCall
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
public void setOnActivityResultDelegateCall(AbstractJClass delegateClass) {
if (onActivityResultMethod != null) {
return;
}
setOnActivityResultMethod();
onActivityResultMethodDelegateBlock.add(delegateClass.staticInvoke("onActivityResult")
.arg(JExpr._this())
.arg(onActivityResultRequestCodeParam));
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:12,代码来源:PermissionDispatcherHolder.java
示例13: process
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
TypeElement annotatedElement = holder.getAnnotatedElement();
String delegateClassName = annotatedElement.getQualifiedName().toString() + "PermissionsDispatcher";
AbstractJClass delegateClass = getJClass(delegateClassName);
PermissionDispatcherHolder permissionDispatcherHolder = holder.getPluginHolder(new PermissionDispatcherHolder(holder));
setDispatcherCallbacks(element, delegateClass, permissionDispatcherHolder);
JFieldVar dispatcherCalledField = permissionDispatcherHolder.getPermissionDispatcherCalledField();
setPermissionMethods(element, holder, delegateClass, dispatcherCalledField);
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:12,代码来源:NeedsPermissionHandler.java
示例14: setPermissionMethods
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
private void setPermissionMethods(Element element, EComponentHolder holder, AbstractJClass delegateClass, JFieldVar dispatcherCalledField) {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod overrideMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(overrideMethod);
JBlock overrideMethodBody = overrideMethod.body();
JConditional conditional = overrideMethodBody._if(dispatcherCalledField.not());
JBlock thenBlock = conditional._then();
thenBlock.assign(dispatcherCalledField, JExpr.TRUE);
String delegateMethodName = element.getSimpleName().toString() + "WithPermissionCheck";
JInvocation delegateCall = delegateClass.staticInvoke(delegateMethodName)
.arg(JExpr._this());
overrideMethod.params().forEach(delegateCall::arg);
if (overrideMethod.hasVarArgs()) {
JVar jVar = overrideMethod.varParam();
if (jVar != null) {
delegateCall.arg(jVar);
}
}
if (!removeRuntimePermissionsAnnotation(holder.getGeneratedClass())) {
codeModelHelper.copyAnnotation(overrideMethod, findAnnotation(element));
}
thenBlock.add(delegateCall);
JBlock elseBlock = conditional._else();
elseBlock.assign(dispatcherCalledField, JExpr.FALSE);
elseBlock.add(previousMethodBody);
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:36,代码来源:NeedsPermissionHandler.java
示例15: setDispatcherCallbacks
import com.helger.jcodemodel.AbstractJClass; //导入依赖的package包/类
private void setDispatcherCallbacks(Element element, AbstractJClass delegateClass, PermissionDispatcherHolder permissionDispatcherHolder) {
if (hasSpecialPermissions(element)) {
permissionDispatcherHolder.setOnActivityResultDelegateCall(delegateClass);
}
if (hasNormalPermissions(element)) {
permissionDispatcherHolder.setOnRequestPermissionsResultDelegateCall(delegateClass);
}
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:9,代码来源:NeedsPermissionHandler.java