Java 类com.intellij.util.xml.highlighting.DomElementProblemDescriptor 实例源码

项目:intellij-ce-playground    文件:ExtendsClassChecker.java   
public List<DomElementProblemDescriptor> checkForProblems(@NotNull final ExtendClass extend, @NotNull final DomElement _element, @NotNull final DomElementAnnotationHolder holder,
                          @NotNull final DomHighlightingHelper helper) {
  if (!(_element instanceof GenericDomValue)) return Collections.emptyList();
  GenericDomValue element = (GenericDomValue)_element;

  if (!isPsiClassType(element)) return Collections.emptyList();

  final Object valueObject = element.getValue();
  PsiClass psiClass = null;

  if (valueObject instanceof PsiClass) {
    psiClass = (PsiClass)valueObject;
  } else if (valueObject instanceof PsiClassType) {
    psiClass = ((PsiClassType)valueObject).resolve();
  }

  if (psiClass != null) {
      return checkExtendClass(element, psiClass, extend.value(),
                              extend.instantiatable(), extend.canBeDecorator(), extend.allowInterface(),
                              extend.allowNonPublic(), extend.allowAbstract(), extend.allowEnum(), holder);
  }
  return Collections.emptyList();
}
项目:tools-idea    文件:ExtendsClassChecker.java   
public List<DomElementProblemDescriptor> checkForProblems(@NotNull final ExtendClass extend, @NotNull final DomElement _element, @NotNull final DomElementAnnotationHolder holder,
                          @NotNull final DomHighlightingHelper helper) {
  if (!(_element instanceof GenericDomValue)) return Collections.emptyList();
  GenericDomValue element = (GenericDomValue)_element;

  if (!isPsiClassType(element)) return Collections.emptyList();

  final Object valueObject = element.getValue();
  PsiClass psiClass = null;

  if (valueObject instanceof PsiClass) {
    psiClass = (PsiClass)valueObject;
  } else if (valueObject instanceof PsiClassType) {
    psiClass = ((PsiClassType)valueObject).resolve();
  }

  if (psiClass != null) {
      return checkExtendClass(element, psiClass, extend.value(),
                              extend.instantiatable(), extend.canBeDecorator(), extend.allowInterface(),
                              extend.allowNonPublic(), extend.allowAbstract(), extend.allowEnum(), holder);
  }
  return Collections.emptyList();
}
项目:consulo-java    文件:ExtendsClassChecker.java   
public List<DomElementProblemDescriptor> checkForProblems(@NotNull final ExtendClass extend, @NotNull final DomElement _element, @NotNull final DomElementAnnotationHolder holder,
                          @NotNull final DomHighlightingHelper helper) {
  if (!(_element instanceof GenericDomValue)) return Collections.emptyList();
  GenericDomValue element = (GenericDomValue)_element;

  if (!isPsiClassType(element)) return Collections.emptyList();

  final Object valueObject = element.getValue();
  PsiClass psiClass = null;

  if (valueObject instanceof PsiClass) {
    psiClass = (PsiClass)valueObject;
  } else if (valueObject instanceof PsiClassType) {
    psiClass = ((PsiClassType)valueObject).resolve();
  }

  if (psiClass != null) {
      return checkExtendClass(element, psiClass, extend.value(),
                              extend.instantiatable(), extend.canBeDecorator(), extend.allowInterface(),
                              extend.allowNonPublic(), extend.allowAbstract(), extend.allowEnum(), holder);
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:ExtendsClassChecker.java   
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();
}
项目:intellij-ce-playground    文件:BaseDomElementNode.java   
@Override
protected void doUpdate() {
  if (!myDomElement.isValid()) return;
  final Project project = myDomElement.getManager().getProject();
  if (project.isDisposed()) return;

  setUniformIcon(getNodeIcon());
  clearColoredText();

  final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
  final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(myDomElement);
  final List<DomElementProblemDescriptor> problems =
    holder.getProblems(myDomElement, highlightIfChildrenHaveProblems(), HighlightSeverity.ERROR);

  if (problems.size() > 0) {
    final String toolTip = TooltipUtils.getTooltipText(problems);
    addColoredFragment(getNodeName(), toolTip, getWavedAttributes(SimpleTextAttributes.STYLE_PLAIN));
    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", toolTip, SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
  else if (myDomElement.getXmlTag() == null && !(myDomElement instanceof DomFileElement)) {
    addColoredFragment(getNodeName(), folder ? SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  else if (folder) {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    final int childrenCount = getChildren().length;
    addColoredFragment(" (" + childrenCount + ')', SimpleTextAttributes.GRAY_ATTRIBUTES);
  }
  else {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);

    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
}
项目:intellij-ce-playground    文件:DomElementsGroupNode.java   
private boolean hasErrors() {
  if (!myParentElement.isValid()) return false;

  for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
    final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
    final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
    final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
    if (problems.size() > 0) return true;
  }

  return false;
}
项目:intellij-ce-playground    文件:DomCollectionControl.java   
private void validate() {
  DomElement domElement = getDomElement();
  final List<DomElementProblemDescriptor> list =
    DomElementAnnotationsManager.getInstance(getProject()).getCachedProblemHolder(domElement).getProblems(domElement);
  final List<String> messages = new ArrayList<String>();
  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();
}
项目:intellij-ce-playground    文件:TooltipUtils.java   
private static String[] getMessages(final List<DomElementProblemDescriptor> problems) {
  String[] messages = new String[problems.size()];
  for (int i = 0; i < problems.size(); i++) {
    messages[i] = problems.get(i).getDescriptionTemplate();
  }
  return messages;
}
项目:tools-idea    文件:ExtendsClassChecker.java   
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 PsiReference[] references = ourProvider.getReferencesByElement(DomUtil.getValueElement(element), 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();
}
项目:tools-idea    文件:BaseDomElementNode.java   
protected void doUpdate() {
  if (!myDomElement.isValid()) return;
  final Project project = myDomElement.getManager().getProject();
  if (project.isDisposed()) return;

  setUniformIcon(getNodeIcon());
  clearColoredText();

  final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
  final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(myDomElement);
  final List<DomElementProblemDescriptor> problems =
    holder.getProblems(myDomElement, highlightIfChildrenHaveProblems(), HighlightSeverity.ERROR);

  if (problems.size() > 0) {
    final String toolTip = TooltipUtils.getTooltipText(problems);
    addColoredFragment(getNodeName(), toolTip, getWavedAttributes(SimpleTextAttributes.STYLE_PLAIN));
    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", toolTip, SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
  else if (myDomElement.getXmlTag() == null && !(myDomElement instanceof DomFileElement)) {
    addColoredFragment(getNodeName(), folder ? SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  else if (folder) {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    final int childrenCount = getChildren().length;
    addColoredFragment(" (" + childrenCount + ')', SimpleTextAttributes.GRAY_ATTRIBUTES);
  }
  else {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);

    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
}
项目:tools-idea    文件:DomElementsGroupNode.java   
private boolean hasErrors() {
  if (!myParentElement.isValid()) return false;

  for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
    final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
    final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
    final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
    if (problems.size() > 0) return true;
  }

  return false;
}
项目:tools-idea    文件:DomCollectionControl.java   
private void validate() {
  DomElement domElement = getDomElement();
  final List<DomElementProblemDescriptor> list =
    DomElementAnnotationsManager.getInstance(getProject()).getCachedProblemHolder(domElement).getProblems(domElement);
  final List<String> messages = new ArrayList<String>();
  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();
}
项目:tools-idea    文件:TooltipUtils.java   
private static String[] getMessages(final List<DomElementProblemDescriptor> problems) {
  String[] messages = new String[problems.size()];
  for (int i = 0; i < problems.size(); i++) {
    messages[i] = problems.get(i).getDescriptionTemplate();
  }
  return messages;
}
项目:idea-dozer-plugin    文件:FieldExpression.java   
public DomElementProblemDescriptor toDomProblem(DomElementAnnotationHolder holder) {
  if (textRange == null) {
    return holder.createProblem(FieldExpression.this.fieldDefinition, severity, message);
  }
  else {
    return holder.createProblem(FieldExpression.this.fieldDefinition, severity, message, textRange);
  }
}
项目:consulo-xml    文件:BaseDomElementNode.java   
protected void doUpdate() {
  if (!myDomElement.isValid()) return;
  final Project project = myDomElement.getManager().getProject();
  if (project.isDisposed()) return;

  setUniformIcon(getNodeIcon());
  clearColoredText();

  final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
  final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(myDomElement);
  final List<DomElementProblemDescriptor> problems =
    holder.getProblems(myDomElement, highlightIfChildrenHaveProblems(), HighlightSeverity.ERROR);

  if (problems.size() > 0) {
    final String toolTip = TooltipUtils.getTooltipText(problems);
    addColoredFragment(getNodeName(), toolTip, getWavedAttributes(SimpleTextAttributes.STYLE_PLAIN));
    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", toolTip, SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
  else if (myDomElement.getXmlTag() == null && !(myDomElement instanceof DomFileElement)) {
    addColoredFragment(getNodeName(), folder ? SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  else if (folder) {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    final int childrenCount = getChildren().length;
    addColoredFragment(" (" + childrenCount + ')', SimpleTextAttributes.GRAY_ATTRIBUTES);
  }
  else {
    addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);

    if (isShowContainingFileInfo()) {
      addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
  }
}
项目:consulo-xml    文件:DomElementsGroupNode.java   
private boolean hasErrors() {
  if (!myParentElement.isValid()) return false;

  for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
    final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
    final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
    final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
    if (problems.size() > 0) return true;
  }

  return false;
}
项目:consulo-xml    文件:DomCollectionControl.java   
private void validate() {
  DomElement domElement = getDomElement();
  final List<DomElementProblemDescriptor> list =
    DomElementAnnotationsManager.getInstance(getProject()).getCachedProblemHolder(domElement).getProblems(domElement);
  final List<String> messages = new ArrayList<String>();
  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();
}
项目:consulo-xml    文件:TooltipUtils.java   
private static String[] getMessages(final List<DomElementProblemDescriptor> problems) {
  String[] messages = new String[problems.size()];
  for (int i = 0; i < problems.size(); i++) {
    messages[i] = problems.get(i).getDescriptionTemplate();
  }
  return messages;
}
项目:consulo-java    文件:ExtendsClassChecker.java   
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 PsiReference[] references = ourProvider.getReferencesByElement(DomUtil.getValueElement(element), 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();
}
项目:intellij-ce-playground    文件:ExtendsClassChecker.java   
@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<DomElementProblemDescriptor>();
  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;
}
项目:intellij-ce-playground    文件:ErrorableTableCellRenderer.java   
@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<DomElementProblemDescriptor>(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;
}
项目:intellij-ce-playground    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations) {
  if (annotations.size() == 0) return null;

  return getTooltipText(getMessages(annotations));
}
项目:intellij-ce-playground    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations, String[] messages) {
  return getTooltipText(ArrayUtil.mergeArrays(getMessages(annotations), messages));
}
项目:tools-idea    文件:ExtendsClassChecker.java   
@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<DomElementProblemDescriptor>();
  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;
}
项目:tools-idea    文件:ErrorableTableCellRenderer.java   
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<DomElementProblemDescriptor>(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;
}
项目:tools-idea    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations) {
  if (annotations.size() == 0) return null;

  return getTooltipText(getMessages(annotations));
}
项目:tools-idea    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations, String[] messages) {
  return getTooltipText(ArrayUtil.mergeArrays(getMessages(annotations), messages));
}
项目:consulo-xml    文件:ErrorableTableCellRenderer.java   
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<DomElementProblemDescriptor>(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;
}
项目:consulo-xml    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations) {
  if (annotations.size() == 0) return null;

  return getTooltipText(getMessages(annotations));
}
项目:consulo-xml    文件:TooltipUtils.java   
public static String getTooltipText(List<DomElementProblemDescriptor> annotations, String[] messages) {
  return getTooltipText(ArrayUtil.mergeArrays(getMessages(annotations), messages));
}
项目:consulo-java    文件:ExtendsClassChecker.java   
@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<DomElementProblemDescriptor>();
  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;
}