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

项目:hybris-integration-intellij-idea-plugin    文件:TSStructureViewTreeModel.java   
@Override
@NotNull
public StructureViewTreeElement getRoot() {
    XmlFile myFile = getPsiFile();
    final DomFileElement<DomElement> fileElement = DomManager.getDomManager(myFile.getProject()).getFileElement(
        myFile,
        DomElement.class
    );
    return fileElement == null ?
        new XmlFileTreeElement(myFile) :
        new TSStructureTreeElement(
            fileElement.getRootElement().createStableCopy(),
            myDescriptor,
            myNavigationProvider
        );
}
项目:mule-intellij-plugins    文件:MuleConfigUtils.java   
@NotNull
private static List<DomElement> getFlowsInScope(Project project, GlobalSearchScope searchScope) {
    final List<DomElement> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                result.addAll(rootElement.getFlows());
                result.addAll(rootElement.getSubFlows());
            }
        }
    }
    return result;
}
项目:mule-intellij-plugins    文件:MuleConfigUtils.java   
@Nullable
private static XmlTag findGlobalElementInFile(Project project, String elementName, VirtualFile file) {
    final DomManager manager = DomManager.getDomManager(project);
    final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
    if (isMuleFile(xmlFile)) {
        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
        if (fileElement != null) {
            final Mule rootElement = fileElement.getRootElement();
            final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
            for (XmlTag subTag : subTags) {
                if (isGlobalElement(subTag)) {
                    if (elementName.equals(subTag.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE))) {
                        return subTag;
                    }
                }
            }
        }
    }
    return null;
}
项目:mule-intellij-plugins    文件:MuleConfigUtils.java   
@Nullable
private static XmlTag findFlowInFile(Project project, String flowName, VirtualFile file) {
    final DomManager manager = DomManager.getDomManager(project);
    final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
    if (isMuleFile(xmlFile)) {
        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
        if (fileElement != null) {
            final Mule rootElement = fileElement.getRootElement();
            final List<Flow> flows = rootElement.getFlows();
            for (Flow flow : flows) {
                if (flowName.equals(flow.getName().getValue())) {
                    return flow.getXmlTag();
                }
            }
            final List<SubFlow> subFlows = rootElement.getSubFlows();
            for (SubFlow subFlow : subFlows) {
                if (flowName.equals(subFlow.getName().getValue())) {
                    return subFlow.getXmlTag();
                }
            }
        }
    }
    return null;
}
项目:mule-intellij-plugins    文件:MuleConfigUtils.java   
@NotNull
private static List<XmlTag> getGlobalElementsInScope(Project project, GlobalSearchScope searchScope) {
    final List<XmlTag> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
                for (XmlTag subTag : subTags) {
                    if (isGlobalElement(subTag)) {
                        result.add(subTag);
                    }
                }
            }
        }
    }
    return result;
}
项目:mule-intellij-plugins    文件:GlobalConfigsTreeStructure.java   
@Override
protected SimpleNode[] buildChildren() {
    List<SimpleNode> myConfigNodes = new ArrayList<>();

    final DomManager manager = DomManager.getDomManager(myProject);
    final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) myXmlFile, Mule.class);

    if (fileElement != null) {
        final Mule rootElement = fileElement.getRootElement();
        XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

        for (XmlTag nextTag : subTags) {
            MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

            if (muleElementType != null && //This is a global config
                    (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {

                GlobalConfigNode nextConfigNode = new GlobalConfigNode(this, nextTag);
                myConfigNodes.add(nextConfigNode);
            }
        }
    }
    return myConfigNodes.toArray(new SimpleNode[]{});
}
项目:intellij-ce-playground    文件:DomElementAnnotationsManagerImpl.java   
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
  DomElementsProblemsHolderImpl holder;
  final DomElement rootElement = element.getRootElement();
  final XmlTag rootTag = rootElement.getXmlTag();
  if (rootTag == null) return new DomElementsProblemsHolderImpl(element);

  holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
  if (isHolderOutdated(element.getFile()) || holder == null) {
    holder = new DomElementsProblemsHolderImpl(element);
    rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
    final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() {
      @Override
      public Result<Boolean> compute() {
        return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, DomElementAnnotationsManagerImpl.this, ProjectRootManager.getInstance(myProject));
      }
    }, false);
    cachedValue.getValue();
    element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
  }
  return holder;
}
项目: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    文件:DomElementClassIndex.java   
public boolean hasStubElementsOfType(final DomFileElement domFileElement,
                                     final Class<? extends DomElement> clazz) {
  final VirtualFile file = domFileElement.getFile().getVirtualFile();
  if (!(file instanceof VirtualFileWithId)) return false;

  final String clazzName = clazz.getName();
  final int virtualFileId = ((VirtualFileWithId)file).getId();

  CommonProcessors.FindFirstProcessor<? super PsiFile> processor =
    new CommonProcessors.FindFirstProcessor<PsiFile>();
  StubIndex.getInstance().processElements(KEY, clazzName,
                                          domFileElement.getFile().getProject(),
                                          GlobalSearchScope.fileScope(domFileElement.getFile()),
                                          new IdFilter() {
                                            @Override
                                            public boolean containsFileId(int id) {
                                              return id == virtualFileId;
                                            }
                                          },
                                          PsiFile.class, 
                                          processor
  );

  return processor.isFound();
}
项目:intellij-ce-playground    文件:DomNamespaceKeyIndex.java   
public boolean hasStubElementsWithNamespaceKey(final DomFileElement domFileElement, final String namespaceKey) {
  final VirtualFile file = domFileElement.getFile().getVirtualFile();
  if (!(file instanceof VirtualFileWithId)) return false;

  final int virtualFileId = ((VirtualFileWithId)file).getId();
  CommonProcessors.FindFirstProcessor<PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>();
  StubIndex.getInstance().processElements(
    KEY,
    namespaceKey,
    domFileElement.getFile().getProject(),
    GlobalSearchScope.fileScope(domFileElement.getFile()),
    new IdFilter() {
      @Override
      public boolean containsFileId(int id) {
        return id == virtualFileId;
      }
    },
    PsiFile.class, 
    processor
  );
  return processor.isFound();
}
项目:intellij-ce-playground    文件:CachedMultipleDomModelFactory.java   
@Nullable
protected M computeCombinedModel(@NotNull Scope scope) {
  final List<M> models = getAllModels(scope);
  switch (models.size()) {
    case 0:
      return null;
    case 1:
      return models.get(0);
  }
  final Set<XmlFile> configFiles = new LinkedHashSet<XmlFile>();
  final LinkedHashSet<DomFileElement<T>> list = new LinkedHashSet<DomFileElement<T>>(models.size());
  for (M model: models) {
    final Set<XmlFile> files = model.getConfigFiles();
    for (XmlFile file: files) {
      ContainerUtil.addIfNotNull(getDomRoot(file), list);
    }
    configFiles.addAll(files);
  }
  final DomFileElement<T> mergedModel = getModelMerger().mergeModels(DomFileElement.class, list);
  final M firstModel = models.get(0);
  return createCombinedModel(configFiles, mergedModel, firstModel, scope);
}
项目:intellij-ce-playground    文件:MavenModulePsiReference.java   
@NotNull
public Object[] getVariants() {
  List<DomFileElement<MavenDomProjectModel>> files = MavenDomUtil.collectProjectModels(getProject());

  List<Object> result = new ArrayList<Object>();

  for (DomFileElement<MavenDomProjectModel> eachDomFile : files) {
    VirtualFile eachVFile = eachDomFile.getOriginalFile().getVirtualFile();
    if (Comparing.equal(eachVFile, myVirtualFile)) continue;

    PsiFile psiFile = eachDomFile.getFile();
    String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);

    result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
  }

  return result.toArray();
}
项目:intellij-ce-playground    文件:RegisterExtensionFix.java   
private void doFix(Editor editor, final DomFileElement<IdeaPlugin> element) {
  if (myEPCandidates.size() == 1) {
    registerExtension(element, myEPCandidates.get(0));
  }
  else {
    final BaseListPopupStep<ExtensionPointCandidate> popupStep =
      new BaseListPopupStep<ExtensionPointCandidate>("Choose Extension Point", myEPCandidates) {
        @Override
        public PopupStep onChosen(ExtensionPointCandidate selectedValue, boolean finalChoice) {
          registerExtension(element, selectedValue);
          return FINAL_CHOICE;
        }
      };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
  }
}
项目: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    文件:DomElementAnnotationsManagerImpl.java   
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
  DomElementsProblemsHolderImpl holder;
  final DomElement rootElement = element.getRootElement();
  final XmlTag rootTag = rootElement.getXmlTag();
  if (rootTag == null) return new DomElementsProblemsHolderImpl(element);

  holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
  if (isHolderOutdated(element.getFile()) || holder == null) {
    holder = new DomElementsProblemsHolderImpl(element);
    rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
    final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() {
      @Override
      public Result<Boolean> compute() {
        return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myModificationTracker, ProjectRootManager.getInstance(myProject));
      }
    }, false);
    cachedValue.getValue();
    element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
  }
  return holder;
}
项目: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    文件:CachedMultipleDomModelFactory.java   
@Nullable
protected M computeCombinedModel(@NotNull Scope scope) {
  final List<M> models = getAllModels(scope);
  switch (models.size()) {
    case 0:
      return null;
    case 1:
      return models.get(0);
  }
  final Set<XmlFile> configFiles = new LinkedHashSet<XmlFile>();
  final LinkedHashSet<DomFileElement<T>> list = new LinkedHashSet<DomFileElement<T>>(models.size());
  for (M model: models) {
    final Set<XmlFile> files = model.getConfigFiles();
    for (XmlFile file: files) {
      ContainerUtil.addIfNotNull(getDomRoot(file), list);
    }
    configFiles.addAll(files);
  }
  final DomFileElement<T> mergedModel = getModelMerger().mergeModels(DomFileElement.class, list);
  final M firstModel = models.get(0);
  return createCombinedModel(configFiles, mergedModel, firstModel, scope);
}
项目:tools-idea    文件:MavenModulePsiReference.java   
@NotNull
public Object[] getVariants() {
  List<DomFileElement<MavenDomProjectModel>> files = MavenDomUtil.collectProjectModels(getProject());

  List<Object> result = new ArrayList<Object>();

  for (DomFileElement<MavenDomProjectModel> eachDomFile : files) {
    VirtualFile eachVFile = eachDomFile.getOriginalFile().getVirtualFile();
    if (Comparing.equal(eachVFile, myVirtualFile)) continue;

    PsiFile psiFile = eachDomFile.getFile();
    String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);

    result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
  }

  return result.toArray();
}
项目:tools-idea    文件:RegisterExtensionFix.java   
private void doFix(Editor editor, final DomFileElement<IdeaPlugin> element) {
  if (myEPCandidates.size() == 1) {
    registerExtension(element, myEPCandidates.get(0));
  }
  else {
    final BaseListPopupStep<ExtensionPointCandidate> popupStep =
      new BaseListPopupStep<ExtensionPointCandidate>("Choose Extension Point", myEPCandidates) {
        @Override
        public PopupStep onChosen(ExtensionPointCandidate selectedValue, boolean finalChoice) {
          registerExtension(element, selectedValue);
          return FINAL_CHOICE;
        }
      };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
  }
}
项目:ibatis-plugin    文件:SqlMapConfigStructureViewBuilderProvider.java   
/**
 * construct view builder
 *
 * @param xmlFile xml file
 * @return structure view builder
 */
@Nullable public StructureViewBuilder createStructureViewBuilder(@NotNull final XmlFile xmlFile) {
    final DomFileElement fileElement = getFileElement(xmlFile);
    if (fileElement == null) {
        return null;
    }
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        public StructureView createStructureView(final FileEditor fileEditor, final Project project) {
            return new StructureViewComponent(fileEditor, createStructureViewModel(), project);
        }

        @NotNull
        public StructureViewModel createStructureViewModel() {
            return new SqlMapConfigStructureViewTreeModel(xmlFile, fileElement.getRootElement());
        }
    };
}
项目:ibatis-plugin    文件:SqlMapStructureViewBuilderProvider.java   
/**
 * construct view builder
 *
 * @param xmlFile xml file
 * @return structure view builder
 */
@Nullable public StructureViewBuilder createStructureViewBuilder(@NotNull final XmlFile xmlFile) {
    final DomFileElement fileElement = getFileElement(xmlFile);
    if (fileElement == null) {
        return null;
    }
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        public StructureView createStructureView(final FileEditor fileEditor, final Project project) {
            return new StructureViewComponent(fileEditor, createStructureViewModel(), project);
        }

        @NotNull
        public StructureViewModel createStructureViewModel() {
            return new SqlMapStructureViewTreeModel(xmlFile, fileElement.getRootElement());
        }
    };
}
项目:ibatis-plugin    文件:SqlMapSymbolCompletionData.java   
/**
 * get xml tag for code completion
 *
 * @param psiElement psiElement
 * @param psiFile    current file
 * @return xml tag
 */
@Nullable
public static XmlTag getXmlTagForSQLCompletion(PsiElement psiElement, PsiFile psiFile) {
    if (!psiFile.isPhysical()) {
        if (psiElement.getParent().getClass().getName().contains("com.intellij.sql.psi")) {   // text only
              if (!psiElement.isPhysical()) {   //injected sql mode
                  //todo jacky resolve parameter code completion in sql
                  List<Pair<PsiElement,TextRange>> files = InjectedLanguageUtil.getInjectedPsiFiles(psiElement);
                  InjectedLanguageManager manager = InjectedLanguageManager.getInstance(psiElement.getProject());
                  PsiLanguageInjectionHost psiLanguageInjectionHost = manager.getInjectionHost(psiElement);
                  if (psiElement.getContainingFile() instanceof XmlFile) {
                      XmlFile xmlFile = (XmlFile) psiElement.getContainingFile();
                      final DomFileElement fileElement = DomManager.getDomManager(psiFile.getProject()).getFileElement(xmlFile, DomElement.class);
                      if (fileElement != null && fileElement.getRootElement() instanceof SqlMap) {
                          return getParentSentence(psiElement);
                      }
                  }
              }
        }
    }
    return null;
}
项目:ibatis-plugin    文件:IbatisConfigurationModelFactory.java   
public Set<XmlFile> getAllSqlMapConfigurationFile(final Module module) {
    if (CONFIGURATION_FILES.containsKey(module.getName())) return CONFIGURATION_FILES.get(module.getName());
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    PsiManager psiManager = PsiManager.getInstance(module.getProject());
    for (VirtualFile root : rootManager.getSourceRoots()) {
        PsiDirectory sourceDir = psiManager.findDirectory(root);
        if (sourceDir != null) {
            sourceDir.accept(new XmlRecursiveElementVisitor() {
                public void visitXmlFile(XmlFile xmlFile) {
                    final DomFileElement fileElement = DomManager.getDomManager(module.getProject()).getFileElement(xmlFile, DomElement.class);
                    if (fileElement != null && fileElement.getRootElement() instanceof SqlMapConfig) {
                        if (!CONFIGURATION_FILES.containsKey(module.getName())) {   //only one configuration file supported
                            Set<XmlFile> configurationFileSet = new HashSet<XmlFile>();
                            configurationFileSet.add(xmlFile);
                            CONFIGURATION_FILES.put(module.getName(), configurationFileSet);
                        }
                    }
                }
            });
        }
    }
    return CONFIGURATION_FILES.get(module.getName());
}
项目:consulo-apache-ant    文件:AntSupport.java   
@Nullable
public static AntDomProject getAntDomProjectForceAntFile(PsiFile psiFile)
{
    if(psiFile instanceof XmlFile)
    {
        final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
        DomFileElement<AntDomProject> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
        if(fileElement == null)
        {
            ForcedAntFileAttribute.forceAntFile(psiFile.getVirtualFile(), true);
            fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
        }
        return fileElement != null ? fileElement.getRootElement() : null;
    }
    return null;
}
项目:consulo-javaee    文件:JavaeeDescriptor.java   
@Nullable
public <T extends DomElement> T getRoot(@Nullable JavaEEModuleExtension<?> facet, @NotNull Class<T> type)
{
    if(facet != null)
    {
        ConfigFile item = facet.getDescriptorsContainer().getConfigFile(meta);
        if(item != null)
        {
            XmlFile xml = item.getXmlFile();
            if(xml != null)
            {
                DomFileElement<T> element = DomManager.getDomManager(facet.getModule().getProject()).getFileElement(xml, type);
                if(element != null)
                {
                    return element.getRootElement();
                }
            }
        }
    }
    return null;
}
项目:consulo-javaee    文件:JamCommonUtil.java   
@Nullable
public static <T> T getRootElement(final PsiFile file, final Class<T> domClass, final Module module)
{
    if(!(file instanceof XmlFile))
    {
        return null;
    }
    final DomManager domManager = DomManager.getDomManager(file.getProject());
    final DomFileElement<DomElement> element = domManager.getFileElement((XmlFile) file, DomElement.class);
    if(element == null)
    {
        return null;
    }
    final DomElement root = element.getRootElement();
    if(!ReflectionUtil.isAssignable(domClass, root.getClass()))
    {
        return null;
    }
    return (T) root;
}
项目:consulo-javaee    文件:JamCommonUtil.java   
@Nullable
public static Module findModuleForPsiElement(final PsiElement element)
{
    PsiFile psiFile = element.getContainingFile();
    if(psiFile == null)
    {
        final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
        return virtualFile == null ? null : ProjectRootManager.getInstance(element.getProject()).getFileIndex().getModuleForFile(virtualFile);
    }

    psiFile = psiFile.getOriginalFile();
    if(psiFile instanceof XmlFile)
    {
        final DomFileElement<CommonDomModelElement> domFileElement = DomManager.getDomManager(element.getProject()).getFileElement((XmlFile) psiFile, CommonDomModelElement.class);
        if(domFileElement != null)
        {
            Module module = domFileElement.getRootElement().getModule();
            if(module != null)
            {
                return module;
            }
        }
    }

    return ModuleUtilCore.findModuleForPsiElement(psiFile);
}
项目:consulo-xml    文件:DomElementAnnotationsManagerImpl.java   
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
  DomElementsProblemsHolderImpl holder;
  final DomElement rootElement = element.getRootElement();
  final XmlTag rootTag = rootElement.getXmlTag();
  if (rootTag == null) return new DomElementsProblemsHolderImpl(element);

  holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
  if (isHolderOutdated(element.getFile()) || holder == null) {
    holder = new DomElementsProblemsHolderImpl(element);
    rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
    final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() {
      @Override
      public Result<Boolean> compute() {
        return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myModificationTracker, ProjectRootManager.getInstance(myProject));
      }
    }, false);
    cachedValue.getValue();
    element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
  }
  return holder;
}
项目: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    文件:DomElementClassIndex.java   
public boolean hasStubElementsOfType(final DomFileElement domFileElement, final Class<? extends DomElement> clazz)
{
    final VirtualFile file = domFileElement.getFile().getVirtualFile();
    if(!(file instanceof VirtualFileWithId))
    {
        return false;
    }

    final String clazzName = clazz.getName();
    final int virtualFileId = ((VirtualFileWithId) file).getId();

    CommonProcessors.FindFirstProcessor<? super PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>();
    StubIndex.getInstance().process(KEY, clazzName, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile())
            , new IdFilter()
    {
        @Override
        public boolean containsFileId(int id)
        {
            return id == virtualFileId;
        }
    }, processor);

    return processor.isFound();
}
项目:consulo-xml    文件:DomNamespaceKeyIndex.java   
public boolean hasStubElementsWithNamespaceKey(final DomFileElement domFileElement, final String namespaceKey)
{
    final VirtualFile file = domFileElement.getFile().getVirtualFile();
    if(!(file instanceof VirtualFileWithId))
    {
        return false;
    }

    final int virtualFileId = ((VirtualFileWithId) file).getId();
    CommonProcessors.FindFirstProcessor<PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>();
    StubIndex.getInstance().process(KEY, namespaceKey, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile
            ()), new IdFilter()
    {
        @Override
        public boolean containsFileId(int id)
        {
            return id == virtualFileId;
        }
    }, processor);
    return processor.isFound();
}
项目:consulo-xml    文件:CachedMultipleDomModelFactory.java   
@Nullable
protected M computeCombinedModel(@NotNull Scope scope) {
  final List<M> models = getAllModels(scope);
  switch (models.size()) {
    case 0:
      return null;
    case 1:
      return models.get(0);
  }
  final Set<XmlFile> configFiles = new LinkedHashSet<XmlFile>();
  final LinkedHashSet<DomFileElement<T>> list = new LinkedHashSet<DomFileElement<T>>(models.size());
  for (M model: models) {
    final Set<XmlFile> files = model.getConfigFiles();
    for (XmlFile file: files) {
      ContainerUtil.addIfNotNull(getDomRoot(file), list);
    }
    configFiles.addAll(files);
  }
  final DomFileElement<T> mergedModel = getModelMerger().mergeModels(DomFileElement.class, list);
  final M firstModel = models.get(0);
  return createCombinedModel(configFiles, mergedModel, firstModel, scope);
}
项目:hybris-integration-intellij-idea-plugin    文件:TSMetaModelBuilder.java   
@SuppressWarnings("ParameterNameDiffersFromOverriddenParameter")
@Override
public boolean process(final PsiFile psiFile) {
    final VirtualFile vFile = psiFile.getVirtualFile();

    if (vFile == null || myFilesToExclude.contains(vFile)) {
        return true;
    }
    myFiles.add(psiFile);
    final DomFileElement<Items> rootWrapper = myDomManager.getFileElement((XmlFile) psiFile, Items.class);
    final Items items = Optional.ofNullable(rootWrapper).map(DomFileElement::getRootElement).orElse(null);

    if (items != null) {
        items.getItemTypes().getItemTypes().forEach(this::processItemType);
        items.getItemTypes().getTypeGroups().stream()
             .flatMap(tg -> tg.getItemTypes().stream())
             .forEach(this::processItemType);

        items.getEnumTypes().getEnumTypes().forEach(this::processEnumType);
        items.getAtomicTypes().getAtomicTypes().forEach(this::processAtomicType);
        items.getCollectionTypes().getCollectionTypes().forEach(this::processCollectionType);
        items.getRelations().getRelations().forEach(myResult::createReference);
    }

    //continue visiting
    return true;
}
项目:mule-intellij-plugins    文件:GlobalConfigsTreeStructure.java   
@Override
        protected SimpleNode[] buildChildren() {
            List<SimpleNode> myConfigNodes = new ArrayList<>();

            final DomManager manager = DomManager.getDomManager(myProject);

            final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, GlobalSearchScope.projectScope(myProject));

            for (VirtualFile file : files) {

                final PsiFile xmlFile = PsiManager.getInstance(myProject).findFile(file);

                if (xmlFile != null) {
//                    PsiDirectory directory = xmlFile.getParent();
//                    Module module = ModuleUtilCore.findModuleForPsiElement((PsiElement) (directory == null ? xmlFile : directory));

                    if (MuleConfigUtils.isMuleFile(xmlFile)) {
                        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);

                        if (fileElement != null) {
                            final Mule rootElement = fileElement.getRootElement();
                            XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

                            for (XmlTag nextTag : subTags) {
                                MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

                                if (muleElementType != null && //This is a global config file and it has at least one connector
                                        (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {
                                    MuleConfigNode nextConfigNode = new MuleConfigNode(this, xmlFile);
                                    myConfigNodes.add(nextConfigNode);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return myConfigNodes.toArray(new SimpleNode[]{});
        }
项目: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    文件:DomElementAnnotationsManagerImpl.java   
public final List<DomElementProblemDescriptor> appendProblems(@NotNull DomFileElement element, @NotNull DomElementAnnotationHolder annotationHolder, Class<? extends DomElementsInspection> inspectionClass) {
  final DomElementAnnotationHolderImpl holderImpl = (DomElementAnnotationHolderImpl)annotationHolder;
  synchronized (LOCK) {
    final DomElementsProblemsHolderImpl holder = _getOrCreateProblemsHolder(element);
    holder.appendProblems(holderImpl, inspectionClass);
  }
  myDispatcher.getMulticaster().highlightingFinished(element);
  return Collections.unmodifiableList(holderImpl);
}
项目:intellij-ce-playground    文件:DomElementAnnotationsManagerImpl.java   
@Override
@NotNull
public <T extends DomElement> List<DomElementProblemDescriptor> checkFileElement(@NotNull final DomFileElement<T> domFileElement,
                                                                                 @NotNull final DomElementsInspection<T> inspection,
                                                                                 boolean onTheFly) {
  final DomElementsProblemsHolder problemHolder = getProblemHolder(domFileElement);
  if (isHolderUpToDate(domFileElement) && problemHolder.isInspectionCompleted(inspection)) {
    return problemHolder.getAllProblems(inspection);
  }

  final DomElementAnnotationHolder holder = new DomElementAnnotationHolderImpl(onTheFly);
  inspection.checkFileElement(domFileElement, holder);
  return appendProblems(domFileElement, holder, inspection.getClass());
}