use of com.intellij.util.xml.highlighting.DomElementProblemDescriptor in project intellij-community by JetBrains.
the class EditorTextFieldControl method updateComponent.
@Override
protected void updateComponent() {
final DomElement domElement = getDomElement();
if (domElement == null || !domElement.isValid())
return;
final EditorTextField textField = getEditorTextField(getComponent());
final Project project = getProject();
ApplicationManager.getApplication().invokeLater(() -> {
if (!project.isOpen())
return;
if (!getDomWrapper().isValid())
return;
final DomElement domElement1 = getDomElement();
if (domElement1 == null || !domElement1.isValid())
return;
final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(domElement1);
final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(domElement1);
final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(domElement1, true, HighlightSeverity.WARNING));
warningProblems.removeAll(errorProblems);
Color background = getDefaultBackground();
if (errorProblems.size() > 0 && textField.getText().trim().length() == 0) {
background = getErrorBackground();
} else if (warningProblems.size() > 0) {
background = getWarningBackground();
}
final Editor editor = textField.getEditor();
if (editor != null) {
final MarkupModel markupModel = editor.getMarkupModel();
markupModel.removeAllHighlighters();
if (!errorProblems.isEmpty() && editor.getDocument().getLineCount() > 0) {
final TextAttributes attributes = SimpleTextAttributes.ERROR_ATTRIBUTES.toTextAttributes();
attributes.setEffectType(EffectType.WAVE_UNDERSCORE);
attributes.setEffectColor(attributes.getForegroundColor());
markupModel.addLineHighlighter(0, 0, attributes);
editor.getContentComponent().setToolTipText(errorProblems.get(0).getDescriptionTemplate());
}
}
textField.setBackground(background);
});
}
use of com.intellij.util.xml.highlighting.DomElementProblemDescriptor in project intellij-community by JetBrains.
the class DomCollectionControl method validate.
private void validate() {
DomElement domElement = getDomElement();
final List<DomElementProblemDescriptor> list = DomElementAnnotationsManager.getInstance(getProject()).getCachedProblemHolder(domElement).getProblems(domElement);
final List<String> messages = new ArrayList<>();
for (final DomElementProblemDescriptor descriptor : list) {
if (descriptor instanceof DomCollectionProblemDescriptor && myChildDescription.equals(((DomCollectionProblemDescriptor) descriptor).getChildDescription())) {
messages.add(descriptor.getDescriptionTemplate());
}
}
myCollectionPanel.setErrorMessages(ArrayUtil.toStringArray(messages));
myCollectionPanel.repaint();
}
use of com.intellij.util.xml.highlighting.DomElementProblemDescriptor in project intellij-community by JetBrains.
the class ErrorableTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component component = myRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!myRoot.isValid()) {
return component;
}
final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(myRowDomElement.getManager().getProject());
final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(myRoot);
final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(myCellValueDomElement);
final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(myCellValueDomElement, true, HighlightSeverity.WARNING));
warningProblems.removeAll(errorProblems);
final boolean hasErrors = errorProblems.size() > 0;
if (hasErrors) {
component.setForeground(JBColor.RED);
if (component instanceof JComponent) {
((JComponent) component).setToolTipText(TooltipUtils.getTooltipText(errorProblems));
}
} else {
component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
if (component instanceof JComponent) {
((JComponent) component).setToolTipText(null);
}
}
// highlight empty cell with errors
if (hasErrors && (value == null || value.toString().trim().length() == 0)) {
component.setBackground(BaseControl.ERROR_BACKGROUND);
} else if (warningProblems.size() > 0) {
component.setBackground(BaseControl.WARNING_BACKGROUND);
if (isSelected)
component.setForeground(JBColor.foreground());
}
final List<DomElementProblemDescriptor> errorDescriptors = annotationsManager.getCachedProblemHolder(myRowDomElement).getProblems(myRowDomElement, true, true);
if (table.getModel().getColumnCount() - 1 == column) {
if (errorDescriptors.size() > 0) {
final JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(component, BorderLayout.CENTER);
wrapper.setBackground(component.getBackground());
final JLabel errorLabel = new JLabel(getErrorIcon());
wrapper.setToolTipText(TooltipUtils.getTooltipText(errorDescriptors));
wrapper.add(errorLabel, BorderLayout.EAST);
if (component instanceof JComponent) {
final JComponent jComponent = (JComponent) component;
wrapper.setBorder(jComponent.getBorder());
jComponent.setBorder(BorderFactory.createEmptyBorder());
jComponent.setToolTipText(TooltipUtils.getTooltipText(errorDescriptors));
}
return wrapper;
} else {
if (component instanceof JComponent) {
((JComponent) component).setToolTipText(null);
}
}
}
return component;
}
use of com.intellij.util.xml.highlighting.DomElementProblemDescriptor in project intellij-community by JetBrains.
the class ExtendsClassChecker method checkExtendClass.
@NotNull
public static List<DomElementProblemDescriptor> checkExtendClass(final GenericDomValue element, final PsiClass value, final String name, final boolean instantiatable, final boolean canBeDecorator, final boolean allowInterface, final boolean allowNonPublic, final boolean allowAbstract, final boolean allowEnum, final DomElementAnnotationHolder holder) {
final Project project = element.getManager().getProject();
PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
if (extendClass != null) {
if (!name.equals(value.getQualifiedName()) && !value.isInheritor(extendClass, true)) {
String message = DomBundle.message("class.is.not.a.subclass", value.getQualifiedName(), extendClass.getQualifiedName());
list.add(holder.createProblem(element, message));
}
}
if (instantiatable) {
if (value.hasModifierProperty(PsiModifier.ABSTRACT)) {
list.add(holder.createProblem(element, DomBundle.message("class.is.not.concrete", value.getQualifiedName())));
} else if (!allowNonPublic && !value.hasModifierProperty(PsiModifier.PUBLIC)) {
list.add(holder.createProblem(element, DomBundle.message("class.is.not.public", value.getQualifiedName())));
} else if (!PsiUtil.hasDefaultConstructor(value, true)) {
if (canBeDecorator) {
boolean hasConstructor = false;
for (PsiMethod method : value.getConstructors()) {
final PsiParameterList psiParameterList = method.getParameterList();
if (psiParameterList.getParametersCount() != 1)
continue;
PsiTypeElement typeElement = psiParameterList.getParameters()[0].getTypeElement();
if (typeElement != null) {
final PsiType psiType = typeElement.getType();
if (psiType instanceof PsiClassType) {
final PsiClass psiClass = ((PsiClassType) psiType).resolve();
if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
hasConstructor = true;
break;
}
}
}
}
if (!hasConstructor) {
list.add(holder.createProblem(element, DomBundle.message("class.decorator.or.has.default.constructor", value.getQualifiedName())));
}
} else {
list.add(holder.createProblem(element, DomBundle.message("class.has.no.default.constructor", value.getQualifiedName())));
}
}
}
if (!allowInterface && value.isInterface()) {
list.add(holder.createProblem(element, DomBundle.message("interface.not.allowed", value.getQualifiedName())));
}
if (!allowEnum && value.isEnum()) {
list.add(holder.createProblem(element, DomBundle.message("enum.not.allowed", value.getQualifiedName())));
}
if (!allowAbstract && value.hasModifierProperty(PsiModifier.ABSTRACT) && !value.isInterface()) {
list.add(holder.createProblem(element, DomBundle.message("abstract.class.not.allowed", value.getQualifiedName())));
}
return list;
}
use of com.intellij.util.xml.highlighting.DomElementProblemDescriptor in project intellij-community by JetBrains.
the class ExtendsClassChecker method checkExtendsClassInReferences.
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
if (!isPsiClassType(element)) {
return Collections.emptyList();
}
final Object valueObject = element.getValue();
if (!(valueObject instanceof PsiClass))
return Collections.emptyList();
final XmlElement valueElement = DomUtil.getValueElement(element);
if (valueElement == null)
return Collections.emptyList();
final PsiReference[] references = ourProvider.getReferencesByElement(valueElement, new ProcessingContext());
for (PsiReference reference : references) {
if (reference instanceof JavaClassReference) {
final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference) reference).getProvider();
final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES.getValue(((JavaClassReferenceProvider) psiReferenceProvider).getOptions()) : null;
if (value != null && value.length != 0) {
for (String className : value) {
final List<DomElementProblemDescriptor> problemDescriptors = checkExtendClass(element, ((PsiClass) valueObject), className, false, false, true, false, true, true, holder);
if (!problemDescriptors.isEmpty()) {
return problemDescriptors;
}
}
}
}
}
return Collections.emptyList();
}
Aggregations