本文整理了Java中org.jboss.errai.codegen.meta.MetaClass
类的一些代码示例,展示了MetaClass
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass
类的具体详情如下:
包路径:org.jboss.errai.codegen.meta.MetaClass
类名称:MetaClass
暂无
代码示例来源:origin: org.jboss.errai/errai-bus
private Statement generateRequest(ClassStructureBuilder<?> classBuilder,
MetaMethod method, Statement methodParams, boolean intercepted) {
final Statement sendable = Stmt
.invokeStatic(MessageBuilder.class, "createCall")
.invoke("call", remote.getFullyQualifiedName())
.invoke("endpoint", ProxyUtil.createCallSignature(method),
Stmt.loadClassMember("qualifiers"),
methodParams)
.invoke("respondTo", method.getReturnType().asBoxed(), Stmt.loadVariable("remoteCallback"))
.invoke("errorsHandledBy", Stmt.loadVariable("errorCallback"));
final BlockStatement requestBlock = new BlockStatement();
requestBlock.addStatement(Stmt.declareVariable("sendable", RemoteCallSendable.class, sendable));
requestBlock.addStatement(Stmt.loadStatic(classBuilder.getClassDefinition(), "this")
.invoke("sendRequest", Variable.get("bus"), Variable.get("sendable")));
return requestBlock;
}
}
代码示例来源:origin: errai/errai
private void setStandaloneInterceptors(final Collection<MetaClass> standaloneInterceptors) {
for (final MetaClass interceptorClass : standaloneInterceptors) {
final InterceptsRemoteCall interceptor = interceptorClass.getAnnotation(InterceptsRemoteCall.class);
final Class<?>[] intercepts = interceptor.value();
for (final Class<?> intercept : intercepts) {
this.standaloneInterceptors.put(intercept, interceptorClass.asClass());
}
}
}
代码示例来源:origin: org.jboss.errai/errai-bus
private void generateMethod(ClassStructureBuilder<?> classBuilder, MetaMethod method) {
final List<Class<?>> interceptors = interceptorProvider.getInterceptors(remote, method);
final boolean intercepted = !interceptors.isEmpty();
final Parameter[] parms = DefParameters.from(method).getParameters().toArray(new Parameter[0]);
final Parameter[] finalParms = new Parameter[parms.length];
final List<Statement> parmVars = new ArrayList<Statement>();
for (int i = 0; i < parms.length; i++) {
finalParms[i] = Parameter.of(parms[i].getType().getErased(), parms[i].getName(), true);
parmVars.add(Stmt.loadVariable(parms[i].getName()));
}
final Statement parameters = (intercepted) ?
new StringStatement("getParameters()", MetaClassFactory.get(Object[].class)) :
Stmt.newArray(Object.class).initialize(parmVars.toArray());
final BlockBuilder<?> methodBlock =
classBuilder.publicMethod(method.getReturnType().getErased(), method.getName(), finalParms);
if (intercepted) {
methodBlock.append(generateInterceptorLogic(classBuilder, method,
generateRequest(classBuilder, method, parameters, true), parmVars, interceptors));
}
else {
methodBlock.append(generateRequest(classBuilder, method, parameters, false));
}
final Statement returnStmt = ProxyUtil.generateProxyMethodReturnStatement(method);
if (returnStmt != null) {
methodBlock.append(returnStmt);
}
methodBlock.finish();
}
代码示例来源:origin: org.jboss.errai/errai-bus
@Override
public Collection<MetaClass> provideTypesToExpose() {
final Set<MetaClass> types = new HashSet<MetaClass>();
for (final MetaClass metaClass : ClassScanner.getTypesAnnotatedWith(Remote.class)) {
for (final MetaMethod method : metaClass.getDeclaredMethods()) {
if (!method.getReturnType().isVoid()) {
types.add(method.getReturnType().getErased());
}
for (final MetaParameter parameter : method.getParameters()) {
final MetaClass type = parameter.getType();
types.add(type.getErased());
final MetaParameterizedType parameterizedType = type.getParameterizedType();
if (parameterizedType != null) {
for (final MetaType tp : parameterizedType.getTypeParameters()) {
if (tp instanceof MetaClass) {
types.add(((MetaClass) tp).getErased());
}
}
}
}
}
}
return types;
}
}
代码示例来源:origin: org.jboss.errai/errai-bus
public ClassStructureBuilder<?> generate() {
final String safeProxyClassName = remote.getFullyQualifiedName().replace('.', '_') + "Impl";
final ClassStructureBuilder<?> classBuilder =
ClassBuilder.define(safeProxyClassName, AbstractRpcProxy.class)
.packageScope()
.implementsInterface(remote)
.body();
for (final MetaMethod method : remote.getMethods()) {
if (ProxyUtil.shouldProxyMethod(method)) {
generateMethod(classBuilder, method);
}
}
return classBuilder;
}
代码示例来源:origin: org.jboss.errai/errai-cdi-client
private BlockBuilder<AnonymousClassStructureBuilder> getJsTypeSubscriptionCallback(final Decorable decorable, final FactoryController controller) {
final MetaParameter parm = decorable.getAsParameter();
final MetaClass eventType = parm.getType().asBoxed();
final String parmClassName = eventType.getFullyQualifiedName();
final MetaClass callBackType = parameterizedAs(JsTypeEventObserver.class, typeParametersOf(eventType));
final AnonymousClassStructureBuilder callBack = Stmt.newObject(callBackType).extend();
BlockBuilder<AnonymousClassStructureBuilder> callBackBlock;
final List<Statement> fireEventStmts = new ArrayList<>();
if (!decorable.isEnclosingTypeDependent()) {
fireEventStmts.add(Stmt.declareFinalVariable("instance", decorable.getEnclosingInjectable().getInjectedType(),
Stmt.invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt())));
}
fireEventStmts.add(decorable.call(Refs.get("event")));
callBackBlock = callBack.publicOverridesMethod("onEvent", Parameter.finalOf(eventType, "event"))
.appendAll(fireEventStmts)
.finish()
.publicOverridesMethod("toString")
._(Stmt.load("JsTypeObserver: " + parmClassName).returnValue());
return callBackBlock;
}
}
代码示例来源:origin: org.jboss.errai/errai-data-binding
Parameter.of(String.class, "property"));
Parameter.of(String.class, "property"),
Parameter.of(Object.class, "value"));
CaseBlockBuilder getSwitchBlock = Stmt.switch_(loadVariable("property"));
CaseBlockBuilder setSwitchBlock = Stmt.switch_(loadVariable("property"));
for (final String property : bindable.getBeanDescriptor().getProperties()) {
generateGetter(classBuilder, property, getSwitchBlock);
generateSetter(classBuilder, property, setSwitchBlock);
final Statement nonExistingPropertyException = Stmt.throw_(NonExistingPropertyException.class,
Stmt.loadLiteral(bindable.getName()), Variable.get("property"));
getSwitchBlock.default_().append(nonExistingPropertyException).finish();
setSwitchBlock.default_().append(nonExistingPropertyException).finish();
.append(Stmt.declareFinalVariable("props", Map.class, ObjectBuilder.newInstanceOf(HashMap.class)
.withParameters(agent().loadField("propertyTypes"))))
.append(Stmt.loadVariable("props").invoke("remove", "this"))
.append(Stmt.invokeStatic(Collections.class, "unmodifiableMap", Stmt.loadVariable("props")).returnValue())
.finish();
代码示例来源:origin: errai/errai
.define("Dynamic" + fullyQualifiedClassNameToCamelCase(validator.getFullyQualifiedName()), validator)
.publicScope()
.implementsInterface(parameterizedAs(GeneratedDynamicValidator.class, typeParametersOf(valueType)))
.body();
.publicMethod(parameterizedAs(Set.class, typeParametersOf(ConstraintViolation.class)), "validate",
finalOf(parameterizedAs(Map.class, typeParametersOf(String.class, Object.class)), "parameters"),
finalOf(valueType, "value"))
.body();
return loadVariable("dynamicValidator").invoke("addValidator", loadLiteral(annoType.getFullyQualifiedName()),
loadLiteral(valueType.getFullyQualifiedName()),
newObject(generatedValidatorBuilder.getClassDefinition()));
代码示例来源:origin: errai/errai
private void implementAccessibleMethods(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable, final BuildMetaClass factoryClass) {
final Multimap<String, MetaMethod> proxiedMethodsByName = HashMultimap.create();
final MetaClass injectedType = injectable.getInjectedType();
for (final MetaMethod method : injectedType.getMethods()) {
if (shouldProxyMethod(method, proxiedMethodsByName)) {
proxiedMethodsByName.put(method.getName(), method);
final BlockBuilder<?> body = createProxyMethodDeclaration(proxyImpl, method);
final StatementBuilder proxiedInstanceDeclaration = declareFinalVariable("proxiedInstance",
injectable.getInjectedType(), loadVariable("proxyHelper").invoke("getInstance", loadVariable("this")));
final ContextualStatementBuilder proxyHelperInvocation = proxyHelperInvocation(method, factoryClass);
final Statement nonInitializedCase;
final boolean nonInitializedReturns;
if (injectedType.isInterface() || method.isAbstract()) {
} else if (!(method.isPublic() || method.isPrivate() || method.isProtected())) {
.append(proxiedInstanceDeclaration)
.appendAll(controller.getInvokeBeforeStatements(method));
if (method.getReturnType().isVoid()) {
ifBlock.append(proxyHelperInvocation);
} else {
ifBlock.append(declareFinalVariable("retVal", method.getReturnType().getErased(), proxyHelperInvocation));
ifBlock.appendAll(controller.getInvokeAfterStatements(method));
ifBlock.append(loadVariable("retVal").returnValue());
if (nonInitializedReturns) {
body.append(ifBlock.finish().else_().append(nestedCall(nonInitializedCase).returnValue()).finish());
logger.warn("The normal scoped type, " + injectable.getInjectedType().getFullyQualifiedName()
代码示例来源:origin: errai/errai
if (!method.isStatic()) {
wrapperDefParms.add(Parameter.of(method.getDeclaringClass().getErased(), "instance"));
args[i++] = Refs.get(p.getName());
= classBuilder.publicMethod(method.getReturnType(),
PrivateAccessUtil.getPrivateMethodName(method))
.parameters(DefParameters.fromParameters(wrapperDefParms))
.body();
final BlockBuilder<CatchBlockBuilder> tryBuilder = Stmt.try_();
final ContextualStatementBuilder statementBuilder = Stmt.loadVariable(cachedMethod)
.invoke("invoke", method.isStatic() ? null : Refs.get("instance"), args);
if (method.getReturnType().isVoid()) {
tryBuilder._(statementBuilder);
tryBuilder._(Stmt.castTo(method.getReturnType().asBoxed(), statementBuilder).returnValue());
body._(tryBuilder
.finish()
.catch_(Throwable.class, "e")
._(Stmt.loadVariable("e").invoke("printStackTrace"))
._(Stmt.throw_(RuntimeException.class, Refs.get("e")))
.finish())
代码示例来源:origin: errai/errai
@Override
public void createReadableField(final MetaClass type,
final ClassStructureBuilder<?> classBuilder,
final MetaField field,
final Modifier[] modifiers) {
final String cachedField = initCachedField(classBuilder, field);
final String getterName = getReflectionFieldGetterName(field);
final MethodCommentBuilder<? extends ClassStructureBuilder<?>> methodBuilder =
classBuilder.privateMethod(field.getType().getErased(), PrivateAccessUtil.getPrivateFieldAccessorName(field));
if (!field.isStatic()) {
methodBuilder.parameters(
DefParameters.fromParameters(
Parameter.of(field.getDeclaringClass().getErased(), "instance")
)
);
}
methodBuilder.modifiers(modifiers)
.body()
._(Stmt.try_()
._(Stmt.nestedCall(Cast.to(field.getType().getErased(), Stmt.loadVariable(cachedField)
.invoke(getterName, field.isStatic() ? null : Refs.get("instance")))).returnValue())
.finish()
.catch_(Throwable.class, "e")
._(Stmt.loadVariable("e").invoke("printStackTrace"))
._(Stmt.throw_(RuntimeException.class, Refs.get("e")))
.finish())
.finish();
}
代码示例来源:origin: org.jboss.errai/errai-marshalling
public Statement extractJSONObjectProperty(final String fieldName, final MetaClass fromType) {
if (fromType.getFullyQualifiedName().equals(EJObject.class.getName())) {
return loadVariable("obj").invoke("get", fieldName);
}
else {
return Stmt.nestedCall(Cast.to(fromType, loadVariable("a0"))).invoke("get", fieldName);
}
}
代码示例来源:origin: errai/errai
public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder,
final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod,
final Statement marshallerCreationCallback) {
final String fieldName = MarshallingGenUtil.getVarName(type);
if (classStructureBuilder.getClassDefinition().getField(fieldName) == null) {
final Statement marshallerLookup = createMarshallerLookup(marshallerForType, type, marshallerCreationCallback);
if (initMethod == null) {
classStructureBuilder.privateField(fieldName,
parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed())))
.initializesWith(marshallerLookup).finish();
}
else {
classStructureBuilder.privateField(fieldName,
parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed())))
.initializesWith(Stmt.load(null)).finish();
initMethod.append(
If.isNull(Stmt.loadVariable(fieldName)).append(
Stmt.loadVariable(fieldName).assignValue(marshallerLookup)).finish());
}
}
}
代码示例来源:origin: errai/errai
public Statement unwrapJSON(final Statement valueStatement, final MetaClass toType, final MetaClass targetType) {
if (toType.isEnum()) {
return demarshallEnum(Stmt.nestedCall(valueStatement).invoke("isObject"), valueStatement, toType);
}
else {
final String varName = MarshallingGenUtil.getVarName(toType);
if (toType.equals(MetaClassFactory.get(Object.class))) {
return Stmt.castTo(ObjectMarshaller.class, Stmt.loadVariable(varName))
.invoke("demarshall", targetType.asClass(), valueStatement, loadVariable("a1"));
}
return Stmt.loadVariable(varName)
.invoke("demarshall", valueStatement, loadVariable("a1"));
}
}
代码示例来源:origin: org.jboss.errai/errai-navigation
/**
* Appends a method that destroys the IOC bean associated with a page node if the bean is
* dependent scope.
*
* @param pageImplBuilder
* The class builder for the implementation of PageNode we are adding the method to.
* @param pageClass
* The "content type" (Widget subclass) of the page. This is the type the user annotated
* with {@code @Page}.
*/
private void appendDestroyMethod(AnonymousClassStructureBuilder pageImplBuilder, MetaClass pageClass) {
BlockBuilder<?> method = pageImplBuilder.publicMethod(
void.class,
"destroy",
Parameter.of(pageClass, "widget")).body();
if (pageClass.getAnnotation(Singleton.class) == null && pageClass.getAnnotation(ApplicationScoped.class) == null
&& pageClass.getAnnotation(EntryPoint.class) == null) {
method.append(Stmt.loadVariable("bm").invoke("destroyBean", Stmt.loadVariable("widget")));
}
method.finish();
}
代码示例来源:origin: errai/errai
private ObjectBuilder createAnonymousImpl(final MetaClass type) {
final AnonymousClassStructureBuilder builder = newObject(type).extend();
stream(type.getMethods())
.filter(m -> m.isPublic() && m.isAbstract())
.forEach(m -> {
builder
.publicOverridesMethod(m.getName(), of(m.getParameters()))
.append(Stmt.throw_(RuntimeException.class))
.finish();
});
return builder.finish();
}
代码示例来源:origin: org.jboss.errai/errai-jaxrs-client
private static Statement marshal(final MetaClass type, final Statement statement) {
ContextualStatementBuilder s = null;
if (type.isPrimitive()) {
s = Stmt.nestedCall(Stmt.newObject(type.asBoxed()).withParameters(statement)).invoke("toString");
}
else if (type.getFullyQualifiedName().equals(Date.class.getName())) {
s = Stmt.nestedCall(new TernaryStatement(Bool.isNull(statement), Stmt.load(""), Stmt.nestedCall(statement).invoke("toGMTString")));
}
else {
s = Stmt.nestedCall(new TernaryStatement(Bool.isNull(statement), Stmt.load(""), Stmt.nestedCall(statement)));
if (!type.equals(MetaClassFactory.get(String.class))) {
s = s.invoke("toString");
}
}
return s;
}
代码示例来源:origin: errai/errai
private ObjectBuilder createJsTypeProvider(final MetaClass type) {
return newObject(DummyJsTypeProvider.class)
.extend()
.publicOverridesMethod("getInstance")
.append(nestedCall(createAnonymousImpl(type)).returnValue())
.finish()
.publicOverridesMethod("getName")
.append(loadLiteral("Anti-inlining impl for: " + type.getFullyQualifiedName()).returnValue())
.finish()
.finish();
}
代码示例来源:origin: errai/errai
@Override
public void generateDecorator(final Decorable decorable, final FactoryController controller) {
MetaMethod method = decorable.getAsMethod();
MetaParameter[] params = method.getParameters();
if (params.length != 1 || !params[0].getType().getErased().equals(MetaClassFactory.get(SyncResponses.class))) {
throw new GenerationException("Methods annotated with @" + Sync.class.getName()
+ " need to have exactly one parameter of type: "
+ SyncResponses.class.getName() +
". Check method: " + GenUtil.getMethodString(method) + " in class "
+ method.getDeclaringClass().getFullyQualifiedName());
}
Sync syncAnnotation = (Sync) decorable.getAnnotation();
controller.addInitializationStatements(createInitStatements(decorable.getDecorableDeclaringType(), "obj", syncAnnotation, decorable, controller));
final Statement syncWorker = controller.getReferenceStmt("syncWorker", ClientSyncWorker.class);
final Statement destruction = Stmt.nestedCall(syncWorker).invoke("stop");
controller.addDestructionStatements(Collections.singletonList(destruction));
}
代码示例来源:origin: errai/errai
private static void _doRunnableTasks(final Collection<MetaClass> classes, final BlockBuilder<?> blockBuilder) {
for (final MetaClass clazz : classes) {
if (!clazz.isAssignableTo(Runnable.class)) {
throw new RuntimeException("annotated @IOCBootstrap task: " + clazz.getName() + " is not of type: "
+ Runnable.class.getName());
}
blockBuilder.append(Stmt.nestedCall(Stmt.newObject(clazz)).invoke("run"));
}
}
内容来源于网络,如有侵权,请联系作者删除!