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


Java XmlTag.getContainingFile方法代码示例

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


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

示例1: getName

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
@NonNls
public String getName(final PsiElement context) {
  final String name = getDefaultName();
  if (context instanceof XmlTag) {
    XmlTag tag = (XmlTag)context;
    final PsiFile file = tag.getContainingFile();
    DomElement element = myManager.getDomElement(tag);
    if (element == null && tag.getParentTag() != null) {
      element = myManager.getDomElement(tag.getParentTag());
    }
    if (element != null && file instanceof XmlFile && !(myChildrenDescription instanceof MyRootDomChildrenDescription)) {
      final String namespace = DomService.getInstance().getEvaluatedXmlName(element).evaluateChildName(myChildrenDescription.getXmlName()).getNamespace(tag, (XmlFile)file);
      if (!tag.getNamespaceByPrefix("").equals(namespace)) {
        final String s = tag.getPrefixByNamespace(namespace);
        if (StringUtil.isNotEmpty(s)) {
          return s + ":" + name;
        }
      }
    }
  }

  return name;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:DomElementXmlDescriptor.java

示例2: applyFix

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  final XmlTag tag = (XmlTag)descriptor.getPsiElement();
  if (tag == null) return;
  final PsiFile psiFile = tag.getContainingFile();

  if (psiFile == null) return;
  if (!FileModificationService.getInstance().prepareFileForWrite(psiFile)) return;

  try {
    XmlUtil.expandTag(tag);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CheckEmptyTagInspection.java

示例3: getDomElementAndBaseClassQName

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

示例4: getClassLoader

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
public final ClassLoader getClassLoader() {
  ClassLoader loader = myClassLoader;
  if (loader == null) {
    final XmlTag tag = getXmlTag();
    final PsiFile containingFile = tag.getContainingFile();
    final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile);
    if (buildFile != null) {
      loader = buildFile.getClassLoader();
    }
    else {
      AntInstallation antInstallation = getAntInstallation();
      loader = antInstallation.getClassLoader();
    }
    myClassLoader = loader;
  }
  return loader;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AntDomProject.java

示例5: getTargetJdk

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
public final Sdk getTargetJdk() {
  final XmlTag tag = getXmlTag();
  final PsiFile containingFile = tag.getContainingFile();
  final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile);
  if (buildFile != null) {
    String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(buildFile.getAllOptions());
    if (jdkName == null || jdkName.length() == 0) {
      jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(buildFile.getAllOptions());
    }
    if (jdkName != null && jdkName.length() > 0) {
      return ProjectJdkTable.getInstance().findJdk(jdkName);
    }
  }
  return ProjectRootManager.getInstance(tag.getProject()).getProjectSdk();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AntDomProject.java

示例6: getLocalUseScope

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
@Override
public SearchScope getLocalUseScope() {
    final XmlTag tag = getTag();
    if (!tag.isValid()) {
        return getDefaultUseScope();
    }
    final XsltTemplate template = getTemplate();
    if (template == null) {
        return getDefaultUseScope();
    }
    if (template.getName() == null) {
        return getDefaultUseScope();
    }
    final XmlFile file = (XmlFile)tag.getContainingFile();
    if (!XsltIncludeIndex.processBackwardDependencies(file, new CommonProcessors.FindFirstProcessor<XmlFile>())) {
        // processor found something
        return getDefaultUseScope();
    }
    return new LocalSearchScope(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:XsltParameterImpl.java

示例7: getWritableAndroidManifestXml

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
public static XmlTag getWritableAndroidManifestXml(@NotNull Module module) {
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet == null) {
        return null;
    }

    Manifest manifest = androidFacet.getManifest();
    if (manifest == null) {
        return null;
    }

    XmlTag manifestTag = manifest.getXmlTag();
    if (manifestTag == null) {
        return null;
    }

    PsiFile manifestFile = manifestTag.getContainingFile();
    if (manifestFile == null) {
        return null;
    }

    VirtualFile vManifestFile = manifestFile.getVirtualFile();
    if (vManifestFile == null) {
        return null;
    }

    if (!ReadonlyStatusHandler.ensureFilesWritable(manifestFile.getProject(), vManifestFile)) {
        return null;
    }

    return manifestTag;
}
 
开发者ID:apsun,项目名称:XposedPlugin,代码行数:34,代码来源:AndroidXmlUtils.java

示例8: setSelectionInTextEditor

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public void setSelectionInTextEditor(final TextEditor textEditor, final DomElement element) {
  if (element != null && element.isValid()) {
    final XmlTag tag = element.getXmlTag();
    if (tag == null) return;

    final PsiFile file = tag.getContainingFile();
    if (file == null) return;

    final Document document = getDocumentManager().getDocument(file);
    if (document == null || !document.equals(textEditor.getEditor().getDocument())) return;

    textEditor.getEditor().getCaretModel().moveToOffset(tag.getTextOffset());
    textEditor.getEditor().getScrollingModel().scrollToCaret(ScrollType.CENTER);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PerspectiveFileEditor.java

示例9: configureManifest

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void configureManifest(@NotNull AndroidFacet facet, @NotNull IAndroidTarget target) {
  final Manifest manifest = facet.getManifest();
  if (manifest == null) {
    return;
  }

  final XmlTag manifestTag = manifest.getXmlTag();
  if (manifestTag == null) {
    return;
  }

  final PsiFile manifestFile = manifestTag.getContainingFile();
  if (manifestFile == null) {
    return;
  }

  final VirtualFile vManifestFile = manifestFile.getVirtualFile();
  if (vManifestFile == null ||
      !ReadonlyStatusHandler.ensureFilesWritable(manifestFile.getProject(), vManifestFile)) {
    return;
  }
  XmlTag usesSdkTag = manifestTag.createChildTag("uses-sdk", "", null, false);
  if (usesSdkTag != null) {
    usesSdkTag = manifestTag.addSubTag(usesSdkTag, true);
    usesSdkTag.setAttribute("minSdkVersion", SdkConstants.NS_RESOURCES, target.getVersion().getApiString());
  }
  CodeStyleManager.getInstance(manifestFile.getProject()).reformat(manifestFile);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:AndroidModuleBuilder.java

示例10: isUnknownCustomView

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static boolean isUnknownCustomView(XmlTag tag) {
  PsiFile file = tag.getContainingFile();
  if (file != null) {
    ResourceFolderType type = ResourceHelper.getFolderType(file);
    if (type == ResourceFolderType.LAYOUT && tag.getName().indexOf('.') != -1) {
      return true;
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:AndroidElementNotAllowedInspection.java

示例11: apply

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
  final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class, false);
  if (attribute == null) {
    return;
  }

  final XmlTag tag = attribute.getParent();
  if (tag == null) {
    LOG.debug("tag is null");
    return;
  }

  String androidNsPrefix = tag.getPrefixByNamespace(SdkConstants.NS_RESOURCES);

  if (androidNsPrefix == null) {
    final PsiFile file = tag.getContainingFile();
    final XmlNamespaceHelper extension = XmlNamespaceHelper.getHelper(file);

    if (extension == null) {
      LOG.debug("Cannot get XmlNamespaceHelper for file + " + file);
      return;
    }

    if (!(file instanceof XmlFile)) {
      LOG.debug(file + " is not XmlFile");
      return;
    }

    final XmlFile xmlFile = (XmlFile)file;
    final String defaultPrefix = "android";
    extension.insertNamespaceDeclaration(xmlFile, null, Collections.singleton(SdkConstants.NS_RESOURCES), defaultPrefix, null);
    androidNsPrefix = defaultPrefix;
  }
  attribute.setName(androidNsPrefix + ':' + attribute.getLocalName());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:AddMissingPrefixQuickFix.java

示例12: replaceByTagContent

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void replaceByTagContent(Project project, XmlTag tagToReplace, XmlTag tagToInline)
  throws AndroidRefactoringErrorException {
  final ASTNode node = tagToInline.getNode();

  if (node == null) {
    throw new AndroidRefactoringErrorException();
  }
  final ASTNode startTagEnd = XmlChildRole.START_TAG_END_FINDER.findChild(node);
  final ASTNode closingTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(node);

  if (startTagEnd == null || closingTagStart == null) {
    throw new AndroidRefactoringErrorException();
  }
  final int contentStart = startTagEnd.getTextRange().getEndOffset();
  final int contentEnd = closingTagStart.getTextRange().getStartOffset();

  if (contentStart < 0 || contentEnd < 0 || contentStart >= contentEnd) {
    throw new AndroidRefactoringErrorException();
  }
  final PsiFile file = tagToInline.getContainingFile();

  if(file == null) {
    throw new AndroidRefactoringErrorException();
  }
  final String textToInline = file.getText().
    substring(contentStart, contentEnd).trim();
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = documentManager.getDocument(tagToReplace.getContainingFile());

  if (document == null) {
    throw new AndroidRefactoringErrorException();
  }
  final TextRange range = tagToReplace.getTextRange();
  document.replaceString(range.getStartOffset(), range.getEndOffset(), textToInline);
  documentManager.commitDocument(document);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:LayoutUsageData.java

示例13: SetAttributeFix

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public SetAttributeFix(@NotNull Project project, @NotNull XmlTag tag, @NotNull String attribute, @Nullable String namespace,
                       @Nullable String value) {
  super(project, String.format("Set %1$s Attribute", StringUtil.capitalize(attribute)), tag.getContainingFile());
  myTag = tag;
  myNamespace = namespace;
  myAttribute = attribute;
  myValue = value;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:SetAttributeFix.java

示例14: getFragmentClassName

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
private String getFragmentClassName(State sourceState, @Nullable RenderedView namedSourceLeaf) {
  if (namedSourceLeaf == null) {
    return null;
  }
  if (sourceState instanceof ActivityState) {
    ActivityState sourceActivityState = (ActivityState)sourceState;
    XmlTag tag = namedSourceLeaf.tag;
    if (tag == null) {
      return null;
    }
    PsiFile fragmentFile = tag.getContainingFile();
    String resourceFileName = fragmentFile.getName();
    String resourceName = resourceFileName.substring(0, resourceFileName.length() - RESOURCE_SUFFIX_LENGTH);
    for (FragmentEntry fragment : sourceActivityState.getFragments()) {
      Module module = myRenderingParams.facet.getModule();
      String fragmentClassName = fragment.className;
      String resource = Analyser.getXMLFileName(module, fragmentClassName, false);
      if (resource == null) {
        PsiClass listClass = NavigationEditorUtils.getPsiClass(module, "android.app.ListFragment");
        if (listClass == null) {
          LOG.warn("Can't find: android.app.ListFragment");
          continue;
        }
        PsiClass psiClass = NavigationEditorUtils.getPsiClass(module, fragmentClassName);
        if (psiClass != null && (psiClass.isInheritor(listClass, true))) {
          if (tag.getName().equals("ListView")) {
            return fragmentClassName;
          }
        }
      }
      if (resourceName.equals(resource)) {
        return fragmentClassName;
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:NavigationView.java

示例15: addVariants

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void addVariants(final CompletionResultSet result,
                                final XmlAttribute[] attributes,
                                final XmlAttributeDescriptor[] descriptors,
                                XmlAttribute attribute,
                                @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
  final XmlTag tag = attribute.getParent();
  final PsiFile file = tag.getContainingFile();
  final XmlExtension extension = XmlExtension.getExtension(file);
  final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0
                        ? attribute.getNamespacePrefix() + ":"
                        : null;

  CompletionData
    completionData = CompletionUtil.getCompletionDataByElement(attribute, attribute.getContainingFile().getOriginalFile());
  boolean caseSensitive = !(completionData instanceof HtmlCompletionData) || ((HtmlCompletionData)completionData).isCaseSensitive();

  for (XmlAttributeDescriptor descriptor : descriptors) {
    if (isValidVariant(attribute, descriptor, attributes, extension)) {
      String name = descriptor.getName(tag);

      InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

      if (tag instanceof HtmlTag &&
          HtmlUtil.isShortNotationOfBooleanAttributePreferred() &&
          HtmlUtil.isBooleanAttribute(descriptor, tag)) {
        insertHandler = null;
      }

      if (replacementInsertHandler != null) {
        insertHandler = replacementInsertHandler;
      }
      else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
        final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag);

        if (file instanceof XmlFile &&
            namespace != null &&
            namespace.length() > 0 &&
            !name.contains(":") &&
            tag.getPrefixByNamespace(namespace) == null) {
          insertHandler = new XmlAttributeInsertHandler(namespace);
        }
      }
      if (prefix == null || name.startsWith(prefix)) {
        if (prefix != null && name.length() > prefix.length()) {
          name = descriptor.getName(tag).substring(prefix.length());
        }
        LookupElementBuilder element = LookupElementBuilder.create(name);
        if (descriptor instanceof PsiPresentableMetaData) {
          element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
        }
        final int separator = name.indexOf(':');
        if (separator > 0) {
          element = element.withLookupString(name.substring(separator + 1));
        }
        element = element
          .withCaseSensitivity(caseSensitive)
          .withInsertHandler(insertHandler);
        result.addElement(
          descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) :
          HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:XmlAttributeReferenceCompletionProvider.java


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