Search in sources :

Example 6 with ClassEntity

use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.

the class Processor method process.

public void process(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls, IProcessor visitor) {
    mainPackage = PsiClassUtil.getPackage(cls);
    onStarProcess(classEntity, factory, cls, visitor);
    for (FieldEntity fieldEntity : classEntity.getFields()) {
        generateField(factory, fieldEntity, cls, classEntity);
    }
    for (ClassEntity innerClass : classEntity.getInnerClasss()) {
        generateClass(factory, innerClass, cls, visitor);
    }
    generateGetterAndSetter(factory, cls, classEntity);
    generateConvertMethod(factory, cls, classEntity);
    onEndProcess(classEntity, factory, cls, visitor);
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) FieldEntity(org.gsonformat.intellij.entity.FieldEntity)

Example 7 with ClassEntity

use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.

the class Processor method generateClass.

protected void generateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass, IProcessor visitor) {
    onStartGenerateClass(factory, classEntity, parentClass, visitor);
    PsiClass generateClass = null;
    if (classEntity.isGenerate()) {
        //// TODO: 16/11/9  待重构 
        if (Config.getInstant().isSplitGenerate()) {
            try {
                generateClass = PsiClassUtil.getPsiClass(parentClass.getContainingFile(), parentClass.getProject(), classEntity.getQualifiedName());
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        } else {
            String classContent = "public static class " + classEntity.getClassName() + "{}";
            generateClass = factory.createClassFromText(classContent, null).getInnerClasses()[0];
        }
        if (generateClass != null) {
            for (ClassEntity innerClass : classEntity.getInnerClasss()) {
                generateClass(factory, innerClass, generateClass, visitor);
            }
            if (!Config.getInstant().isSplitGenerate()) {
                generateClass = (PsiClass) parentClass.add(generateClass);
            }
            for (FieldEntity fieldEntity : classEntity.getFields()) {
                generateField(factory, fieldEntity, generateClass, classEntity);
            }
            generateGetterAndSetter(factory, generateClass, classEntity);
            generateConvertMethod(factory, generateClass, classEntity);
        }
    }
    onEndGenerateClass(factory, classEntity, parentClass, generateClass, visitor);
    if (Config.getInstant().isSplitGenerate()) {
        formatJavCode(generateClass);
    }
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) FieldEntity(org.gsonformat.intellij.entity.FieldEntity)

Example 8 with ClassEntity

use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.

the class FieldsDialog method createDataNode.

private void createDataNode(DefaultMutableTreeTableNode root, ClassEntity innerClassEntity) {
    for (FieldEntity field : innerClassEntity.getFields()) {
        DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(field);
        root.add(node);
        defaultMutableTreeTableNodeList.add(node);
    }
    for (ClassEntity classEntity : innerClassEntity.getInnerClasss()) {
        DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(classEntity);
        root.add(node);
        createDataNode(node, classEntity);
    }
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) FieldEntity(org.gsonformat.intellij.entity.FieldEntity) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)

Example 9 with ClassEntity

use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.

the class ConvertBridge method listTypeByValue.

private FieldEntity listTypeByValue(ClassEntity parentClass, String key, Object type, int deep) {
    FieldEntity item = null;
    if (type instanceof JSONObject) {
        ClassEntity classEntity = existDeclareClass((JSONObject) type);
        if (classEntity == null) {
            IterableFieldEntity iterableFieldEntity = new IterableFieldEntity();
            ClassEntity innerClassEntity = createInnerClass(createSubClassName(key, type), (JSONObject) type, parentClass);
            iterableFieldEntity.setKey(key);
            iterableFieldEntity.setDeep(deep);
            iterableFieldEntity.setTargetClass(innerClassEntity);
            item = iterableFieldEntity;
        } else {
            IterableFieldEntity fieldEntity = new IterableFieldEntity();
            fieldEntity.setKey(key);
            fieldEntity.setTargetClass(classEntity);
            fieldEntity.setType(classEntity.getQualifiedName());
            fieldEntity.setDeep(deep);
            item = fieldEntity;
        }
    } else if (type instanceof JSONArray) {
        FieldEntity fieldEntity = handleJSONArray(parentClass, (JSONArray) type, key, ++deep);
        fieldEntity.setKey(key);
        item = fieldEntity;
    } else {
        IterableFieldEntity fieldEntity = new IterableFieldEntity();
        fieldEntity.setKey(key);
        fieldEntity.setType(type.getClass().getSimpleName());
        fieldEntity.setDeep(deep);
        item = fieldEntity;
    }
    return item;
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) IterableFieldEntity(org.gsonformat.intellij.entity.IterableFieldEntity) JSONObject(org.json.JSONObject) FieldEntity(org.gsonformat.intellij.entity.FieldEntity) IterableFieldEntity(org.gsonformat.intellij.entity.IterableFieldEntity) JSONArray(org.json.JSONArray)

Example 10 with ClassEntity

use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.

the class CheckTreeCellProvider method format.

@Override
protected void format(CellContext arg0) {
    //  从CellContext获取tree中的文字和图标
    JTree tree = (JTree) arg0.getComponent();
    DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) arg0.getValue();
    Object obj = node.getUserObject();
    if (obj instanceof FieldEntity) {
        _label.setText(((FieldEntity) obj).getKey());
        _checkBox.setSelector((FieldEntity) obj);
    } else if (obj instanceof ClassEntity) {
        _label.setText(((ClassEntity) obj).getClassName());
        _checkBox.setSelector((ClassEntity) obj);
    }
    //        _label.setIcon(arg0.getIcon());
    //  根据selectionModel中的状态来绘制TristateCheckBox的外观
    TreePath path = tree.getPathForRow(arg0.getRow());
    if (path != null) {
        if (selectionModel.isPathSelected(path, true)) {
            _checkBox.setState(Boolean.TRUE);
        } else if (selectionModel.isPartiallySelected(path)) {
            //  注意“部分选中”状态的API
            _checkBox.setState(null);
        } else {
            _checkBox.setState(Boolean.FALSE);
        }
    }
    //  使用BorderLayout布局,依次放置TristateCheckBox和JLabel
    rendererComponent.setLayout(new BorderLayout());
    rendererComponent.add(_checkBox);
    rendererComponent.add(_label, BorderLayout.LINE_END);
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) BorderLayout(java.awt.BorderLayout) FieldEntity(org.gsonformat.intellij.entity.FieldEntity) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)

Aggregations

ClassEntity (org.gsonformat.intellij.entity.ClassEntity)13 FieldEntity (org.gsonformat.intellij.entity.FieldEntity)9 IterableFieldEntity (org.gsonformat.intellij.entity.IterableFieldEntity)5 JSONObject (org.json.JSONObject)4 DefaultMutableTreeTableNode (org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)2 JSONArray (org.json.JSONArray)2 PsiClass (com.intellij.psi.PsiClass)1 PsiElementFactory (com.intellij.psi.PsiElementFactory)1 BorderLayout (java.awt.BorderLayout)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 ClassProcessor (org.gsonformat.intellij.process.ClassProcessor)1 IProcessor (org.gsonformat.intellij.process.IProcessor)1