use of com.intellij.uiDesigner.PsiPropertiesProvider in project intellij-community by JetBrains.
the class PsiNestedFormLoader method loadForm.
public LwRootContainer loadForm(String formFileName) throws Exception {
if (myFormCache.containsKey(formFileName)) {
return myFormCache.get(formFileName);
}
VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(myModule, formFileName);
if (formFile == null) {
throw new Exception("Could not find nested form file " + formFileName);
}
final LwRootContainer container = Utils.getRootContainer(formFile.getInputStream(), new PsiPropertiesProvider(myModule));
myFormCache.put(formFileName, container);
return container;
}
use of com.intellij.uiDesigner.PsiPropertiesProvider in project intellij-community by JetBrains.
the class Generator method exposeForm.
/**
* @param rootContainer output parameter; should be LwRootContainer[1]
*/
public static FormProperty[] exposeForm(final Project project, final VirtualFile formFile, final LwRootContainer[] rootContainer) throws MyException {
final Module module = ModuleUtil.findModuleForFile(formFile, project);
LOG.assertTrue(module != null);
final PsiPropertiesProvider propertiesProvider = new PsiPropertiesProvider(module);
final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
final LwRootContainer _rootContainer;
try {
_rootContainer = Utils.getRootContainer(doc.getText(), propertiesProvider);
} catch (AlienFormFileException e) {
throw new MyException(e.getMessage());
} catch (Exception e) {
throw new MyException(UIDesignerBundle.message("error.cannot.process.form.file", e));
}
rootContainer[0] = _rootContainer;
final String classToBind = _rootContainer.getClassToBind();
if (classToBind == null) {
throw new MyException(UIDesignerBundle.message("error.form.is.not.bound.to.a.class"));
}
final PsiClass boundClass = FormEditingUtil.findClassToBind(module, classToBind);
if (boundClass == null) {
throw new MyException(UIDesignerBundle.message("error.bound.class.does.not.exist", classToBind));
}
final ArrayList<FormProperty> result = new ArrayList<>();
final MyException[] exception = new MyException[1];
FormEditingUtil.iterate(_rootContainer, new FormEditingUtil.ComponentVisitor<LwComponent>() {
public boolean visit(final LwComponent component) {
final String binding = component.getBinding();
if (binding == null) {
return true;
}
final PsiField[] fields = boundClass.getFields();
PsiField field = null;
for (int i = fields.length - 1; i >= 0; i--) {
if (binding.equals(fields[i].getName())) {
field = fields[i];
break;
}
}
if (field == null) {
exception[0] = new MyException(UIDesignerBundle.message("error.field.not.found.in.class", binding, classToBind));
return false;
}
final PsiClass fieldClass = getClassByType(field.getType());
if (fieldClass == null) {
exception[0] = new MyException(UIDesignerBundle.message("error.invalid.binding.field.type", binding, classToBind));
return false;
}
if (instanceOf(fieldClass, JTextComponent.class.getName())) {
result.add(new FormProperty(component, "getText", "setText", String.class.getName()));
} else if (instanceOf(fieldClass, JCheckBox.class.getName())) {
result.add(new FormProperty(component, "isSelected", "setSelected", boolean.class.getName()));
}
return true;
}
});
if (exception[0] != null) {
throw exception[0];
}
return result.toArray(new FormProperty[result.size()]);
}
use of com.intellij.uiDesigner.PsiPropertiesProvider in project intellij-community by JetBrains.
the class BaseFormInspection method checkFile.
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!file.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
return null;
}
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return null;
}
final Module module = ModuleUtil.findModuleForFile(virtualFile, file.getProject());
if (module == null) {
return null;
}
final LwRootContainer rootContainer;
try {
rootContainer = Utils.getRootContainer(file.getText(), new PsiPropertiesProvider(module));
} catch (Exception e) {
return null;
}
if (rootContainer.isInspectionSuppressed(getShortName(), null)) {
return null;
}
final FormFileErrorCollector collector = new FormFileErrorCollector(file, manager, isOnTheFly);
startCheckForm(rootContainer);
FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor() {
@Override
public boolean visit(final IComponent component) {
if (!rootContainer.isInspectionSuppressed(getShortName(), component.getId())) {
checkComponentProperties(module, component, collector);
}
return true;
}
});
doneCheckForm(rootContainer);
return collector.result();
}
Aggregations