当前位置: 首页>>代码示例>>Java>>正文


Java XmlFile.findElementAt方法代码示例

本文整理汇总了Java中com.intellij.psi.xml.XmlFile.findElementAt方法的典型用法代码示例。如果您正苦于以下问题:Java XmlFile.findElementAt方法的具体用法?Java XmlFile.findElementAt怎么用?Java XmlFile.findElementAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.xml.XmlFile的用法示例。


在下文中一共展示了XmlFile.findElementAt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInsert

import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:MavenArtifactCoordinatesGroupIdConverter.java

示例2: runXmlFileSchemaValidation

import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
  final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));

  final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
  for (ExternalAnnotator<?, ?> annotator : annotators) {
    processAnnotator(xmlFile, holder, annotator);
  }

  if (!holder.hasAnnotations()) return Collections.emptyMap();

  Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>();
  for (final Annotation annotation : holder) {
    final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
    if (info.getSeverity() == HighlightSeverity.INFORMATION) continue;

    final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
    final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
    if (startElement == null || endElement == null) continue;

    final ProblemDescriptor descriptor =
      myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                                                  false);
    final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR? HighlightDisplayLevel.ERROR: HighlightDisplayLevel.WARNING;
    problemsMap.put(descriptor, level);
  }
  return problemsMap;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:InspectionValidatorWrapper.java

示例3: isEnabledAt

import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
protected boolean isEnabledAt(XmlFile xmlFile, int offset) {
    final PsiElement element = xmlFile.findElementAt(offset);
    if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
        return false;
    }

    final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
    return node != null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ShowXPathAction.java

示例4: handleInsert

import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@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 = item.getLookupString();

  String groupId = dependency.getGroupId().getStringValue();
  if (StringUtil.isEmpty(groupId)) {
    String g = getUniqueGroupIdOrNull(context.getProject(), artifactId);
    if (g != null) {
      dependency.getGroupId().setStringValue(g);
      groupId = g;
    }
    else {
      if (groupId == null) {
        dependency.getGroupId().setStringValue("");
      }

      XmlTag groupIdTag = dependency.getGroupId().getXmlTag();
      context.getEditor().getCaretModel().moveToOffset(groupIdTag.getValue().getTextRange().getStartOffset());

      MavenDependencyCompletionUtil.invokeCompletion(context, CompletionType.SMART);

      return;
    }
  }

  MavenDependencyCompletionUtil.addTypeAndClassifierAndVersion(context, dependency, groupId, artifactId);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:MavenArtifactCoordinatesArtifactIdConverter.java

示例5: findAntTarget

import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@Nullable
private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();

  final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);

  if (project == null || editor == null) {
    return null;
  }
  final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
  if (file == null) {
    return null;
  }

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (!(psiFile instanceof XmlFile)) {
    return null;
  }
  final XmlFile xmlFile = (XmlFile)psiFile;

  final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile);
  if (antFile == null) {
    return null;
  }

  final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset());
  if (element == null) {
    return null;
  }
  final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
  if (xmlTag == null) {
    return null;
  }

  DomElement dom = AntSupport.getAntDomElement(xmlTag);
  while (dom != null && !(dom instanceof AntDomTarget)) {
    dom = dom.getParent();
  }

  final AntDomTarget domTarget = (AntDomTarget)dom;
  if (domTarget == null) {
    return null;
  }
  return Pair.create(antFile, domTarget);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:RunTargetAction.java


注:本文中的com.intellij.psi.xml.XmlFile.findElementAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。