本文整理汇总了Java中com.helger.jcodemodel.JExpr类的典型用法代码示例。如果您正苦于以下问题:Java JExpr类的具体用法?Java JExpr怎么用?Java JExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JExpr类属于com.helger.jcodemodel包,在下文中一共展示了JExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setOnRequestPermissionsResultMethod
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
private void setOnRequestPermissionsResultMethod() {
onRequestPermissionsResultMethod = holder().getGeneratedClass().method(JMod.PUBLIC, getCodeModel().VOID, "onRequestPermissionsResult");
onRequestPermissionsResultMethod.annotate(Override.class);
onRequestPermissionsResultRequestCodeParam = onRequestPermissionsResultMethod.param(getCodeModel().INT, "requestCode");
JVar permissionsParam = onRequestPermissionsResultMethod.param(getJClass("java.lang.String").array(), "permissions");
onRequestPermissionsResultGrantResultsParam = onRequestPermissionsResultMethod.param(getCodeModel().INT.array(), "grantResults");
JBlock onRequestPermissionsResultMethodBody = onRequestPermissionsResultMethod.body();
onRequestPermissionsResultMethodBody.invoke(JExpr._super(), "onRequestPermissionsResult")
.arg(onRequestPermissionsResultRequestCodeParam)
.arg(permissionsParam)
.arg(onRequestPermissionsResultGrantResultsParam);
onRequestPermissionsResultMethodDelegateBlock = onRequestPermissionsResultMethodBody.blockVirtual();
onRequestPermissionsResultMethodBody.assign(getPermissionDispatcherCalledField(), JExpr.FALSE);
}
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:20,代码来源:PermissionDispatcherHolder.java
示例2: buildFactory
import com.helger.jcodemodel.JExpr; //导入依赖的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: buildHashCodeCachedValueField
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
private JFieldVar buildHashCodeCachedValueField(Serialization serialization) {
if (!environment.hashCodeCaching().enabled())
throw new IllegalStateException("Unsupported method evaluation to cache hash code: " + environment.hashCodeCaching());
else {
boolean isSerializable = serialization.isSerializable();
boolean precomputes = environment.hashCodeCaching() == Caching.PRECOMPUTE;
int mods = JMod.PRIVATE;
mods = !isSerializable ? mods : mods | JMod.TRANSIENT;
if (!precomputes)
return environment.buildValueClassField(mods, types._int, "hashCodeCachedValue", JExpr.lit(0));
else {
mods = isSerializable ? mods : mods | JMod.FINAL;
return environment.buildValueClassField(mods, types._int, "hashCodeCachedValue");
}
}
}
示例4: buildProtectedConstructor
import com.helger.jcodemodel.JExpr; //导入依赖的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: generatePredicate
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
void generatePredicate(String name, PredicateConfigutation predicate) {
JMethod predicateMethod = environment.buildValueClassMethod(Source.toJMod(predicate.accessLevel()) | JMod.FINAL, name);
predicateMethod.type(types._boolean);
if (isError) {
predicateMethod.body()._throw(JExpr._new(types._UnsupportedOperationException));
} else {
JMethod implementation = environment.buildAcceptingInterfaceMethod(JMod.PUBLIC, name);
implementation.type(types._boolean);
predicateMethod.body()._return(JExpr.refthis(acceptorField).invoke(implementation));
for (JMethod interfaceMethod1: environment.visitorDefinition().methodDefinitions()) {
JDefinedClass caseClass = caseClasses.get(interfaceMethod1.name());
predicateMethod = caseClass.method(JMod.PUBLIC | JMod.FINAL, types._boolean, name);
predicateMethod.annotate(Override.class);
boolean result = predicate.isTrueFor(interfaceMethod1);
predicateMethod.body()._return(JExpr.lit(result));
}
}
}
示例6: appendNonnullPrimitive
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
private void appendNonnullPrimitive(AbstractJType type, IJExpression value1, IJExpression value2, boolean isLast) {
IJExpression equalsCondition;
IJExpression notEqualsCondition;
if (!type.name().equals("float") && !type.name().equals("doable")) {
equalsCondition = value1.eq(value2);
notEqualsCondition = value1.ne(value2);
} else {
IJExpression epsilon = type.name().equals("float") ? JExpr.lit(floatCustomization.floatEpsilon()) : JExpr.lit(floatCustomization.doubleEpsilon());
JInvocation invocation = types._Math.staticInvoke("abs");
invocation.arg(value1.minus(value2));
equalsCondition = invocation.lte(epsilon);
notEqualsCondition = invocation.gt(epsilon);
}
if (isLast) {
body._return(equalsCondition);
} else {
JConditional _if = body._if(notEqualsCondition);
_if._then()._return(JExpr.FALSE);
}
}
示例7: appendNonnullArray
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
private void appendNonnullArray(IJExpression value1, IJExpression value2, AbstractJType type) {
JInvocation invocation = types._Math.staticInvoke("min");
invocation.arg(value1.ref("length"));
invocation.arg(value2.ref("length"));
JVar length = body.decl(types._int, nameSource.get("length"), invocation);
VariableNameSource localNames = nameSource.forBlock();
JForLoop _for = body._for();
JVar i = _for.init(types._int, localNames.get("i"), JExpr.lit(0));
_for.test(i.lt(length));
_for.update(i.incr());
Body forBody = new Body(resultVariable, _for.body(), localNames);
if (type.elementType().isReference())
forBody.appendNullableValue(type.elementType(), value1.component(i), value2.component(i));
else
forBody.appendNotNullValue(type.elementType(), value1.component(i), value2.component(i));
appendNotNullValue(types._int, value1.ref("length"), value2.ref("length"));
}
示例8: visitEnum_def
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
@Override
public Void visitEnum_def(Enum_defContext ctx) {
try {
String name = ctx.enum_name().IDENTIFIER().getText();
ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JPackage jPackage = codeModel._package( pkg );
JDefinedClass m = codeModel._package( pkg )._enum( name );
JDefinedClass container = jPackage._getClass( containerName );
String tag = "tag";
m.field( JMod.PUBLIC | JMod.FINAL, codeModel.INT, tag );
JMethod constructor = m.constructor( JMod.PRIVATE );
constructor.param( codeModel.INT, tag );
constructor.body().assign( JExpr._this().ref( tag ), JExpr.ref( tag ) );
addDenifition( container, m );
logger.info( "Enum({}.{})", m._package().name(), m.name() );
return super.visitEnum_def( ctx );
}
catch ( JClassAlreadyExistsException err ) {
throw new RuntimeException( err );
}
}
示例9: visitEnum_member_tag
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
@Override
public Void visitEnum_member_tag(Enum_member_tagContext ctx) {
int enumTag = Integer.parseInt( ctx.enum_tag().INTEGER_LITERAL().getText() );
String enumMember = ctx.enum_member().IDENTIFIER().getText();
Enum_defContext enumCtx = (Enum_defContext) ctx.getParent();
String enumName = enumCtx.enum_name().IDENTIFIER().getText();
ProtoContext pkgCtx = (ProtoContext) enumCtx.getParent();
String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
JDefinedClass m = codeModel._package( pkg )._getClass( enumName );
JEnumConstant enumConstant = m.enumConstant( enumMember );
enumConstant.arg( JExpr.lit( enumTag ) ).annotate( JsonProperty.class ).param( "index", enumTag );
logger.info( "\t +-> {}.{} {}", m._package().name(), m.name(), enumMember );
return super.visitEnum_member_tag( ctx );
}
示例10: setOnRequestPermissionsResultDelegateCall
import com.helger.jcodemodel.JExpr; //导入依赖的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
示例11: setOnActivityResultDelegateCall
import com.helger.jcodemodel.JExpr; //导入依赖的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
示例12: setPermissionMethods
import com.helger.jcodemodel.JExpr; //导入依赖的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
示例13: appendNullableValue
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
void appendNullableValue(AbstractJType type, IJExpression value) {
if (!type.isReference())
throw new AssertionError("appendNullableValue called for non-reference type");
else {
JConditional _if = body._if(value.eq(JExpr._null()));
Body thenBody = new Body(result, _if._then(), nameSource);
thenBody.appendNotNullValue(types._int, JExpr.lit(0));
Body elseBody = new Body(result, _if._else(), nameSource);
elseBody.appendNotNullValue(type, value);
}
}
示例14: buildPrivateConstructor
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
void buildPrivateConstructor() {
if (!isError) {
JMethod constructor = environment.buildValueClassConstructor(JMod.PRIVATE);
JVar acceptorParam = constructor.param(acceptorField.type(), acceptorField.name());
if (environment.hashCodeCaching() == Caching.PRECOMPUTE) {
JInvocation invocation = acceptorParam.invoke(hashCodeAcceptorMethodName());
constructor.body().assign(JExpr.refthis(hashCodeCachedValueField), invocation);
}
constructor.body().assign(JExpr.refthis(acceptorField.name()), acceptorParam);
}
}
示例15: buildAcceptMethod
import com.helger.jcodemodel.JExpr; //导入依赖的package包/类
void buildAcceptMethod() {
JMethod acceptMethod = environment.buildValueClassMethod(Source.toJMod(environment.acceptMethodAccessLevel()) | JMod.FINAL, environment.acceptMethodName());
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 exceptionTypeVar = acceptMethod.generify(visitorExceptionTypeParameter.name());
exceptionTypeVar.boundLike(visitorExceptionTypeParameter);
exceptionType = exceptionTypeVar;
acceptMethod._throws(exceptionType);
}
AbstractJClass usedValueClassType = environment.wrappedValueClassTypeInsideValueClass();
VisitorDefinition.VisitorUsage usedVisitorType = environment.visitor(usedValueClassType, resultType, exceptionType);
acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");
if (isError) {
acceptMethod.body()._throw(JExpr._new(types._UnsupportedOperationException));
} else {
JInvocation invocation = acceptorField.invoke(environment.acceptMethodName());
invocation.arg(JExpr.ref("visitor"));
acceptMethod.body()._return(invocation);
}
}