use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class MavenPluginConfigurationLanguageInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) {
if (host.isValid() && host.getContainingFile().getLanguage().is(HTMLLanguage.INSTANCE))
return;
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;
}
}
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class DomElementProblemDescriptorImpl method getPsiElement.
@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;
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class MavenVersionCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC)
return;
PsiElement element = parameters.getPosition();
PsiElement xmlText = element.getParent();
if (!(xmlText instanceof XmlText))
return;
PsiElement tagElement = xmlText.getParent();
if (!(tagElement instanceof XmlTag))
return;
XmlTag tag = (XmlTag) tagElement;
Project project = element.getProject();
DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
if (!(domElement instanceof GenericDomValue))
return;
DomElement parent = domElement.getParent();
if (parent instanceof MavenDomArtifactCoordinates && ((GenericDomValue) domElement).getConverter() instanceof MavenArtifactCoordinatesVersionConverter) {
MavenDomArtifactCoordinates coordinates = (MavenDomArtifactCoordinates) parent;
String groupId = coordinates.getGroupId().getStringValue();
String artifactId = coordinates.getArtifactId().getStringValue();
if (StringUtil.isEmptyOrSpaces(artifactId))
return;
CompletionResultSet newResultSet = result.withRelevanceSorter(CompletionService.getCompletionService().emptySorter().weigh(new LookupElementWeigher("mavenVersionWeigher") {
@Nullable
@Override
public Comparable weigh(@NotNull LookupElement element) {
return new NegatingComparable(new MavenVersionComparable(element.getLookupString()));
}
}));
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
Set<String> versions;
if (StringUtil.isEmptyOrSpaces(groupId)) {
if (!(coordinates instanceof MavenDomPlugin))
return;
versions = indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[0], artifactId);
for (int i = 0; i < MavenArtifactUtil.DEFAULT_GROUPS.length; i++) {
versions = Sets.union(versions, indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[i], artifactId));
}
} else {
versions = indicesManager.getVersions(groupId, artifactId);
}
for (String version : versions) {
newResultSet.addElement(LookupElementBuilder.create(version));
}
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.ReleaseVersionId));
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.LatestVersionId));
}
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlWhiteSpaceFormattingStrategy method addWhitespaceToTagBody.
private static void addWhitespaceToTagBody(final ASTNode treePrev, final LeafElement whiteSpaceElement) {
final CharTable charTable = SharedImplUtil.findCharTableByTree(treePrev);
final ASTNode treeParent = treePrev.getTreeParent();
final boolean before;
final XmlText xmlText;
if (treePrev.getElementType() == XmlElementType.XML_TEXT) {
xmlText = (XmlText) treePrev.getPsi();
before = true;
} else if (treePrev.getTreePrev().getElementType() == XmlElementType.XML_TEXT) {
xmlText = (XmlText) treePrev.getTreePrev().getPsi();
before = false;
} else {
xmlText = (XmlText) Factory.createCompositeElement(XmlElementType.XML_TEXT, charTable, treeParent.getPsi().getManager());
CodeEditUtil.setNodeGenerated(xmlText.getNode(), true);
treeParent.addChild(xmlText.getNode(), treePrev);
before = true;
}
final ASTNode node = xmlText.getNode();
assert node != null;
final TreeElement anchorInText = (TreeElement) (before ? node.getFirstChildNode() : node.getLastChildNode());
if (anchorInText == null)
node.addChild(whiteSpaceElement);
else if (anchorInText.getElementType() != XmlTokenType.XML_WHITE_SPACE)
node.addChild(whiteSpaceElement, before ? anchorInText : null);
else {
final String text = before ? whiteSpaceElement.getText() + anchorInText.getText() : anchorInText.getText() + whiteSpaceElement.getText();
node.replaceChild(anchorInText, ASTFactory.whitespace(text));
}
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlVcsSelectionProvider method getSelection.
@Override
public VcsSelection getSelection(VcsContext context) {
final Editor editor = context.getEditor();
if (editor == null)
return null;
PsiElement psiElement = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
if (psiElement == null || !psiElement.isValid()) {
return null;
}
final String actionName;
if (psiElement instanceof XmlTag) {
actionName = VcsBundle.message("action.name.show.history.for.tag");
} else if (psiElement instanceof XmlText) {
actionName = VcsBundle.message("action.name.show.history.for.text");
} else {
return null;
}
TextRange textRange = psiElement.getTextRange();
if (textRange == null) {
return null;
}
VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
if (virtualFile == null) {
return null;
}
if (!virtualFile.isValid()) {
return null;
}
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
return new VcsSelection(document, textRange, actionName);
}
Aggregations