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


Java XmlText类代码示例

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


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

示例1: extractTextFromElement

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Override
public Optional<String> extractTextFromElement(PsiElement element, boolean concatString, boolean stripWhitespace) {
    // maybe its xml then try that
    if (element instanceof XmlAttributeValue) {
        return Optional.ofNullable(((XmlAttributeValue) element).getValue());
    } else if (element instanceof XmlText) {
        return Optional.ofNullable(((XmlText) element).getValue());
    } else if (element instanceof XmlToken) {
        // it may be a token which is a part of an combined attribute
        if (concatString) {
            XmlAttributeValue xml = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class);
            if (xml != null) {
                return Optional.ofNullable(getInnerText(xml.getValue()));
            }
        } else {
            String returnText = element.getText();
            final PsiElement prevSibling = element.getPrevSibling();
            if (prevSibling != null && prevSibling.getText().equalsIgnoreCase("&amp;")) {
                returnText = prevSibling.getText() + returnText;
            }
            return Optional.ofNullable(getInnerText(returnText));
        }
    }
    return Optional.empty();
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:26,代码来源:XmlIdeaUtils.java

示例2: getPsiElement

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Nullable
private PsiElement getPsiElement() {
  if (myDomElement instanceof DomFileElement) {
    return ((DomFileElement)myDomElement).getFile();
  }

  if (myDomElement instanceof GenericAttributeValue) {
    final GenericAttributeValue attributeValue = (GenericAttributeValue)myDomElement;
    final XmlAttributeValue value = attributeValue.getXmlAttributeValue();
    return value != null && StringUtil.isNotEmpty(value.getText()) ? value : attributeValue.getXmlElement();
  }
  final XmlTag tag = myDomElement.getXmlTag();
  if (myDomElement instanceof GenericValue && tag != null) {
    final XmlText[] textElements = tag.getValue().getTextElements();
    if (textElements.length > 0) {
      return textElements[0];
    }
  }

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

示例3: getRangeInElement

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Override
@NotNull
public TextRange getRangeInElement(@NotNull final XmlTag tag) {
  if (tag.getSubTags().length > 0) {
    // Text range in tag with subtags is not supported, return empty range, consider making this function nullable.
    return TextRange.EMPTY_RANGE;
  }

  final XmlTagValue value = tag.getValue();
  final XmlText[] texts = value.getTextElements();
  switch (texts.length) {
    case 0:
      return value.getTextRange().shiftRight(-tag.getTextOffset());
    case 1:
      return getValueRange(texts[0]);
    default:
      return TextRange.EMPTY_RANGE;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:XmlTagManipulator.java

示例4: testInsertAtOffset

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
public void testInsertAtOffset() throws Exception {
  new WriteCommandAction(getProject()) {

    @Override
    protected void run(@NotNull final Result result) throws Throwable {
      String xml = "<root>0123456789</root>";
      XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject())
        .createFileFromText("foo.xml", StdFileTypes.XML, xml, (long)1, true, false);
      //System.out.println(DebugUtil.psiToString(file, false));
      XmlTag root = file.getDocument().getRootTag();
      final XmlText text1 = root.getValue().getTextElements()[0];

      assertFalse(CodeEditUtil.isNodeGenerated(root.getNode()));
      final XmlText text = text1;

      final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5);
      assertNotNull(element);
      assertTrue(element instanceof XmlText);
      assertEquals("01234", element.getText());
      assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText());
    }
  }.execute();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:XmlTextTest.java

示例5: shouldSkipAutopopup

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
  ASTNode node = contextElement.getNode();
  if (node != null && node.getElementType() == XmlTokenType.XML_DATA_CHARACTERS) {
    PsiElement parent = contextElement.getParent();
    if (parent instanceof XmlText || parent instanceof XmlDocument) {
      String contextElementText = contextElement.getText();
      int endOffset = offset - contextElement.getTextRange().getStartOffset();
      String prefix = contextElementText.substring(0, Math.min(contextElementText.length(), endOffset));
      if (!StringUtil.startsWithChar(prefix, '<') && !StringUtil.startsWithChar(prefix, '&')) {
        return ThreeState.YES;
      }
    }
  }
  return ThreeState.UNSURE;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:HtmlTextCompletionConfidence.java

示例6: adjustElement

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Nullable
@Override
public PsiElement adjustElement(Editor editor, int flags, @Nullable PsiElement element, @Nullable PsiElement contextElement) {
  if (element != null) return element;
  if (contextElement == null) return null;

  final PsiElement parent = contextElement.getParent();
  if (parent instanceof XmlText || parent instanceof XmlAttributeValue) {
    final PsiElement gParent = parent.getParent();
    if (gParent == null) return null;
    return TargetElementUtil.getInstance().findTargetElement(editor, flags, gParent.getTextRange().getStartOffset() + 1);
  }
  else if (parent instanceof XmlTag || parent instanceof XmlAttribute) {
    return TargetElementUtil.getInstance().findTargetElement(editor, flags, parent.getTextRange().getStartOffset() + 1);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:XmlTargetElementEvaluator.java

示例7: isInContext

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
public static boolean isInContext(@NotNull PsiElement element) {
  if (PsiTreeUtil.getParentOfType(element, XmlComment.class) != null) {
    return false;
  }
  if (PsiTreeUtil.getParentOfType(element, XmlText.class) != null) {
    return true;
  }
  if (element.getNode().getElementType() == XmlTokenType.XML_START_TAG_START) {
    return true;
  }
  PsiElement parent = element.getParent();
  if (parent instanceof PsiErrorElement) {
    parent = parent.getParent();
  }
  return parent instanceof XmlDocument;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:HtmlTextContextType.java

示例8: checkAndMove

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
private static boolean checkAndMove(Editor editor, Document doc, int offset, PsiElement current) {
  if (current == null) return false;
  if (current.getParent() instanceof XmlText) {
    final int line = doc.getLineNumber(offset);
    final int lineStart = doc.getLineStartOffset(line);
    final int lineEnd = doc.getLineEndOffset(line);

    final CharSequence text = doc.getCharsSequence().subSequence(lineStart, lineEnd);
    if (StringUtil.isEmptyOrSpaces(text) && moveCaret(editor, current, lineEnd)) {
      return true;
    }
  } else if (isEmptyEditPoint(current) && moveCaret(editor, current, current.getTextRange().getStartOffset())) {
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:EmmetEditPointUtil.java

示例9: getLanguagesToInject

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) {
  if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) {
    return;
  }
  XmlTag scriptTag = ((XmlText)host).getParentTag();

  if (scriptTag == null) {
    return;
  }
  final Language language = getScriptLanguageToInject(scriptTag);

  if (language == null || HtmlScriptInjectionBlockerExtension.isInjectionBlocked(scriptTag, language)) {
    return;
  }

  if (LanguageUtil.isInjectableLanguage(language)) {
    registrar
      .startInjecting(language)
      .addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength()))
      .doneInjecting();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:HtmlScriptLanguageInjector.java

示例10: isAvailableOnElementInEditorAndFile

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Override
protected boolean isAvailableOnElementInEditorAndFile(@NotNull PsiElement element, @NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext context) {
  final XmlTag[] tags = getXmlTagsFromExternalContext(context);
  if (tags.length > 0) {
    return AndroidFacet.getInstance(tags[0]) != null && isEnabledForTags(tags);
  }

  final TextRange range = getNonEmptySelectionRange(editor);
  if (range != null) {
    final Pair<PsiElement, PsiElement> psiRange = getExtractableRange(
      file, range.getStartOffset(), range.getEndOffset());
    return psiRange != null && isEnabledForPsiRange(psiRange.getFirst(), psiRange.getSecond());
  }

  if (element == null ||
      AndroidFacet.getInstance(element) == null ||
      PsiTreeUtil.getParentOfType(element, XmlText.class) != null) {
    return false;
  }
  final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
  return tag != null && isEnabledForTags(new XmlTag[]{tag});
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AndroidBaseXmlRefactoringAction.java

示例11: getTextContent

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
/**
 * Returns the text content of a given tag
 */
public static String getTextContent(@NonNull XmlTag tag) {
  // We can't just use tag.getValue().getTrimmedText() here because we need to remove
  // intermediate elements such as <xliff> text:
  // TODO: Make sure I correct handle HTML content for XML items in <string> nodes!
  // For example, for the following string we want to compute "Share with %s":
  // <string name="share">Share with <xliff:g id="application_name" example="Bluetooth">%s</xliff:g></string>
  XmlTag[] subTags = tag.getSubTags();
  XmlText[] textElements = tag.getValue().getTextElements();
  if (subTags.length == 0) {
    if (textElements.length == 1) {
      return getXmlTextValue(textElements[0]);
    } else if (textElements.length == 0) {
      return "";
    }
  }
  StringBuilder sb = new StringBuilder(40);
  appendText(sb, tag);
  return sb.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PsiResourceItem.java

示例12: getLanguagesToInject

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) {
  if (!(host instanceof XmlText)) return;

  final XmlText xmlText = (XmlText)host;

  if (!MavenPluginParamInfo.isSimpleText(xmlText)) return;

  MavenPluginParamInfo.ParamInfoList infoList = MavenPluginParamInfo.getParamInfoList(xmlText);
  for (MavenPluginParamInfo.ParamInfo info : infoList) {
    Language language = info.getLanguage();

    if (language == null) {
      MavenParamLanguageProvider provider = info.getLanguageProvider();
      if (provider != null) {
        language = provider.getLanguage(xmlText, infoList.getDomCfg());
      }
    }

    if (language != null) {
      injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix());
      return;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MavenPluginConfigurationLanguageInjector.java

示例13: getReferencesByElement

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
  final XmlText xmlText = (XmlText)element.getParent();

  if (!MavenPluginParamInfo.isSimpleText(xmlText)) return PsiReference.EMPTY_ARRAY;

  MavenPluginParamInfo.ParamInfoList paramInfos = MavenPluginParamInfo.getParamInfoList(xmlText);
  for (ParamInfo info : paramInfos) {
    MavenParamReferenceProvider providerInstance = info.getProviderInstance();
    if (providerInstance != null) {
      return providerInstance.getReferencesByElement(xmlText, paramInfos.getDomCfg(), context);
    }
  }

  return PsiReference.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:MavenPluginParamReferenceContributor.java

示例14: getLanguage

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@Nullable
@Override
public Language getLanguage(@NotNull XmlText xmlText, @NotNull MavenDomConfiguration configuration) {
  // Parameter 'source' of gmaven-plugin can be a peace of groovy code or file path or URL.

  String text = xmlText.getText();

  if (text.indexOf('\n') >= 0) { // URL or file path can not be multiline so it's a groovy code
    return GroovyLanguage.INSTANCE;
  }
  if (text.indexOf('(') >= 0) { // URL or file path hardly contains '(', but code usually contain '('
    return GroovyLanguage.INSTANCE;
  }

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

示例15: getControllerActionElements

import com.intellij.psi.xml.XmlText; //导入依赖的package包/类
@NotNull
private Collection<PsiElement> getControllerActionElements(@NotNull XmlText xmlText) {
    PsiElement xmlTag = xmlText.getParent();
    if(!(xmlTag instanceof XmlTag)) {
        return Collections.emptyList();
    }

    String controllerName = ShopwareXmlCompletion.getControllerOnScope((XmlTag) xmlTag);
    if (controllerName == null) {
        return Collections.emptyList();
    }

    String value = xmlText.getValue();

    Collection<PsiElement> targets = new HashSet<>();

    ShopwareUtil.collectControllerAction(xmlText.getProject(), controllerName, (method, methodStripped, moduleName, controllerName1) -> {
        if(value.equalsIgnoreCase(methodStripped)) {
            targets.add(method);
        }
    }, "Backend");

    return targets;
}
 
开发者ID:Haehnchen,项目名称:idea-php-shopware-plugin,代码行数:25,代码来源:XmlGoToHandler.java


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