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);
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations