use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class MavenSourceDirectoryConverter method isSoft.
@Override
public boolean isSoft(@NotNull DomElement element) {
DomElement buildElement = element.getParent();
if (!(buildElement instanceof MavenDomBuild)) {
return false;
}
DomElement mavenProject = buildElement.getParent();
if (!(mavenProject instanceof MavenDomProjectModel)) {
return false;
}
return "pom".equals(((MavenDomProjectModel) mavenProject).getPackaging().getStringValue());
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class MavenProjectConstantListConverter method getValues.
protected Collection<String> getValues(@NotNull ConvertContext context) {
DomElement element = context.getInvocationElement();
MavenProject project = MavenDomUtil.findContainingProject(element);
if (project == null)
return Collections.emptyList();
return getValues(context, project);
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class ChooseFileIntentionAction method getDependency.
@Nullable
private static MavenDomDependency getDependency(PsiFile file, Editor editor) {
PsiElement el = PsiUtilCore.getElementAtOffset(file, editor.getCaretModel().getOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(el, XmlTag.class, false);
if (tag == null)
return null;
DomElement dom = DomManager.getDomManager(el.getProject()).getDomElement(tag);
if (dom == null)
return null;
return dom.getParentOfType(MavenDomDependency.class, false);
}
use of com.intellij.util.xml.DomElement 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.util.xml.DomElement in project intellij-community by JetBrains.
the class AntDomDocumentationProvider method getQuickNavigateInfo.
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
// todo!
if (element instanceof PomTargetPsiElement) {
final PomTarget pomTarget = ((PomTargetPsiElement) element).getTarget();
if (pomTarget instanceof DomTarget) {
final DomElement domElement = ((DomTarget) pomTarget).getDomElement();
if (domElement instanceof AntDomTarget) {
final AntDomTarget antTarget = (AntDomTarget) domElement;
final String description = antTarget.getDescription().getRawText();
if (description != null && description.length() > 0) {
final String targetName = antTarget.getName().getRawText();
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
builder.append("Target");
if (targetName != null) {
builder.append(" \"").append(targetName).append("\"");
}
final XmlElement xmlElement = antTarget.getXmlElement();
if (xmlElement != null) {
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
final String fileName = containingFile.getName();
builder.append(" [").append(fileName).append("]");
}
}
return builder.append(" ").append(description).toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
} else if (pomTarget instanceof DomChildrenDescription) {
final DomChildrenDescription description = (DomChildrenDescription) pomTarget;
Type type = null;
try {
type = description.getType();
} catch (UnsupportedOperationException e) {
LOG.info(e);
}
if (type instanceof Class && AntDomElement.class.isAssignableFrom(((Class) type))) {
final String elemName = description.getName();
if (elemName != null) {
final AntDomElement.Role role = description.getUserData(AntDomElement.ROLE);
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
if (role == AntDomElement.Role.TASK) {
builder.append("Task ");
} else if (role == AntDomElement.Role.DATA_TYPE) {
builder.append("Data structure ");
}
builder.append(elemName);
return builder.toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
}
}
return null;
}
Aggregations