Search in sources :

Example 1 with JavaSignature

use of org.whole.lang.java.util.JavaReflectUtils.JavaSignature in project whole by wholeplatform.

the class WorkflowsUIContentAssistVisitor method allSignatures.

protected boolean allSignatures(IEntity entity) {
    if (!WorkflowsUtils.isSignatureInJavaActivity(entity))
        return false;
    IEntity parent = entity.wGetParent();
    boolean isMethod = !Matcher.match(CreateJavaClassInstance, parent);
    boolean isStatic = Matcher.match(InvokeJavaClassMethod, parent);
    IEntity classNameEntity = parent.wGet(className);
    if (!Matcher.matchImpl(StringLiteral, classNameEntity))
        return false;
    String className = classNameEntity.wStringValue();
    Class<?> declaringClass = null;
    try {
        declaringClass = JavaReflectUtils.forName(className, getClassLoader());
    } catch (IllegalArgumentException e) {
        return false;
    }
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction signaturesGroup = aef.createGroupAction();
    signaturesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(20)));
    signaturesGroup.getText().setValue("workflows.signatures");
    Actions actions = aef.createActions(0);
    WorkflowsEntityFactory wef = WorkflowsEntityFactory.instance;
    if (isMethod) {
        for (Method method : declaringClass.getMethods()) if (isStatic == Modifier.isStatic(method.getModifiers())) {
            JavaSignature signature = JavaReflectUtils.fromMethod(method);
            StringLiteral literal = wef.createStringLiteral(JavaReflectUtils.unparse(signature));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(literal, WorkflowsUtils.unparseCompact(signature), calculateImageDescriptor(parent)));
        }
    } else {
        for (Constructor<?> constructor : declaringClass.getConstructors()) {
            JavaSignature signature = JavaReflectUtils.fromConstructor(constructor);
            StringLiteral literal = wef.createStringLiteral(JavaReflectUtils.unparse(signature));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(literal, WorkflowsUtils.unparseCompact(signature), calculateImageDescriptor(parent)));
        }
    }
    signaturesGroup.setActions(actions);
    return EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, signaturesGroup) : mergeResult(signaturesGroup);
}
Also used : WorkflowsEntityFactory(org.whole.lang.workflows.factories.WorkflowsEntityFactory) IEntity(org.whole.lang.model.IEntity) Actions(org.whole.lang.actions.model.Actions) InvokeJavaClassMethod(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.InvokeJavaClassMethod) Method(java.lang.reflect.Method) JavaSignature(org.whole.lang.java.util.JavaReflectUtils.JavaSignature) GroupAction(org.whole.lang.actions.model.GroupAction) StringLiteral(org.whole.lang.workflows.model.StringLiteral) StringLiteral(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.StringLiteral) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Aggregations

Method (java.lang.reflect.Method)1 Actions (org.whole.lang.actions.model.Actions)1 GroupAction (org.whole.lang.actions.model.GroupAction)1 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)1 JavaSignature (org.whole.lang.java.util.JavaReflectUtils.JavaSignature)1 IEntity (org.whole.lang.model.IEntity)1 WorkflowsEntityFactory (org.whole.lang.workflows.factories.WorkflowsEntityFactory)1 StringLiteral (org.whole.lang.workflows.model.StringLiteral)1 InvokeJavaClassMethod (org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.InvokeJavaClassMethod)1 StringLiteral (org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.StringLiteral)1