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

项目:hybris-integration-intellij-idea-plugin    文件:BeansUtils.java   
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
    @NotNull final PsiElement element,
    @NotNull final Class<? extends T> domTagClass,
    @NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
    final DomManager domManager = DomManager.getDomManager(element.getProject());

    if (!(element instanceof XmlElement)) {
        return null;
    }

    final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (xmlAttribute == null) {
        return null;
    }

    final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    DomElement domParentTag = domManager.getDomElement(xmlParentTag);

    return Optional.ofNullable(domParentTag)
                   .map(o -> ObjectUtils.tryCast(o, domTagClass))
                   .map(domGetter)
                   .filter(val -> val == domManager.getDomElement(xmlAttribute))
                   .orElse(null);
}
项目: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[]{});
}
项目:mule-intellij-plugins    文件:WeaveEditor.java   
private List<String> getGlobalDefinitions(VirtualFile file) {

        List<String> globalDefs = new ArrayList<>();

        final DomManager manager = DomManager.getDomManager(project);
        final XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(file);
        final XmlDocument document = xmlFile.getDocument();
        final XmlTag rootTag = document.getRootTag();

        try {
            final XmlTag globalFunctions = rootTag.findFirstSubTag("configuration")
                    .findFirstSubTag("expression-language")
                    .findFirstSubTag("global-functions");
            String nextFunction = globalFunctions.getValue().getText();
            if (nextFunction != null && StringUtils.isNotEmpty(nextFunction)) {
                globalDefs.add(nextFunction);
            }

        } catch (Exception e) {//If the global functions config does not exist, we get NPE - but it's expected :)
            //Do nothing for now
        }
        return globalDefs;
    }
项目:intellij-ce-playground    文件:DomStructureViewBuilder.java   
@Override
@NotNull
public StructureView createStructureView(final FileEditor fileEditor, @NotNull final Project project) {
  return new StructureViewComponent(fileEditor, createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null), project, true) {
    @Override
    public AsyncResult<AbstractTreeNode> expandPathToElement(final Object element) {
      if (element instanceof XmlElement && ((XmlElement)element).isValid()) {
        final XmlElement xmlElement = (XmlElement)element;
        XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
        while (tag != null) {
          final DomElement domElement = DomManager.getDomManager(xmlElement.getProject()).getDomElement(tag);
          if (domElement != null) {
            for (DomElement curElement = domElement; curElement != null; curElement = curElement.getParent()) {
              if (myDescriptor.fun(curElement) == DomService.StructureViewMode.SHOW) {
                return super.expandPathToElement(curElement.getXmlElement());
              }
            }
          }
          tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class, true);
        }

      }
      return super.expandPathToElement(element);
    }
  };
}
项目:intellij-ce-playground    文件:DomMetaDataContributor.java   
@Override
public void contributeMetaData(MetaDataRegistrar registrar) {
  registrar.registerMetaData(new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag)element;
        final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
        if (domElement != null) {
          return domElement.getGenericInfo().getNameDomElement(domElement) != null;
        }
      }
      return false;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return XmlTag.class.isAssignableFrom(hintClass);
    }
  }, DomMetaData.class);
}
项目:intellij-ce-playground    文件:MockDomElementsEditor.java   
private <T extends DomElement> T createMockElement(final Class<T> aClass, final Module module) {
  final Project project = module.getProject();
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      if (myFileEditor.isInitialised()) {
        myContents.reset();
      }
    }
  });
  final DomManager domManager = DomManager.getDomManager(project);
  final T mockElement = domManager.createMockElement(aClass, module, true);
  if (myFileEditor != null) {
    myFileEditor.addWatchedElement(mockElement);
  }
  return mockElement;
}
项目:intellij-ce-playground    文件:AndroidCompletionContributor.java   
private static void addAndroidPrefixElement(PsiElement position, PsiElement parent, CompletionResultSet resultSet) {
  if (position.getText().startsWith("android:")) {
    return;
  }

  final PsiElement gp = parent.getParent();
  if (!(gp instanceof XmlTag)) {
    return;
  }

  final DomElement element = DomManager.getDomManager(gp.getProject()).getDomElement((XmlTag)gp);
  if (!(element instanceof LayoutElement) &&
      !(element instanceof PreferenceElement)) {
    return;
  }

  final String prefix = ((XmlTag)gp).getPrefixByNamespace(SdkConstants.NS_RESOURCES);
  if (prefix == null || prefix.length() < 3) {
    return;
  }
  final LookupElementBuilder e = LookupElementBuilder.create(prefix + ":").withTypeText("[Namespace Prefix]", true);
  resultSet.addElement(PrioritizedLookupElement.withPriority(e, Double.MAX_VALUE));
}
项目:intellij-ce-playground    文件:AndroidXmlSpellcheckingStrategy.java   
private static boolean isAttributeValueContext(@NotNull PsiElement element) {
  if (!(element instanceof XmlAttributeValue)) {
    return false;
  }
  PsiElement parent = element.getParent();
  parent = parent != null ? parent.getParent() : null;

  if (!(parent instanceof XmlTag)) {
    return false;
  }
  final DomElement domElement = DomManager.getDomManager(
    element.getProject()).getDomElement((XmlTag)parent);
  if (domElement instanceof AndroidDomElement) {
    return inEnglish(element);
  }

  return false;
}
项目:intellij-ce-playground    文件:AndroidXmlFormattingModelBuilder.java   
@Nullable
private static ContextSpecificSettingsProviders.Provider getContextSpecificSettings(PsiElement context) {
  final PsiFile file = context.getContainingFile();

  if (!(file instanceof XmlFile) ||
      AndroidFacet.getInstance(file) == null) {
    return null;
  }
  final DomFileDescription<?> description = DomManager.getDomManager(
    context.getProject()).getDomFileDescription((XmlFile)file);
  if (description instanceof LayoutDomFileDescription) {
    return ContextSpecificSettingsProviders.LAYOUT;
  }
  else if (description instanceof ManifestDomFileDescription) {
    return ContextSpecificSettingsProviders.MANIFEST;
  }
  else if (description instanceof ResourcesDomFileDescription ||
           description instanceof DrawableStateListDomFileDescription ||
           description instanceof ColorDomFileDescription) {
    return ContextSpecificSettingsProviders.VALUE_RESOURCE_FILE;
  }
  else if (description instanceof AndroidResourceDomFileDescription) {
    return ContextSpecificSettingsProviders.OTHER;
  }
  return null;
}
项目:intellij-ce-playground    文件:AndroidMissingOnClickHandlerInspection.java   
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
  if (!(file instanceof XmlFile)) {
    return ProblemDescriptor.EMPTY_ARRAY;
  }
  final AndroidFacet facet = AndroidFacet.getInstance(file);

  if (facet == null) {
    return ProblemDescriptor.EMPTY_ARRAY;
  }
  final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile)file);

  if (!(description instanceof LayoutDomFileDescription) &&
      !(description instanceof MenuDomFileDescription)) {
    return ProblemDescriptor.EMPTY_ARRAY;
  }
  final Collection<PsiClass> activities = findRelatedActivities((XmlFile)file, facet, description);
  final MyVisitor visitor = new MyVisitor(manager, isOnTheFly, activities);
  file.accept(visitor);
  return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]);
}
项目:intellij-ce-playground    文件:AndroidDomElementDescriptorProvider.java   
@Nullable
public static Pair<AndroidDomElement, String> getDomElementAndBaseClassQName(@NotNull XmlTag tag) {
  final PsiFile file = tag.getContainingFile();
  if (!(file instanceof XmlFile)) return null;
  Project project = file.getProject();
  if (project.isDefault()) return null;

  final DomManager domManager = DomManager.getDomManager(project);
  if (domManager.getFileElement((XmlFile)file, AndroidDomElement.class) == null) return null;

  final DomElement domElement = domManager.getDomElement(tag);
  if (!(domElement instanceof AndroidDomElement)) {
    return null;
  }

  String className = null;
  if (domElement instanceof LayoutViewElement) {
    className = AndroidUtils.VIEW_CLASS_NAME;
  }
  else if (domElement instanceof XmlResourceElement) {
    className = AndroidXmlResourcesUtil.PREFERENCE_CLASS_NAME;
  }
  return Pair.create((AndroidDomElement)domElement, className);
}
项目:intellij-ce-playground    文件:AndroidExtractAsIncludeAction.java   
@Override
protected boolean isEnabledForPsiRange(@NotNull PsiElement from, @Nullable PsiElement to) {
  final DomManager domManager = DomManager.getDomManager(from.getProject());
  PsiElement e = from;
  boolean containsViewElement = false;

  while (e != null) {
    if (e instanceof XmlTag) {
      final DomElement domElement = domManager.getDomElement((XmlTag)e);

      if (!isSuitableDomElement(domElement)) {
        return false;
      }
      if (domElement instanceof LayoutViewElement) {
        containsViewElement = true;
      }
    }
    if (e == to) {
      break;
    }
    e = e.getNextSibling();
  }
  return containsViewElement;
}
项目:intellij-ce-playground    文件:AndroidFindStyleApplicationsProcessor.java   
private void findAllStyleApplications(final VirtualFile layoutVFile, final List<UsageInfo> usages) {
  ApplicationManager.getApplication().runReadAction(new Runnable() {
    @Override
    public void run() {
      final PsiFile layoutFile = PsiManager.getInstance(myProject).findFile(layoutVFile);

      if (!(layoutFile instanceof XmlFile)) {
        return;
      }
      if (!(DomManager.getDomManager(myProject).getDomFileDescription(
        (XmlFile)layoutFile) instanceof LayoutDomFileDescription)) {
        return;
      }
      collectPossibleStyleApplications(layoutFile, usages);
      PsiManager.getInstance(myProject).dropResolveCaches();
      InjectedLanguageManager.getInstance(myProject).dropFileCaches(layoutFile);
    }
  });
}
项目:intellij-ce-playground    文件:AndroidFindStyleApplicationsAction.java   
@Nullable
static MyStyleData getStyleData(@NotNull XmlTag tag) {
  final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);    

  if (!(element instanceof Style)) {
    return null;
  }
  final Style style = (Style)element;
  final GenericAttributeValue<String> styleNameDomAttr = style.getName();
  final String styleName = styleNameDomAttr.getStringValue();
  final XmlAttributeValue styleNameAttrValue = styleNameDomAttr.getXmlAttributeValue();

  if (styleName == null ||
      styleName.length() == 0 ||
      styleNameAttrValue == null) {
    return null;
  }
  final AndroidFacet facet = AndroidFacet.getInstance(tag);

  if (facet == null) {
    return null;
  }
  return new MyStyleData(style, styleName, facet, styleNameAttrValue);
}
项目:intellij-ce-playground    文件:AndroidInlineUtil.java   
@Nullable
static MyStyleData getInlinableStyleData(@NotNull XmlTag tag) {
  final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);

  if (!(domElement instanceof Style)) {
    return null;
  }
  final Style style = (Style)domElement;
  final XmlAttributeValue nameAttrValue = style.getName().getXmlAttributeValue();

  if (nameAttrValue == null) {
    return null;
  }
  final String styleName = style.getName().getStringValue();

  if (styleName == null || styleName.length() == 0) {
    return null;
  }
  return new MyStyleData(styleName, style, nameAttrValue);
}
项目:intellij-ce-playground    文件:AndroidApplicationPackageRenameProcessor.java   
private static void processAllClassAttrValues(@NotNull XmlFile file,
                                              @NotNull final Processor<Pair<GenericAttributeValue, PsiClass>> processor) {
  final DomManager domManager = DomManager.getDomManager(file.getProject());

  file.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlAttribute(XmlAttribute attribute) {
      final GenericAttributeValue domAttrValue = domManager.getDomElement(attribute);

      if (domAttrValue != null) {
        final Object value = domAttrValue.getValue();

        if (value instanceof PsiClass) {
          processor.process(Pair.create(domAttrValue, (PsiClass)value));
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:RtlSupportProcessor.java   
private List<UsageInfo> getLayoutRefactoringForFile(@NotNull final PsiFile layoutFile, final boolean createV17, final int minSdk) {
  final List<UsageInfo> result = new ArrayList<UsageInfo>();

  if (layoutFile instanceof XmlFile &&
      DomManager.getDomManager(myProject).getDomFileDescription((XmlFile)layoutFile) instanceof LayoutDomFileDescription) {
    layoutFile.accept(new XmlRecursiveElementVisitor() {
      @Override
      public void visitXmlTag(XmlTag tag) {
        super.visitXmlTag(tag);

        List<UsageInfo> usageInfos = getLayoutRefactoringForTag(tag, createV17, minSdk);
        if (usageInfos.isEmpty()) {
          return;
        }
        result.addAll(usageInfos);
      }
    });
  }

  return result;
}
项目:intellij-ce-playground    文件:AndroidFindStyleApplicationsTest.java   
public void testGranular1() throws Exception {
  myFixture.copyFileToProject(BASE_PATH + "1_layout.xml", "res/layout/layout.xml");
  final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + "1.xml", "res/values/styles.xml");
  myFixture.configureFromExistingVirtualFile(f);
  XmlTag tag = PsiTreeUtil.getParentOfType(myFixture.getElementAtCaret(), XmlTag.class);
  AndroidFindStyleApplicationsAction.MyStyleData styleData = AndroidFindStyleApplicationsAction.getStyleData(tag);
  assertNotNull(styleData);
  AndroidFindStyleApplicationsProcessor processor =
    AndroidFindStyleApplicationsAction.createFindStyleApplicationsProcessor(tag, styleData, null);
  processor.configureScope(AndroidFindStyleApplicationsProcessor.MyScope.PROJECT, null);
  Collection<PsiFile> files = processor.collectFilesToProcess();
  assertEquals(1, files.size());
  XmlFile layoutFile = (XmlFile)files.iterator().next();
  assertInstanceOf(DomManager.getDomManager(myFixture.getProject()).getDomFileDescription(
    (XmlFile)layoutFile), LayoutDomFileDescription.class);
  final List<UsageInfo> usages = new ArrayList<UsageInfo>();
  processor.collectPossibleStyleApplications(layoutFile, usages);
  assertEquals(2, usages.size());
}
项目:intellij-ce-playground    文件:MavenDomGutterAnnotator.java   
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
  if (psiElement instanceof XmlTag) {
    final DomElement element = DomManager.getDomManager(psiElement.getProject()).getDomElement((XmlTag)psiElement);
    if (element instanceof MavenDomDependency) {
      if (element.getParentOfType(MavenDomPlugin.class, true) != null) return;

      MavenDomDependency dependency = (MavenDomDependency)element;
      if (isDependencyManagementSection(dependency)) {
        annotateDependencyUsages(dependency, holder);
      }
      else {
        annotateManagedDependency(dependency, holder);
      }
    }
    else if (element instanceof MavenDomParent) {
      annotateMavenDomParent((MavenDomParent)element, holder);
    }
    else if (element instanceof MavenDomProjectModel) {
      annotateMavenDomProjectChildren((MavenDomProjectModel)element, holder);
    }
    else if (element instanceof MavenDomPlugin) {
      annotateMavenDomPlugin((MavenDomPlugin)element, holder);
    }
  }
}
项目:intellij-ce-playground    文件:MavenDomGutterAnnotator.java   
@Override
public String getElementText(XmlTag tag) {
  DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
  if (domElement != null) {
    MavenDomProjectModel model = domElement.getParentOfType(MavenDomProjectModel.class, false);
    if (model != null) {
      MavenProject mavenProject = MavenDomUtil.findProject(model);
      if (mavenProject != null) return mavenProject.getDisplayName();

      String name = model.getName().getStringValue();
      if (!StringUtil.isEmptyOrSpaces(name)) {
        return name;
      }
    }
  }

  return tag.getContainingFile().getName();
}
项目:intellij-ce-playground    文件:MavenArtifactCoordinatesGroupIdConverter.java   
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
  if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) {
    return; // Don't brake the template.
  }

  context.commitDocument();

  XmlFile xmlFile = (XmlFile)context.getFile();

  PsiElement element = xmlFile.findElementAt(context.getStartOffset());
  XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
  if (tag == null) return;

  XmlTag dependencyTag = tag.getParentTag();

  DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(dependencyTag);
  if (!(domElement instanceof MavenDomDependency)) return;

  MavenDomDependency dependency = (MavenDomDependency)domElement;

  String artifactId = dependency.getArtifactId().getStringValue();
  if (StringUtil.isEmpty(artifactId)) return;

  MavenDependencyCompletionUtil.addTypeAndClassifierAndVersion(context, dependency, item.getLookupString(), artifactId);
}
项目:intellij-ce-playground    文件:MavenGroovyPomScriptMemberContributor.java   
@Override
public void processDynamicElements(@NotNull PsiType qualifierType,
                                   PsiClass aClass,
                                   @NotNull PsiScopeProcessor processor,
                                   @NotNull PsiElement place,
                                   @NotNull ResolveState state) {
  PsiElement pomElement = aClass.getContainingFile().getContext();
  if (pomElement == null) return;

  PsiFile pomFile = pomElement.getContainingFile();
  if (!(pomFile instanceof XmlFile)) return;

  DomManager domManager = DomManager.getDomManager(pomElement.getProject());
  if (!(domManager.getDomFileDescription((XmlFile)pomFile) instanceof MavenDomProjectModelDescription)) {
    return;
  }

  DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE);
}
项目: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    文件:DomStructureViewBuilder.java   
@Override
@NotNull
public StructureView createStructureView(final FileEditor fileEditor, final Project project) {
  return new StructureViewComponent(fileEditor, createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null), project) {
    @Override
    public AsyncResult<AbstractTreeNode> expandPathToElement(final Object element) {
      if (element instanceof XmlElement) {
        final XmlElement xmlElement = (XmlElement)element;
        XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
        while (tag != null) {
          final DomElement domElement = DomManager.getDomManager(xmlElement.getProject()).getDomElement(tag);
          if (domElement != null) {
            for (DomElement curElement = domElement; curElement != null; curElement = curElement.getParent()) {
              if (myDescriptor.fun(curElement) == DomService.StructureViewMode.SHOW) {
                return super.expandPathToElement(curElement.getXmlElement());
              }
            }
          }
          tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class, true);
        }

      }
      return super.expandPathToElement(element);
    }
  };
}
项目:tools-idea    文件:DomMetaDataContributor.java   
@Override
public void contributeMetaData(MetaDataRegistrar registrar) {
  registrar.registerMetaData(new ElementFilter() {
    public boolean isAcceptable(Object element, PsiElement context) {
      if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag)element;
        final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
        if (domElement != null) {
          return domElement.getGenericInfo().getNameDomElement(domElement) != null;
        }
      }
      return false;
    }

    public boolean isClassAcceptable(Class hintClass) {
      return XmlTag.class.isAssignableFrom(hintClass);
    }
  }, DomMetaData.class);
}
项目:tools-idea    文件:DomDescriptorProvider.java   
@Nullable
public XmlElementDescriptor getDescriptor(final XmlTag tag) {
  Project project = tag.getProject();
  if (project.isDefault()) return null;
  final DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
  if (domElement != null) {
    final DefinesXml definesXml = domElement.getAnnotation(DefinesXml.class);
    if (definesXml != null) {
      return new DomElementXmlDescriptor(domElement);
    }
    final PsiElement parent = tag.getParent();
    if (parent instanceof XmlTag) {
      final XmlElementDescriptor descriptor = ((XmlTag)parent).getDescriptor();

      if (descriptor instanceof DomElementXmlDescriptor) {
        return descriptor.getElementDescriptor(tag, (XmlTag)parent);
      }
    }
  }

  return null;
}
项目:tools-idea    文件:MockDomElementsEditor.java   
private <T extends DomElement> T createMockElement(final Class<T> aClass, final Module module) {
  final Project project = module.getProject();
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    public void run() {
      if (myFileEditor.isInitialised()) {
        myContents.reset();
      }
    }
  });
  final DomManager domManager = DomManager.getDomManager(project);
  final T mockElement = domManager.createMockElement(aClass, module, true);
  if (myFileEditor != null) {
    myFileEditor.addWatchedElement(mockElement);
  }
  return mockElement;
}
项目:tools-idea    文件:MavenDomGutterAnnotator.java   
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
  if (psiElement instanceof XmlTag) {
    final DomElement element = DomManager.getDomManager(psiElement.getProject()).getDomElement((XmlTag)psiElement);
    if (element instanceof MavenDomDependency) {
      if (element.getParentOfType(MavenDomPlugin.class, true) != null) return;

      MavenDomDependency dependency = (MavenDomDependency)element;
      if (isDependencyManagementSection(dependency)) {
        annotateDependencyUsages(dependency, holder);
      }
      else {
        annotateManagedDependency(dependency, holder);
      }
    }
    else if (element instanceof MavenDomParent) {
      annotateMavenDomParent((MavenDomParent)element, holder);
    }
    else if (element instanceof MavenDomProjectModel) {
      annotateMavenDomProjectChildren((MavenDomProjectModel)element, holder);
    }
    else if (element instanceof MavenDomPlugin) {
      annotateMavenDomPlugin((MavenDomPlugin)element, holder);
    }
  }
}
项目:tools-idea    文件:MavenDomGutterAnnotator.java   
@Override
public String getElementText(XmlTag tag) {
  DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
  if (domElement != null) {
    MavenDomProjectModel model = domElement.getParentOfType(MavenDomProjectModel.class, false);
    if (model != null) {
      MavenProject mavenProject = MavenDomUtil.findProject(model);
      if (mavenProject != null) return mavenProject.getDisplayName();

      String name = model.getName().getStringValue();
      if (!StringUtil.isEmptyOrSpaces(name)) {
        return name;
      }
    }
  }

  return tag.getContainingFile().getName();
}
项目:tools-idea    文件:MavenGroovyPomScriptMemberContributor.java   
@Override
public void processDynamicElements(@NotNull PsiType qualifierType,
                                   PsiClass aClass,
                                   PsiScopeProcessor processor,
                                   PsiElement place,
                                   ResolveState state) {
  PsiElement pomElement = aClass.getContainingFile().getContext();
  if (pomElement == null) return;

  PsiFile pomFile = pomElement.getContainingFile();
  if (!(pomFile instanceof XmlFile)) return;

  DomManager domManager = DomManager.getDomManager(pomElement.getProject());
  if (!(domManager.getDomFileDescription((XmlFile)pomFile) instanceof MavenDomProjectModelDescription)) {
    return;
  }

  DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE);
}
项目:ibatis-plugin    文件:SQLPreviewAction.java   
/**
 * display preview popup menu
 *
 * @param e event
 */
public void actionPerformed(AnActionEvent e) {
    PsiFile psiFile = e.getData(DataKeys.PSI_FILE);
    Editor editor = e.getData(DataKeys.EDITOR);
    if ((psiFile != null && psiFile instanceof XmlFile) && editor != null) {
        PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
        if (psiElement != null) {
            XmlTag xmlTag = SqlMapSymbolCompletionData.getXmlTagForSQLCompletion(psiElement, psiFile);
            if (xmlTag != null) {
                DomElement domElement = DomManager.getDomManager(e.getData(DataKeys.PROJECT)).getDomElement(xmlTag);
                if (domElement != null && domElement instanceof BaseStatement) {
                    BaseStatement baseStatement = (BaseStatement) domElement;
                    PsiClass parameterClass = baseStatement.getParameterClass().getValue();
                    Set<String> parameters = SymbolInSQLInspection.getAllParameterInTag(baseStatement.getXmlTag());
                    String SQLCode = IbatisUtil.getSQLForXmlTag(xmlTag);
                    showPopup(e.getData(DataKeys.PROJECT), e.getData(DataKeys.EDITOR), xmlTag.getAttributeValue("id"), SQLCode.trim(), parameterClass, parameters);
                }
            }
        }
    }

}
项目: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    文件:IbatisUtil.java   
/**
 * get the SQL code in xml tag
 *
 * @param xmlTag xml tag
 * @return SQL in xml tag
 */
@SuppressWarnings({"ConstantConditions"})
@NotNull
public static String getSQLForXmlTag(XmlTag xmlTag) {
    StringBuilder sql = new StringBuilder();
    PsiElement[] children = xmlTag.getChildren();
    for (PsiElement child : children) {
        if (child instanceof XmlTag) {
            XmlTag tag = (XmlTag) child;
            if (tag.getName().equals("include")) {
                XmlAttribute refid = tag.getAttribute("refid");
                if (refid != null && StringUtil.isNotEmpty(refid.getText())) {
                    PsiElement psiElement = refid.getValueElement().getReference().resolve();
                    if (psiElement != null && psiElement instanceof XmlTag) {
                        Sql sqlDom = (Sql) DomManager.getDomManager(psiElement.getProject()).getDomElement((XmlTag) psiElement);
                        if (sqlDom != null)
                            sql.append(" ").append(sqlDom.getSQL());
                    }
                }
            }
        } else if (child instanceof XmlText) {
            sql.append(" ").append(((XmlText) child).getValue());
        }
    }
    return sql.toString();
}
项目: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;
}