Java 类com.intellij.util.xml.DomUtil 实例源码

项目:intellij-ce-playground    文件:DomElementsToggleAction.java   
public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) {
  myTreeView = treeView;
  myClass = aClass;

  Icon myIcon = ElementPresentationManager.getIcon(myClass);
  if (myIcon == null) {
    myIcon = AllIcons.Nodes.Pointcut;
  }
  this.myIcon = myIcon;

  myText = TypePresentationService.getService().getTypePresentableName(myClass);

  if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(AbstractDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>());

  if(getHiders().get(myClass) == null) getHiders().put(myClass, true);
}
项目:intellij-ce-playground    文件:AddElementInCollectionAction.java   
@Override
protected AnAction createAddingAction(final AnActionEvent e,
                                              final String name,
                                              final Icon icon,
                                              final Type type,
                                              final DomCollectionChildDescription description) {

  final DomElement parentDomElement = getParentDomElement(e);

  if (parentDomElement instanceof MergedObject) {
    final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations();
    final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true);

    for (DomElement implementation : implementations) {
      final XmlFile xmlFile = DomUtil.getFile(implementation);
      actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description));
    }
    return actionGroup;
  }

  return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description);
}
项目:intellij-ce-playground    文件:DeleteDomElement.java   
@Override
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
  final SimpleNode selectedNode = treeView.getTree().getSelectedNode();

  if (selectedNode instanceof BaseDomElementNode) {

    if (selectedNode instanceof DomFileElementNode) {
      e.getPresentation().setVisible(false);
      return;
    }

    final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement();

    final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove",
                                                Messages.getQuestionIcon());
    if (ret == Messages.OK) {
    new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {
      @Override
      protected void run(@NotNull final Result result) throws Throwable {
        domElement.undefine();
      }
    }.execute();
    }
  }
}
项目:intellij-ce-playground    文件:DomElementAnnotationsManagerImpl.java   
@Override
@NotNull
public DomElementsProblemsHolder getProblemHolder(DomElement element) {
  if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER;
  final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(element);

  synchronized (LOCK) {
    final XmlTag tag = fileElement.getRootElement().getXmlTag();
    if (tag != null) {
      final DomElementsProblemsHolder readyHolder = tag.getUserData(DOM_PROBLEM_HOLDER_KEY);
      if (readyHolder != null) {
        return readyHolder;
      }
    }
    return EMPTY_PROBLEMS_HOLDER;
  }
}
项目:intellij-ce-playground    文件:DomElementAnnotationsManagerImpl.java   
@NotNull
public DomHighlightStatus getHighlightStatus(final DomElement element) {
  synchronized (LOCK) {
    final DomFileElement<DomElement> root = DomUtil.getFileElement(element);
    if (!isHolderOutdated(root.getFile())) {
      final DomElementsProblemsHolder holder = getProblemHolder(element);
      if (holder instanceof DomElementsProblemsHolderImpl) {
        DomElementsProblemsHolderImpl holderImpl = (DomElementsProblemsHolderImpl)holder;
        final List<DomElementsInspection> suitableInspections = getSuitableDomInspections(root, true);
        final DomElementsInspection mockInspection = getMockInspection(root);
        final boolean annotatorsFinished = mockInspection == null || holderImpl.isInspectionCompleted(mockInspection);
        final boolean inspectionsFinished = areInspectionsFinished(holderImpl, suitableInspections);
        if (annotatorsFinished) {
          if (suitableInspections.isEmpty() || inspectionsFinished) return DomHighlightStatus.INSPECTIONS_FINISHED;
          return DomHighlightStatus.ANNOTATORS_FINISHED;
        }
      }
    }
    return DomHighlightStatus.NONE;
  }

}
项目:intellij-ce-playground    文件:AbstractDomElementNode.java   
protected boolean shouldBeShown(final Type type) {
  final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY);
  if (type == null || hiders == null || hiders.size() == 0) return true;

  final Class aClass = ReflectionUtil.getRawType(type);

  List<Class> allParents = new ArrayList<Class>();
  for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) {
    if (entry.getKey().isAssignableFrom(aClass)) {
      allParents.add(entry.getKey());
    }
  }
  if (allParents.size() == 0) return false;

  Collections.sort(allParents, INHERITORS_COMPARATOR);

  return hiders.get(allParents.get(0)).booleanValue();

}
项目:intellij-ce-playground    文件:MavenDomProjectProcessorUtils.java   
@Nullable
public T process(@NotNull MavenDomProjectModel projectDom) {
  MavenDomParent parent = projectDom.getMavenParent();
  MavenParentDesc parentDesc = null;
  if (DomUtil.hasXml(parent)) {
    String parentGroupId = parent.getGroupId().getStringValue();
    String parentArtifactId = parent.getArtifactId().getStringValue();
    String parentVersion = parent.getVersion().getStringValue();
    String parentRelativePath = parent.getRelativePath().getStringValue();
    if (StringUtil.isEmptyOrSpaces(parentRelativePath)) parentRelativePath = "../pom.xml";
    MavenId parentId = new MavenId(parentGroupId, parentArtifactId, parentVersion);
    parentDesc = new MavenParentDesc(parentId, parentRelativePath);
  }

  return process(myManager.getGeneralSettings(), MavenDomUtil.getVirtualFile(projectDom), parentDesc);
}
项目:intellij-ce-playground    文件:MavenProjectModelModifier.java   
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull final LanguageLevel level) {
  if (!myProjectsManager.isMavenizedModule(module)) return null;

  MavenProject mavenProject = myProjectsManager.findProject(module);
  if (mavenProject == null) return null;

  final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
  if (model == null) return null;

  new WriteCommandAction(myProject, "Add Maven Dependency", DomUtil.getFile(model)) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      MavenDomConfiguration configuration = getCompilerPlugin(model).getConfiguration();
      XmlTag tag = configuration.ensureTagExists();
      setChildTagValue(tag, "source", level.getCompilerComplianceDefaultOption());
      setChildTagValue(tag, "target", level.getCompilerComplianceDefaultOption());
      Document document = PsiDocumentManager.getInstance(myProject).getDocument(DomUtil.getFile(model));
      if (document != null) {
        FileDocumentManager.getInstance().saveDocument(document);
      }
    }
  }.execute();
  return myProjectsManager.forceUpdateProjects(Collections.singleton(mavenProject));
}
项目:intellij-ce-playground    文件:AntDomMacrodefAttributeReference.java   
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
  final PsiElement element = psiReference.getElement();
  if (element == null) {
    return null;
  }
  final DomElement domElement = DomUtil.getDomElement(element);
  if (domElement == null) {
    return null;
  }
  final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false);
  if (macrodef == null) {
    return null;
  }
  final String name = AntStringResolver.computeString(domElement, psiReference.getCanonicalText());
  for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) {
    if (name.equals(attribute.getName().getStringValue())) {
      final DomTarget target = DomTarget.getTarget(attribute);
      return target != null? PomService.convertToPsi(target) : null;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:ActionOrGroupResolveConverter.java   
@Nullable
@Override
public LookupElement createLookupElement(ActionOrGroup actionOrGroup) {
  if (actionOrGroup instanceof Action) {
    Action action = (Action)actionOrGroup;
    final PsiElement element = getPsiElement(actionOrGroup);
    if (element == null) {
      throw new IllegalStateException(action.getId().getStringValue() + " in " + DomUtil.getFile(action) + " " + action.isValid() + " ");
    }

    LookupElementBuilder builder =
      LookupElementBuilder.create(ObjectUtils.assertNotNull(element),
                                  ObjectUtils.assertNotNull(getName(action)));

    final String text = action.getText().getStringValue();
    if (StringUtil.isNotEmpty(text)) {
      String withoutMnemonic = StringUtil.replace(text, "_", "");
      builder = builder.withTailText(" \"" + withoutMnemonic + "\"", true);
    }

    return builder;
  }

  return super.createLookupElement(actionOrGroup);
}
项目:butterknife_inspections    文件:ButterKnifeNoViewWithIdInspection.java   
private boolean checkIncludes(PsiFile layoutFile, PsiElement idElement) {
    AndroidFacet facet = AndroidFacet.getInstance(idElement);
    PsiFile containingFile = idElement.getContainingFile();
    DomFileElement<AndroidDomElement> fileElement = DomManager.getDomManager(layoutFile.getProject()).getFileElement((XmlFile) layoutFile, AndroidDomElement.class);
    boolean found = false;

    if (fileElement != null) {
        AndroidDomElement rootElement = fileElement.getRootElement();
        List<Include> includes = DomUtil.getChildrenOfType(rootElement, Include.class);
        for (Include include : includes) {
            ResourceValue value = include.getLayout().getValue();
            if (value != null) {
                if (facet != null) {
                    if (value.getResourceType() != null && value.getResourceName() != null) {
                        List<PsiFile> resourceFiles = facet.getLocalResourceManager().findResourceFiles(value.getResourceType(), value.getResourceName());
                        if (!resourceFiles.isEmpty()) {

                            found = isInAllIncludes(idElement, found, resourceFiles);
                        }
                    }
                }
            }
        }
    }
    return found;
}
项目:tools-idea    文件:DomElementsToggleAction.java   
public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) {
  myTreeView = treeView;
  myClass = aClass;

  Icon myIcon = ElementPresentationManager.getIcon(myClass);
  if (myIcon == null) {
    myIcon = AllIcons.Nodes.Pointcut;
  }
  this.myIcon = myIcon;

  myText = TypePresentationService.getService().getTypePresentableName(myClass);

  if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(BaseDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>());

  if(getHiders().get(myClass) == null) getHiders().put(myClass, true);
}
项目:tools-idea    文件:AddElementInCollectionAction.java   
protected AnAction createAddingAction(final AnActionEvent e,
                                              final String name,
                                              final Icon icon,
                                              final Type type,
                                              final DomCollectionChildDescription description) {

  final DomElement parentDomElement = getParentDomElement(e);

  if (parentDomElement instanceof MergedObject) {
    final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations();
    final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true);

    for (DomElement implementation : implementations) {
      final XmlFile xmlFile = DomUtil.getFile(implementation);
      actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description));
    }
    return actionGroup;
  }

  return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description);
}
项目:tools-idea    文件:DeleteDomElement.java   
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
  final SimpleNode selectedNode = treeView.getTree().getSelectedNode();

  if (selectedNode instanceof BaseDomElementNode) {

    if (selectedNode instanceof DomFileElementNode) {
      e.getPresentation().setVisible(false);
      return;
    }

    final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement();

    final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode) + "?", ApplicationBundle.message("action.remove"),
                                                Messages.getQuestionIcon());
    if (ret == 0) {
    new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {
      protected void run(final Result result) throws Throwable {
        domElement.undefine();
      }
    }.execute();
    }
  }
}
项目:tools-idea    文件:DomElementAnnotationsManagerImpl.java   
@Override
@NotNull
public DomElementsProblemsHolder getProblemHolder(DomElement element) {
  if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER;
  final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(element);

  synchronized (LOCK) {
    final XmlTag tag = fileElement.getRootElement().getXmlTag();
    if (tag != null) {
      final DomElementsProblemsHolder readyHolder = tag.getUserData(DOM_PROBLEM_HOLDER_KEY);
      if (readyHolder != null) {
        return readyHolder;
      }
    }
    return EMPTY_PROBLEMS_HOLDER;
  }
}
项目:tools-idea    文件:DomElementAnnotationsManagerImpl.java   
@NotNull
public DomHighlightStatus getHighlightStatus(final DomElement element) {
  synchronized (LOCK) {
    final DomFileElement<DomElement> root = DomUtil.getFileElement(element);
    if (!isHolderOutdated(root.getFile())) {
      final DomElementsProblemsHolder holder = getProblemHolder(element);
      if (holder instanceof DomElementsProblemsHolderImpl) {
        DomElementsProblemsHolderImpl holderImpl = (DomElementsProblemsHolderImpl)holder;
        final List<DomElementsInspection> suitableInspections = getSuitableDomInspections(root, true);
        final DomElementsInspection mockInspection = getMockInspection(root);
        final boolean annotatorsFinished = mockInspection == null || holderImpl.isInspectionCompleted(mockInspection);
        final boolean inspectionsFinished = areInspectionsFinished(holderImpl, suitableInspections);
        if (annotatorsFinished) {
          if (suitableInspections.isEmpty() || inspectionsFinished) return DomHighlightStatus.INSPECTIONS_FINISHED;
          return DomHighlightStatus.ANNOTATORS_FINISHED;
        }
      }
    }
    return DomHighlightStatus.NONE;
  }

}
项目:tools-idea    文件:DomElementsProblemsHolderImpl.java   
@NotNull
private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) {
  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement);
  if (map != null) {
    return map;
  }

  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>();
  if (domElement == myElement) {
    for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) {
      mergeMaps(problems, listMap);
    }
  } else {
    mergeMaps(problems, myCachedErrors.get(domElement));
    if (DomUtil.hasXml(domElement)) {
      domElement.acceptChildren(new DomElementVisitor() {
        public void visitDomElement(DomElement element) {
          mergeMaps(problems, getProblemsMap(element));
        }
      });
    }
  }

  myCachedChildrenErrors.put(domElement, problems);
  return problems;
}
项目:tools-idea    文件:AbstractDomElementNode.java   
protected boolean shouldBeShown(final Type type) {
  final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY);
  if (type == null || hiders == null || hiders.size() == 0) return true;

  final Class aClass = ReflectionUtil.getRawType(type);

  List<Class> allParents = new ArrayList<Class>();
  for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) {
    if (entry.getKey().isAssignableFrom(aClass)) {
      allParents.add(entry.getKey());
    }
  }
  if (allParents.size() == 0) return false;

  Collections.sort(allParents, INHERITORS_COMPARATOR);

  return hiders.get(allParents.get(0)).booleanValue();

}
项目:tools-idea    文件:AddMavenDependencyQuickFix.java   
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!myRef.isValid()) return;

  MavenProject mavenProject = MavenDomUtil.findContainingProject(file);
  if (mavenProject == null) return;

  final List<MavenId> ids = MavenArtifactSearchDialog.searchForClass(project, getReferenceText());
  if (ids.isEmpty()) return;

  final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile());
  if (model == null) return;

  new WriteCommandAction(project, "Add Maven Dependency", DomUtil.getFile(model)) {
    @Override
    protected void run(Result result) throws Throwable {
      for (MavenId each : ids) {
        MavenDomUtil.createDomDependency(model, null, each);
      }
    }
  }.execute();
}
项目:tools-idea    文件:MavenDomProjectProcessorUtils.java   
@Nullable
public T process(@NotNull MavenDomProjectModel projectDom) {
  MavenDomParent parent = projectDom.getMavenParent();
  MavenParentDesc parentDesc = null;
  if (DomUtil.hasXml(parent)) {
    String parentGroupId = parent.getGroupId().getStringValue();
    String parentArtifactId = parent.getArtifactId().getStringValue();
    String parentVersion = parent.getVersion().getStringValue();
    String parentRelativePath = parent.getRelativePath().getStringValue();
    if (StringUtil.isEmptyOrSpaces(parentRelativePath)) parentRelativePath = "../pom.xml";
    MavenId parentId = new MavenId(parentGroupId, parentArtifactId, parentVersion);
    parentDesc = new MavenParentDesc(parentId, parentRelativePath);
  }

  return process(myManager.getGeneralSettings(), MavenDomUtil.getVirtualFile(projectDom), parentDesc);
}
项目:tools-idea    文件:AntDomMacrodefAttributeReference.java   
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
  final PsiElement element = psiReference.getElement();
  if (element == null) {
    return null;
  }
  final DomElement domElement = DomUtil.getDomElement(element);
  if (domElement == null) {
    return null;
  }
  final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false);
  if (macrodef == null) {
    return null;
  }
  final String name = AntStringResolver.computeString(domElement, psiReference.getCanonicalText());
  for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) {
    if (name.equals(attribute.getName().getStringValue())) {
      final DomTarget target = DomTarget.getTarget(attribute);
      return target != null? PomService.convertToPsi(target) : null;
    }
  }
  return null;
}
项目:consulo-apache-ant    文件:AntDomMacrodefAttributeReference.java   
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
  final PsiElement element = psiReference.getElement();
  if (element == null) {
    return null;
  }
  final DomElement domElement = DomUtil.getDomElement(element);
  if (domElement == null) {
    return null;
  }
  final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false);
  if (macrodef == null) {
    return null;
  }
  final String name = AntStringResolver.computeString(domElement, psiReference.getCanonicalText());
  for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) {
    if (name.equals(attribute.getName().getStringValue())) {
      final DomTarget target = DomTarget.getTarget(attribute);
      return target != null? PomService.convertToPsi(target) : null;
    }
  }
  return null;
}
项目:consulo-javaee    文件:EjbInjectionTargetConverter.java   
@NotNull
protected PsiType getPsiType(final ConvertContext context) {
  final Resource resource;
  final EjbReference ejbReference;
  final ServiceRef serviceReference;
  final PsiClass aClass;
  if ((resource = DomUtil.getParentOfType(context.getInvocationElement(), Resource.class, false)) != null) {
    aClass = resource.getType().getValue();
  }
  else if ((ejbReference = DomUtil.getParentOfType(context.getInvocationElement(), EjbReference.class, false)) != null) {
    aClass = ejbReference.getBeanInterface().getValue();
  }
  else if ((serviceReference = DomUtil.getParentOfType(context.getInvocationElement(), ServiceRef.class, false)) != null) {
    aClass = serviceReference.getServiceInterface().getValue();
  }
  else {
    aClass = null;
  }
  return aClass == null? super.getPsiType(context) : JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass);
}
项目:consulo-javaee    文件:ResAuthConverter.java   
private static boolean is23(final ConvertContext context) {
  final DomElement element = DomUtil.getFileElement(context.getInvocationElement()).getRootElement();
  final XmlTag tag = element.getXmlTag();
  if (tag != null && "web-app".equals(element.getXmlElementName()) && tag.getAttribute("version") == null) {
    XmlDocument document = (XmlDocument)tag.getParent();
    final XmlProlog prolog = document.getProlog();
    if (prolog != null) {
      final XmlDoctype doctype = prolog.getDoctype();
      if (doctype != null) {
        final String uri = doctype.getDtdUri();
        if (uri != null && uri.contains("2_3")) return true;
      }
    }
    return false;
  }
  return true;
}
项目:consulo-javaee    文件:BaseImpl.java   
@Nullable
public Module getModule() {
  if (!isValid()) {
    return null;
  }
  if (getManager().isMockElement(this)) {
    return DomUtil.getFile(this).getUserData(DomManager.MOCK_ELEMENT_MODULE);
  }
  final DomElement root = DomUtil.getRoot(this);
  if (equals(root)) {
    final PsiElement element = getIdentifyingPsiElement();
    return element == null ? null : ModuleUtil.findModuleForPsiElement(element);
  }
  else {
    return root.getModule();
  }
}
项目:consulo-xml    文件:DomElementsToggleAction.java   
public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) {
  myTreeView = treeView;
  myClass = aClass;

  Icon myIcon = ElementPresentationManager.getIcon(myClass);
  if (myIcon == null) {
    myIcon = AllIcons.Nodes.Pointcut;
  }
  this.myIcon = myIcon;

  myText = TypePresentationService.getInstance().getTypePresentableName(myClass);

  if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(BaseDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>());

  if(getHiders().get(myClass) == null) getHiders().put(myClass, true);
}
项目:consulo-xml    文件:AddElementInCollectionAction.java   
protected AnAction createAddingAction(final AnActionEvent e,
                                              final String name,
                                              final Icon icon,
                                              final Type type,
                                              final DomCollectionChildDescription description) {

  final DomElement parentDomElement = getParentDomElement(e);

  if (parentDomElement instanceof MergedObject) {
    final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations();
    final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true);

    for (DomElement implementation : implementations) {
      final XmlFile xmlFile = DomUtil.getFile(implementation);
      actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), IconDescriptorUpdaters.getIcon(xmlFile, 0), e, type, description));
    }
    return actionGroup;
  }

  return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description);
}
项目:consulo-xml    文件:DeleteDomElement.java   
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
  final SimpleNode selectedNode = treeView.getTree().getSelectedNode();

  if (selectedNode instanceof BaseDomElementNode) {

    if (selectedNode instanceof DomFileElementNode) {
      e.getPresentation().setVisible(false);
      return;
    }

    final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement();

    final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode) + "?", ApplicationBundle.message("action.remove"),
                                                Messages.getQuestionIcon());
    if (ret == 0) {
    new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {
      protected void run(final Result result) throws Throwable {
        domElement.undefine();
      }
    }.execute();
    }
  }
}
项目:consulo-xml    文件:DomElementAnnotationsManagerImpl.java   
@Override
@NotNull
public DomElementsProblemsHolder getProblemHolder(DomElement element) {
  if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER;
  final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(element);

  synchronized (LOCK) {
    final XmlTag tag = fileElement.getRootElement().getXmlTag();
    if (tag != null) {
      final DomElementsProblemsHolder readyHolder = tag.getUserData(DOM_PROBLEM_HOLDER_KEY);
      if (readyHolder != null) {
        return readyHolder;
      }
    }
    return EMPTY_PROBLEMS_HOLDER;
  }
}
项目:consulo-xml    文件:DomElementAnnotationsManagerImpl.java   
@NotNull
public DomHighlightStatus getHighlightStatus(final DomElement element) {
  synchronized (LOCK) {
    final DomFileElement<DomElement> root = DomUtil.getFileElement(element);
    if (!isHolderOutdated(root.getFile())) {
      final DomElementsProblemsHolder holder = getProblemHolder(element);
      if (holder instanceof DomElementsProblemsHolderImpl) {
        DomElementsProblemsHolderImpl holderImpl = (DomElementsProblemsHolderImpl)holder;
        final List<DomElementsInspection> suitableInspections = getSuitableDomInspections(root, true);
        final DomElementsInspection mockInspection = getMockInspection(root);
        final boolean annotatorsFinished = mockInspection == null || holderImpl.isInspectionCompleted(mockInspection);
        final boolean inspectionsFinished = areInspectionsFinished(holderImpl, suitableInspections);
        if (annotatorsFinished) {
          if (suitableInspections.isEmpty() || inspectionsFinished) return DomHighlightStatus.INSPECTIONS_FINISHED;
          return DomHighlightStatus.ANNOTATORS_FINISHED;
        }
      }
    }
    return DomHighlightStatus.NONE;
  }

}
项目:consulo-xml    文件:DomElementsProblemsHolderImpl.java   
@NotNull
private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) {
  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement);
  if (map != null) {
    return map;
  }

  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>();
  if (domElement == myElement) {
    for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) {
      mergeMaps(problems, listMap);
    }
  } else {
    mergeMaps(problems, myCachedErrors.get(domElement));
    if (DomUtil.hasXml(domElement)) {
      domElement.acceptChildren(new DomElementVisitor() {
        public void visitDomElement(DomElement element) {
          mergeMaps(problems, getProblemsMap(element));
        }
      });
    }
  }

  myCachedChildrenErrors.put(domElement, problems);
  return problems;
}
项目:consulo-xml    文件:AbstractDomElementNode.java   
protected boolean shouldBeShown(final Type type) {
  final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY);
  if (type == null || hiders == null || hiders.size() == 0) return true;

  final Class aClass = ReflectionUtil.getRawType(type);

  List<Class> allParents = new ArrayList<Class>();
  for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) {
    if (entry.getKey().isAssignableFrom(aClass)) {
      allParents.add(entry.getKey());
    }
  }
  if (allParents.size() == 0) return false;

  Collections.sort(allParents, INHERITORS_COMPARATOR);

  return hiders.get(allParents.get(0)).booleanValue();

}
项目:intellij-ce-playground    文件:XmlSpellcheckingStrategy.java   
@Override
public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) {
  DomElement domElement = DomUtil.getDomElement(element);
  if (domElement != null) {
    if (domElement.getAnnotation(NoSpellchecking.class) != null) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:DeleteDomElement.java   
@Override
public void update(AnActionEvent e, DomModelTreeView treeView) {
  final SimpleNode selectedNode = treeView.getTree().getSelectedNode();

  if (selectedNode instanceof DomFileElementNode) {
    e.getPresentation().setVisible(false);
    return;
  }

  boolean enabled = false;
  if (selectedNode instanceof BaseDomElementNode) {
    final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement();
    if (domElement.isValid() && DomUtil.hasXml(domElement) && !(domElement.getParent() instanceof DomFileElement)) {
      enabled = true;
    }
  }

  e.getPresentation().setEnabled(enabled);


  if (enabled) {
    e.getPresentation().setText(getPresentationText(selectedNode, ApplicationBundle.message("action.remove")));
  }
  else {
    e.getPresentation().setText(ApplicationBundle.message("action.remove"));
  }

  e.getPresentation().setIcon(AllIcons.General.Remove);
}
项目:intellij-ce-playground    文件:DomElementsProblemsHolderImpl.java   
@NotNull
private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) {
  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement);
  if (map != null) {
    return map;
  }

  final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>();
  if (domElement == myElement) {
    for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) {
      mergeMaps(problems, listMap);
    }
  } else {
    mergeMaps(problems, myCachedErrors.get(domElement));
    if (DomUtil.hasXml(domElement)) {
      domElement.acceptChildren(new DomElementVisitor() {
        @Override
        public void visitDomElement(DomElement element) {
          mergeMaps(problems, getProblemsMap(element));
        }
      });
    }
  }

  myCachedChildrenErrors.put(domElement, problems);
  return problems;
}
项目:intellij-ce-playground    文件:DomUIFactoryImpl.java   
@Override
public BackgroundEditorHighlighter createDomHighlighter(final Project project, final PerspectiveFileEditor editor, final DomElement element) {
  return new BackgroundEditorHighlighter() {
    @Override
    @NotNull
    public HighlightingPass[] createPassesForEditor() {
      if (!element.isValid()) return HighlightingPass.EMPTY_ARRAY;

      final XmlFile psiFile = DomUtil.getFile(element);

      final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
      final Document document = psiDocumentManager.getDocument(psiFile);
      if (document == null) return HighlightingPass.EMPTY_ARRAY;

      editor.commit();

      psiDocumentManager.commitAllDocuments();

      GeneralHighlightingPass ghp = new GeneralHighlightingPass(project, psiFile, document, 0, document.getTextLength(),
                                                                true, new ProperTextRange(0, document.getTextLength()), null, new DefaultHighlightInfoProcessor());
      LocalInspectionsPass lip = new LocalInspectionsPass(psiFile, document, 0,
                                                          document.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true,
                                                          new DefaultHighlightInfoProcessor());
      return new HighlightingPass[]{ghp, lip};
    }

    @Override
    @NotNull
    public HighlightingPass[] createPassesForVisibleArea() {
      return createPassesForEditor();
    }
  };

}
项目:intellij-ce-playground    文件:GenericDomValuePattern.java   
protected GenericDomValuePattern(final Class<T> aClass) {
  super(new InitialPatternCondition(aClass) {
    @Override
    public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
      return o instanceof GenericDomValue && aClass.equals(DomUtil.getGenericValueParameter(((GenericDomValue)o).getDomElementType()));
    }

  });
}
项目:intellij-ce-playground    文件:ErrorableTableCellRenderer.java   
public ErrorableTableCellRenderer(@Nullable final T cellValueDomElement, final TableCellRenderer renderer, @NotNull final DomElement rowDomElement) {
  myCellValueDomElement = cellValueDomElement;
  myRenderer = renderer;
  myRowDomElement = rowDomElement;

  myRoot = DomUtil.getRoot(myRowDomElement);
}
项目:intellij-ce-playground    文件:DomUIFactory.java   
public ColumnInfo createColumnInfo(final DomCollectionChildDescription description,
                                   final DomElement element) {
  final String presentableName = description.getCommonPresentableName(element);
  final Class aClass = DomUtil.extractParameterClassFromGenericType(description.getType());
  if (aClass != null) {
    if (Boolean.class.equals(aClass) || boolean.class.equals(aClass)) {
      return new BooleanColumnInfo(presentableName);
    }

    return new GenericValueColumnInfo(presentableName, aClass, createCellEditor(element, aClass));
  }

  return new StringColumnInfo(presentableName);
}
项目:intellij-ce-playground    文件:DomTableView.java   
@Override
protected void wrapValueSetting(@NotNull final DomElement domElement, final Runnable valueSetter) {
  if (domElement.isValid()) {
    new WriteCommandAction(getProject(), DomUtil.getFile(domElement)) {
      @Override
      protected void run(@NotNull final Result result) throws Throwable {
        valueSetter.run();
      }
    }.execute();
    fireChanged();
  }
}