use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class AntBuildTargetImpl method findTask.
@Nullable
public BuildTask findTask(final String taskName) {
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
final AntDomProject domProject = AntSupport.getAntDomProject(psiFile);
if (domProject != null) {
final AntDomTarget antTarget = domProject.findDeclaredTarget(myName);
if (antTarget != null) {
final Ref<AntDomElement> result = new Ref<>(null);
antTarget.accept(new AntDomRecursiveVisitor() {
public void visitAntDomElement(AntDomElement element) {
if (result.get() != null) {
return;
}
if (element.isTask() && taskName.equals(element.getXmlElementName())) {
result.set(element);
return;
}
super.visitAntDomElement(element);
}
});
final AntDomElement task = result.get();
if (task != null) {
return new BuildTask(this, task);
}
}
}
return null;
}
use of com.intellij.lang.ant.dom.AntDomTarget 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;
}
use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class RunTargetAction method update.
@Override
public void update(AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
Pair<AntBuildFileBase, AntDomTarget> antTarget = findAntTarget(e);
if (antTarget == null) {
presentation.setEnabled(false);
presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", ""));
} else {
presentation.setEnabled(true);
presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", "'" + antTarget.second.getName().getValue() + "'"));
}
}
use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class AntCreatePropertyFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile containingFile = psiElement.getContainingFile();
final FileModificationService modificationService = FileModificationService.getInstance();
Navigatable result = null;
if (myPropFile != null) {
final VirtualFile vFile = myPropFile.getVirtualFile();
boolean canModify = true;
if (myPropFile instanceof PsiFile) {
canModify = modificationService.prepareFileForWrite((PsiFile) myPropFile);
} else if (vFile != null) {
canModify = modificationService.prepareVirtualFilesForWrite(project, Collections.singleton(vFile));
}
if (canModify) {
final IProperty generatedProperty = myPropFile.addProperty(myCanonicalText, "");
result = vFile != null ? new OpenFileDescriptor(project, vFile, generatedProperty.getPsiElement().getTextRange().getEndOffset()) : generatedProperty;
}
} else {
if (containingFile instanceof XmlFile) {
final XmlFile xmlFile = (XmlFile) containingFile;
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag != null && modificationService.prepareFileForWrite(xmlFile)) {
final XmlTag propTag = rootTag.createChildTag(PROPERTY, rootTag.getNamespace(), null, false);
propTag.setAttribute(NAME_ATTR, myCanonicalText);
propTag.setAttribute(VALUE_ATTR, "");
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
PsiElement generated;
if (contextElement == null) {
generated = rootTag.addSubTag(propTag, true);
} else {
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
final XmlTag tag = anchor.getXmlTag();
if (!rootTag.equals(tag)) {
generated = tag.getParent().addBefore(propTag, tag);
} else {
generated = rootTag.addSubTag(propTag, true);
}
}
if (generated instanceof XmlTag) {
final XmlAttribute valueAttrib = ((XmlTag) generated).getAttribute(VALUE_ATTR);
if (valueAttrib != null) {
final XmlAttributeValue valueElement = valueAttrib.getValueElement();
if (valueElement instanceof Navigatable) {
result = (Navigatable) valueElement;
}
}
}
if (result == null && generated instanceof Navigatable) {
result = (Navigatable) generated;
}
}
}
}
if (result != null) {
result.navigate(true);
}
}
use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class AntDuplicateTargetsInspection method checkDomElement.
protected void checkDomElement(DomElement element, final DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
if (element instanceof AntDomProject) {
final AntDomProject project = (AntDomProject) element;
TargetResolver.validateDuplicateTargets(project.getContextAntProject(), new TargetResolver.TargetSink() {
public void duplicateTargetDetected(AntDomTarget existingTarget, AntDomTarget duplicatingTarget, String targetEffectiveName) {
final AntDomProject existingTargetProj = existingTarget.getAntProject();
final AntDomProject duplucatingTargetProj = duplicatingTarget.getAntProject();
final boolean isFromDifferentFiles = !Comparing.equal(existingTargetProj, duplucatingTargetProj);
if (project.equals(existingTargetProj)) {
final String duplicatedMessage = isFromDifferentFiles ? AntBundle.message("target.is.duplicated.in.imported.file", targetEffectiveName, duplucatingTargetProj != null ? duplucatingTargetProj.getName() : "") : AntBundle.message("target.is.duplicated", targetEffectiveName);
holder.createProblem(existingTarget.getName(), duplicatedMessage);
}
if (project.equals(duplucatingTargetProj)) {
final String duplicatedMessage = isFromDifferentFiles ? AntBundle.message("target.is.duplicated.in.imported.file", targetEffectiveName, existingTargetProj != null ? existingTargetProj.getName() : "") : AntBundle.message("target.is.duplicated", targetEffectiveName);
holder.createProblem(duplicatingTarget.getName(), duplicatedMessage);
}
}
});
}
}
Aggregations