public final AntDomProject getContextAntProject() { final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(getManager().getProject()); final XmlElement xmlElement = getXmlElement(); if (xmlElement == null) { return getAntProject(); } PsiFile containingFile = xmlElement.getContainingFile(); if (containingFile != null) { containingFile = containingFile.getOriginalFile(); } if (!(containingFile instanceof XmlFile)) { return getAntProject(); } final XmlFile contextFile = antConfig.getEffectiveContextFile(((XmlFile)containingFile)); if (contextFile == null) { return getAntProject(); } return AntSupport.getAntDomProject(contextFile); }
private void processFileInclusion(AntDomIncludingDirective directive, final InclusionKind kind) { if (directive.equals(myContextElement)) { stop(); } if (myStopped) { return; } final PsiFileSystemItem item = directive.getFile().getValue(); if (item instanceof PsiFile) { final AntDomProject slaveProject = item instanceof XmlFile ? AntSupport.getAntDomProjectForceAntFile((XmlFile)item) : null; if (slaveProject != null) { myNameContext.pushPrefix(directive, kind, slaveProject); try { slaveProject.accept(this); } finally { myNameContext.popPrefix(); } } } }
@Nullable public TargetResolver.Result fromString(@Nullable @NonNls String s, ConvertContext context) { final AntDomElement element = AntSupport.getInvocationAntDomElement(context); if (element != null && s != null) { final AntDomProject project = element.getAntProject(); AntDomProject projectToSearchFrom; final AntDomAnt antDomAnt = element.getParentOfType(AntDomAnt.class, false); if (antDomAnt != null) { final PsiFileSystemItem antFile = antDomAnt.getAntFilePath().getValue(); projectToSearchFrom = antFile instanceof PsiFile? AntSupport.getAntDomProjectForceAntFile((PsiFile)antFile) : null; } else { projectToSearchFrom = project.getContextAntProject(); } if (projectToSearchFrom == null) { return null; } final TargetResolver.Result result = TargetResolver.resolve(projectToSearchFrom, null, s); result.setRefsString(s); return result; } return null; }
@Nullable private TargetResolver.Result doResolve(@Nullable final String referenceText) { final AntDomElement hostingElement = getHostingAntDomElement(); if (hostingElement == null) { return null; } AntDomProject projectToSearchFrom; AntDomTarget contextTarget; if (hostingElement instanceof AntDomAnt) { final PsiFileSystemItem antFile = ((AntDomAnt)hostingElement).getAntFilePath().getValue(); projectToSearchFrom = antFile instanceof PsiFile ? AntSupport.getAntDomProjectForceAntFile((PsiFile)antFile) : null; contextTarget = null; } else { projectToSearchFrom = hostingElement.getContextAntProject(); contextTarget = hostingElement.getParentOfType(AntDomTarget.class, false); } if (projectToSearchFrom == null) { return null; } return TargetResolver.resolve(projectToSearchFrom, contextTarget, referenceText == null? Collections.<String>emptyList() : Collections.singletonList(referenceText)); }
private void loadDefinitionsFromAntlib(XmlFile xmlFile, String uri, ClassLoader loader, @Nullable AntDomTypeDef typedef, AntDomProject antProject) { final AntDomAntlib antLib = AntSupport.getAntLib(xmlFile); if (antLib != null) { final List<AntDomTypeDef> defs = new ArrayList<AntDomTypeDef>(); defs.addAll(antLib.getTaskdefs()); defs.addAll(antLib.getTypedefs()); if (!defs.isEmpty()) { for (AntDomTypeDef def : defs) { final String tagName = def.getName().getStringValue(); final String className = def.getClassName().getStringValue(); if (tagName != null && className != null) { AntDomNamedElement declaringElement = typedef != null? typedef : def; addCustomDefinition(declaringElement, tagName, uri, ClassProvider.create(className, loader)); } else { defineCustomElementsFromResources(def, uri, antProject, loader); } } } } }
private AntBuildFileBase addBuildFileImpl(final VirtualFile file) throws AntNoFileException { PsiFile xmlFile = myPsiManager.findFile(file); if (!(xmlFile instanceof XmlFile)) { throw new AntNoFileException("the file is not an xml file", file); } AntSupport.markFileAsAntFile(file, xmlFile.getProject(), true); if (!AntDomFileDescription.isAntFile(((XmlFile)xmlFile))) { throw new AntNoFileException("the file is not recognized as an ANT file", file); } final AntBuildFileImpl buildFile = new AntBuildFileImpl((XmlFile)xmlFile, this); synchronized (myBuildFiles) { myBuildFilesArray = null; myBuildFiles.add(buildFile); } return buildFile; }
public AntDomElement fromString(@Nullable @NonNls String s, ConvertContext context) { if (s != null) { final AntDomElement element = AntSupport.getInvocationAntDomElement(context); if (element != null) { return findElementById(element.getContextAntProject(), s, CustomAntElementsRegistry.ourIsBuildingClasspathForCustomTagLoading.get()); } } return null; }
private void processInclude(AntDomIncludingDirective directive) { final PsiFileSystemItem item = directive.getFile().getValue(); if (item instanceof PsiFile) { final AntDomProject slaveProject = AntSupport.getAntDomProject((PsiFile)item); if (slaveProject != null) { slaveProject.accept(this); } } }
@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<AntDomElement>(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; }
private void removeBuildFileImpl(AntBuildFile buildFile) { final XmlFile antFile = buildFile.getAntFile(); if (antFile != null) { AntSupport.markFileAsAntFile(antFile.getOriginalFile().getVirtualFile(), antFile.getProject(), false); } synchronized (myBuildFiles) { myBuildFilesArray = null; myBuildFiles.remove(buildFile); } myModelToBuildFileMap.remove(buildFile); myEventDispatcher.getMulticaster().buildFileRemoved(buildFile); }
@Nullable private static String getAdditionalDocumentation(PsiElement elem) { final XmlTag xmlTag = PsiTreeUtil.getParentOfType(elem, XmlTag.class); if (xmlTag == null) { return null; } final AntDomElement antElement = AntSupport.getAntDomElement(xmlTag); if (antElement instanceof AntFilesProvider) { final List<File> list = ((AntFilesProvider)antElement).getFiles(new HashSet<AntFilesProvider>()); if (list.size() > 0) { final @NonNls StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { final XmlTag tag = antElement.getXmlTag(); if (tag != null) { builder.append("<b>"); builder.append(tag.getName()); builder.append(":</b>"); } for (File file : list) { if (builder.length() > 0) { builder.append("<br>"); } builder.append(file.getPath()); } return builder.toString(); } finally { StringBuilderSpinAllocator.dispose(builder); } } } return null; }
private static void checkReferences(final XmlElement xmlElement, final @NonNls DomElementAnnotationHolder holder, DomElement domElement) { if (xmlElement == null) { return; } Set<PsiReference> processed = null; Collection<PropertiesFile> propertyFiles = null; // to be initialized lazily for (final PsiReference ref : xmlElement.getReferences()) { if (!(ref instanceof AntDomReference)) { continue; } final AntDomReference antDomRef = (AntDomReference)ref; if (antDomRef.shouldBeSkippedByAnnotator()) { continue; } if (processed != null && processed.contains(ref)) { continue; } if (!isResolvable(ref)) { final List<LocalQuickFix> quickFixList = new SmartList<LocalQuickFix>(); quickFixList.add(new AntChangeContextLocalFix()); if (ref instanceof AntDomPropertyReference) { final String canonicalText = ref.getCanonicalText(); quickFixList.add(new AntCreatePropertyFix(canonicalText, null)); final PsiFile containingFile = xmlElement.getContainingFile(); if (containingFile != null) { if (propertyFiles == null) { propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement); } for (PropertiesFile propertyFile : propertyFiles) { quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile)); } } } else if (ref instanceof AntDomTargetReference) { quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText())); } holder.createProblem( domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])) ); if (ref instanceof AntDomFileReference) { if (processed == null) { processed = new HashSet<PsiReference>(); } ContainerUtil.addAll(processed, ((AntDomFileReference)ref).getFileReferenceSet().getAllReferences()); } } } }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }
public AntDomProject getAntProject() { return AntSupport.getAntDomProject(getBuildFile().getAntFile()); }
@Nullable private static VirtualFile getHelpFile(final PsiElement element) { final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } final AntDomElement antElement = AntSupport.getAntDomElement(xmlTag); if (antElement == null) { return null; } final AntDomProject antProject = antElement.getAntProject(); if (antProject == null) { return null; } final AntInstallation installation = antProject.getAntInstallation(); if (installation == null) { return null; // not configured properly and bundled installation missing } final String antHomeDir = AntInstallation.HOME_DIR.get(installation.getProperties()); if (antHomeDir == null) { return null; } @NonNls String path = antHomeDir + "/docs/manual"; String url; if (new File(path).exists()) { url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path)); } else { path = antHomeDir + "/docs.zip"; if (new File(path).exists()) { url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path) + JarFileSystem.JAR_SEPARATOR + "docs/manual"); } else { return null; } } final VirtualFile documentationRoot = VirtualFileManager.getInstance().findFileByUrl(url); if (documentationRoot == null) { return null; } return getHelpFile(antElement, documentationRoot); }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }