diff options
Diffstat (limited to 'plugins/ant/src/com/intellij/lang')
4 files changed, 45 insertions, 14 deletions
diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntToolWindowFactory.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntToolWindowFactory.java index 4aa217f789bc..02d8f0696e7f 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntToolWindowFactory.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntToolWindowFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,14 @@ import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowFactory; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentManager; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class AntToolWindowFactory implements ToolWindowFactory { @Override - public void createToolWindowContent(Project project, ToolWindow toolWindow) { + public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { AntExplorer explorer = new AntExplorer(project); final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getFactory().createContent(explorer, null, false); diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProperty.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProperty.java index 2ef2ddb9737b..3e60d22711d2 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProperty.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProperty.java @@ -16,11 +16,13 @@ package com.intellij.lang.ant.dom; import com.intellij.lang.properties.IProperty; +import com.intellij.lang.properties.PropertiesImplUtil; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.util.io.FileUtil; import com.intellij.pom.references.PomService; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.PathUtil; import com.intellij.util.containers.HashMap; @@ -131,8 +133,9 @@ public abstract class AntDomProperty extends AntDomClasspathComponent implements } _propertyName = propertyName.substring(prefix.length()); } - if (psiFile instanceof PropertiesFile) { - final IProperty property = ((PropertiesFile)psiFile).findPropertyByKey(_propertyName); + final PropertiesFile pf = toPropertiesFile(psiFile); + if (pf != null) { + final IProperty property = pf.findPropertyByKey(_propertyName); return property != null? property.getPsiElement() : null; } } @@ -185,9 +188,10 @@ public abstract class AntDomProperty extends AntDomClasspathComponent implements else { // name attrib is not specified final PsiFileSystemItem psiFile = getFile().getValue(); if (psiFile != null) { - if (psiFile instanceof PropertiesFile) { + final PropertiesFile file = toPropertiesFile(psiFile); + if (file != null) { result = new HashMap<String, String>(); - for (final IProperty property : ((PropertiesFile)psiFile).getProperties()) { + for (final IProperty property : file.getProperties()) { result.put(property.getUnescapedKey(), property.getUnescapedValue()); } } @@ -212,6 +216,7 @@ public abstract class AntDomProperty extends AntDomClasspathComponent implements final InputStream stream = loader.getResourceAsStream(resource); if (stream != null) { try { + // todo: Remote file can be XmlPropertiesFile final PropertiesFile propFile = (PropertiesFile)CustomAntElementsRegistry.loadContentAsFile(getXmlTag().getProject(), stream, StdFileTypes.PROPERTIES); result = new HashMap<String, String>(); for (final IProperty property : propFile.getProperties()) { @@ -255,4 +260,17 @@ public abstract class AntDomProperty extends AntDomClasspathComponent implements return loader; } + @Nullable + public PropertiesFile getPropertiesFile() { + return toPropertiesFile(getFile().getValue()); + } + + @Nullable + private static PropertiesFile toPropertiesFile(@Nullable final PsiFileSystemItem item) { + if (item instanceof PropertiesFile) { + return (PropertiesFile)item; + } + // Sometimes XmlPropertiesFile is just XmlFile, sao we should ask PropertiesImplUtil about that. + return item instanceof PsiFile? PropertiesImplUtil.getPropertiesFile(((PsiFile)item)) : null; + } } diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java index b17f29ae11ac..838d69af8027 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java @@ -25,7 +25,6 @@ import com.intellij.lang.ant.quickfix.AntCreateTargetFix; import com.intellij.lang.ant.validation.AntInspection; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileSystemItem; import com.intellij.psi.PsiPolyVariantReference; import com.intellij.psi.PsiReference; import com.intellij.psi.xml.XmlElement; @@ -175,9 +174,9 @@ public class AntResolveInspection extends AntInspection { } if (child instanceof AntDomProperty) { final AntDomProperty property = (AntDomProperty)child; - final PsiFileSystemItem file = property.getFile().getValue(); - if (file instanceof PropertiesFile) { - files.add((PropertiesFile)file); + final PropertiesFile file = property.getPropertiesFile(); + if (file != null) { + files.add(file); } } } diff --git a/plugins/ant/src/com/intellij/lang/ant/validation/AntMissingPropertiesFileInspection.java b/plugins/ant/src/com/intellij/lang/ant/validation/AntMissingPropertiesFileInspection.java index b434b1bfc4d4..4e7ac458d6cb 100644 --- a/plugins/ant/src/com/intellij/lang/ant/validation/AntMissingPropertiesFileInspection.java +++ b/plugins/ant/src/com/intellij/lang/ant/validation/AntMissingPropertiesFileInspection.java @@ -18,8 +18,11 @@ package com.intellij.lang.ant.validation; import com.intellij.lang.ant.AntBundle; import com.intellij.lang.ant.dom.AntDomProperty; import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileSystemItem; +import com.intellij.psi.xml.XmlFile; import com.intellij.util.xml.DomElement; +import com.intellij.util.xml.GenericAttributeValue; import com.intellij.util.xml.highlighting.DomElementAnnotationHolder; import com.intellij.util.xml.highlighting.DomHighlightingHelper; import org.jetbrains.annotations.Nls; @@ -45,11 +48,21 @@ public class AntMissingPropertiesFileInspection extends AntInspection { protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) { if (element instanceof AntDomProperty) { final AntDomProperty property = (AntDomProperty)element; - final String fileName = property.getFile().getStringValue(); + final GenericAttributeValue<PsiFileSystemItem> fileValue = property.getFile(); + final String fileName = fileValue.getStringValue(); if (fileName != null) { - final PsiFileSystemItem file = property.getFile().getValue(); - if (!(file instanceof PropertiesFile)) { - holder.createProblem(property.getFile(), AntBundle.message("file.doesnt.exist", fileName)); + final PropertiesFile propertiesFile = property.getPropertiesFile(); + if (propertiesFile == null) { + final PsiFileSystemItem file = fileValue.getValue(); + if (file instanceof XmlFile) { + holder.createProblem(fileValue, AntBundle.message("file.type.xml.not.supported", fileName)); + } + else if (file instanceof PsiFile) { + holder.createProblem(fileValue, AntBundle.message("file.type.not.supported", fileName)); + } + else { + holder.createProblem(fileValue, AntBundle.message("file.doesnt.exist", fileName)); + } } } } |