diff --git a/plugins/ant/src/META-INF/plugin.xml b/plugins/ant/src/META-INF/plugin.xml index 3b0ba93c082f..e2019fee9644 100644 --- a/plugins/ant/src/META-INF/plugin.xml +++ b/plugins/ant/src/META-INF/plugin.xml @@ -24,20 +24,14 @@ - - - - - + + - - - diff --git a/plugins/ant/src/com/intellij/lang/ant/AntDeclarationRangeHandler.java b/plugins/ant/src/com/intellij/lang/ant/AntDeclarationRangeHandler.java deleted file mode 100644 index fdb6ef25d23d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntDeclarationRangeHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.codeInsight.hint.DeclarationRangeHandler; -import com.intellij.codeInsight.hint.DeclarationRangeUtil; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; - -/** - * @author yole - */ -public class AntDeclarationRangeHandler implements DeclarationRangeHandler { - @NotNull - public TextRange getDeclarationRange(@NotNull final PsiElement container) { - AntStructuredElement element = (AntStructuredElement) container; - return DeclarationRangeUtil.getDeclarationRange(element.getSourceElement()); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/AntDefaultNSProvider.java b/plugins/ant/src/com/intellij/lang/ant/AntDefaultNSProvider.java deleted file mode 100644 index ac84dcb20a9d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntDefaultNSProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.lang.ant.config.AntConfigurationBase; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlFileNSInfoProvider; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -/** - * @author Maxim.Mossienko, lvo - */ -public class AntDefaultNSProvider implements XmlFileNSInfoProvider { - @NonNls - private static final String ANT_URI = "http://ant.apache.org/schema.xsd"; // XmlUtil.ANT_URI - private static final String[][] myNamespaces = new String[][]{new String[]{"", ANT_URI}}; - - // nsPrefix, namespaceId - public String[][] getDefaultNamespaces(@NotNull XmlFile xmlFile) { - if (AntConfigurationBase.getInstance(xmlFile.getProject()).getAntBuildFile(xmlFile) != null) { - return myNamespaces; - } - final XmlDocument document = xmlFile.getDocument(); - if (document != null) { - final XmlTag tag = document.getRootTag(); - if (tag != null && AntFileImpl.PROJECT_TAG.equals(tag.getName()) && tag.getContext() instanceof XmlDocument) { - if (tag.getAttributeValue(AntFileImpl.DEFAULT_ATTR) != null) { - return myNamespaces; - } - final VirtualFile file = xmlFile.getVirtualFile(); - if (file != null && ForcedAntFileAttribute.isAntFile(file)) { - return myNamespaces; - } - } - } - return null; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntFilesProvider.java b/plugins/ant/src/com/intellij/lang/ant/AntFilesProvider.java similarity index 96% rename from plugins/ant/src/com/intellij/lang/ant/psi/AntFilesProvider.java rename to plugins/ant/src/com/intellij/lang/ant/AntFilesProvider.java index 6a8df0ee3310..470599c12e84 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntFilesProvider.java +++ b/plugins/ant/src/com/intellij/lang/ant/AntFilesProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lang.ant.psi; +package com.intellij.lang.ant; import org.jetbrains.annotations.NotNull; diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportsIndex.java b/plugins/ant/src/com/intellij/lang/ant/AntImportsIndex.java similarity index 98% rename from plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportsIndex.java rename to plugins/ant/src/com/intellij/lang/ant/AntImportsIndex.java index a466ef4bf23b..9b94d9fb34d0 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportsIndex.java +++ b/plugins/ant/src/com/intellij/lang/ant/AntImportsIndex.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lang.ant.psi.impl; +package com.intellij.lang.ant; import com.intellij.ide.highlighter.XmlFileType; import com.intellij.openapi.vfs.VirtualFile; diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntIntrospector.java b/plugins/ant/src/com/intellij/lang/ant/AntIntrospector.java similarity index 98% rename from plugins/ant/src/com/intellij/lang/ant/psi/impl/AntIntrospector.java rename to plugins/ant/src/com/intellij/lang/ant/AntIntrospector.java index 24507476882e..234a734b08ec 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntIntrospector.java +++ b/plugins/ant/src/com/intellij/lang/ant/AntIntrospector.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lang.ant.psi.impl; +package com.intellij.lang.ant; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.Alarm; @@ -32,7 +32,7 @@ import java.util.*; * Date: Mar 22, 2007 */ public final class AntIntrospector { - private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.psi.impl.AntIntrospector"); + private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.AntIntrospector"); private final Object myHelper; //private static final ObjectCache> ourCache = new ObjectCache>(300); private static final HashMap ourCache = new HashMap(); diff --git a/plugins/ant/src/com/intellij/lang/ant/AntLanguageExtension.java b/plugins/ant/src/com/intellij/lang/ant/AntLanguageExtension.java deleted file mode 100644 index 4c3600308c3e..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntLanguageExtension.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.lang.Language; -import com.intellij.lang.LanguageFilter; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; - -public class AntLanguageExtension implements LanguageFilter { - - public boolean isRelevantForFile(final PsiFile psi) { - if (psi instanceof XmlFile) { - if (isAntFile((XmlFile)psi)) return true; - } - return false; - } - - public static boolean isAntFile(final XmlFile xmlFile) { - final XmlDocument document = xmlFile.getDocument(); - if (document != null) { - final XmlTag tag = document.getRootTag(); - if (tag != null && AntFileImpl.PROJECT_TAG.equals(tag.getName()) && tag.getContext() instanceof XmlDocument) { - if (tag.getAttributeValue(AntFileImpl.DEFAULT_ATTR) != null) { - return true; - } - VirtualFile vFile = xmlFile.getOriginalFile().getVirtualFile(); - if (vFile != null && ForcedAntFileAttribute.isAntFile(vFile)) { - return true; - } - } - } - return false; - } - - public Language getLanguage() { - return AntSupport.getLanguage(); - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/AntParserDefinition.java b/plugins/ant/src/com/intellij/lang/ant/AntParserDefinition.java deleted file mode 100644 index 4d9738d21793..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntParserDefinition.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.lang.*; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.lexer.Lexer; -import com.intellij.openapi.project.Project; -import com.intellij.psi.FileViewProvider; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.tree.IFileElementType; -import com.intellij.psi.tree.TokenSet; -import org.jetbrains.annotations.NotNull; - -public class AntParserDefinition implements ParserDefinition { - - private final ParserDefinition myXmlParserDef; - - public AntParserDefinition() { - myXmlParserDef = LanguageParserDefinitions.INSTANCE.forLanguage(StdLanguages.XML); - } - - @NotNull - public Lexer createLexer(Project project) { - return myXmlParserDef.createLexer(project); - } - - @NotNull - public PsiParser createParser(Project project) { - return myXmlParserDef.createParser(project); - } - - public IFileElementType getFileNodeType() { - return myXmlParserDef.getFileNodeType(); - } - - @NotNull - public TokenSet getWhitespaceTokens() { - return myXmlParserDef.getWhitespaceTokens(); - } - - @NotNull - public TokenSet getCommentTokens() { - return myXmlParserDef.getCommentTokens(); - } - - @NotNull - public TokenSet getStringLiteralElements() { - return TokenSet.EMPTY; - } - - @NotNull - public PsiElement createElement(ASTNode node) { - return myXmlParserDef.createElement(node); - } - - public PsiFile createFile(FileViewProvider viewProvider) { - return new AntFileImpl(viewProvider); - } - - public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { - return SpaceRequirements.MAY; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/AntPropertyRefSelectioner.java b/plugins/ant/src/com/intellij/lang/ant/AntPropertyRefSelectioner.java deleted file mode 100644 index 1ab36d62b005..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntPropertyRefSelectioner.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.impl.reference.AntPropertyReference; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * @author Eugene Zhuravlev - * Date: Sep 14, 2007 - */ -public class AntPropertyRefSelectioner implements ExtendWordSelectionHandler { - public boolean canSelect(final PsiElement e) { - return getRangesToSelect(e).size() > 0; - } - - public List select(final PsiElement e, final CharSequence editorText, final int cursorOffset, final Editor editor) { - List rangesToSelect = getRangesToSelect(e); - for (Iterator it = rangesToSelect.iterator(); it.hasNext();) { - final TextRange range = (TextRange)it.next(); - if (!range.contains(cursorOffset)) { - it.remove(); - } - } - return rangesToSelect; - } - - @NotNull - private static List getRangesToSelect(PsiElement e) { - final PsiFile containingFile = e.getContainingFile(); - if (containingFile == null) { - return Collections.emptyList(); - } - final AntFile antFile = AntSupport.getAntFile(containingFile); - if (antFile == null) { - return Collections.emptyList(); - } - final PsiElement antElement = antFile.findElementAt(e.getTextOffset()); - if (antElement == null) { - return Collections.emptyList(); - } - final TextRange antElementRange = antElement.getTextRange(); - final TextRange selectionElementRange = e.getTextRange(); - final PsiReference[] refs = antElement.getReferences(); - ArrayList ranges = new ArrayList(refs.length); - for (PsiReference ref : refs) { - if (ref instanceof AntPropertyReference) { - TextRange refRange = ref.getRangeInElement(); - refRange = refRange.shiftRight(antElementRange.getStartOffset()); - if (selectionElementRange.contains(refRange)) { - ranges.add(refRange); - } - } - } - return ranges; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/AntStructureViewBuilderFactory.java b/plugins/ant/src/com/intellij/lang/ant/AntStructureViewBuilderFactory.java deleted file mode 100644 index e5875b378c81..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/AntStructureViewBuilderFactory.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * @author max - */ -package com.intellij.lang.ant; - -import com.intellij.ide.structureView.*; -import com.intellij.ide.structureView.impl.common.PsiTreeElementBase; -import com.intellij.ide.util.treeView.smartTree.Sorter; -import com.intellij.lang.PsiStructureViewFactory; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntTarget; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class AntStructureViewBuilderFactory implements PsiStructureViewFactory { - public static final String UNNAMED = AntBundle.message("unnamed.string.presentation"); - - @Nullable - public StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) { - final AntFile antFile = AntSupport.getAntFile(psiFile); - if (antFile != null ) { - return new TreeBasedStructureViewBuilder() { - @NotNull - public StructureViewModel createStructureViewModel() { - return new StructureViewModelBase(antFile, new AntFileTreeElement(antFile)) - .withSuitableClasses(AntFile.class, AntTarget.class); - } - }; - } - return null; - } - - static class AntFileTreeElement extends PsiTreeElementBase { - - public AntFileTreeElement(AntFile antFile) { - super(antFile); - } - - private AntProject getAntProject() { - return getValue().getAntProject(); - } - - public String getPresentableText() { - final String name = getAntProject().getName(); - return name != null ? name : UNNAMED; - } - - @NotNull - public Collection getChildrenBase() { - List list = new ArrayList(); - for (AntTarget target : getAntProject().getTargets()) { - list.add(new AntTargetTreeElement(target)); - } - Collections.sort(list, Sorter.ALPHA_SORTER.getComparator()); - return list; - } - } - - static class AntTargetTreeElement extends PsiTreeElementBase { - - public AntTargetTreeElement(AntTarget target) { - super(target); - } - - public String getPresentableText() { - final AntTarget value = getValue(); - final String name = value != null? value.getName() : null; - return name != null ? name : UNNAMED; - } - - @NotNull - public Collection getChildrenBase() { - return new ArrayList(); - } - } -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/AntSupport.java b/plugins/ant/src/com/intellij/lang/ant/AntSupport.java index 4d6ea4e391e2..01fabf70fc43 100644 --- a/plugins/ant/src/com/intellij/lang/ant/AntSupport.java +++ b/plugins/ant/src/com/intellij/lang/ant/AntSupport.java @@ -19,11 +19,8 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.lang.ant.dom.AntDomAntlib; import com.intellij.lang.ant.dom.AntDomElement; import com.intellij.lang.ant.dom.AntDomProject; -import com.intellij.lang.ant.psi.AntFile; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ApplicationComponent; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -40,26 +37,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.Collections; -import java.util.List; public class AntSupport implements ApplicationComponent { - private static LanguageFileType ourFileType = null; - private static AntLanguage ourLanguage = null; - public AntSupport(FileTypeManager fileTypeManager) { - //fileTypeManager.getRegisteredFileTypes(); - //((CompositeLanguage)StdLanguages.XML).registerLanguageExtension(new AntLanguageExtension()); - } - - public static synchronized AntLanguage getLanguage() { - if (ourLanguage == null) { - if (ourFileType == null) { - ourFileType = new AntFileType(); - } - ourLanguage = (AntLanguage)ourFileType.getLanguage(); - } - return ourLanguage; + public AntSupport() { } @NotNull @@ -101,24 +82,6 @@ public class AntSupport implements ApplicationComponent { // Managing ant files dependencies via the task. // - public static synchronized List getImportingFiles(final AntFile imported) { - // todo: to be removed soon - return Collections.emptyList(); - } - - public static synchronized void registerDependency(final AntFile importing, final AntFile imported) { - // todo: to be removed soon - } - - public static AntFile getAntFile ( PsiFile psiFile ) { - if (psiFile instanceof AntFile) { - return (AntFile)psiFile; - } - else { - return (AntFile)psiFile.getViewProvider().getPsi(getLanguage()); - } - } - @Nullable public static AntDomProject getAntDomProject(PsiFile psiFile) { if (psiFile instanceof XmlFile) { diff --git a/plugins/ant/src/com/intellij/lang/ant/PsiAntElement.java b/plugins/ant/src/com/intellij/lang/ant/PsiAntElement.java deleted file mode 100644 index 0562603fd3cf..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/PsiAntElement.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant; - -import com.intellij.psi.PsiElement; - -/** - * @author dyoma - */ -public interface PsiAntElement extends PsiElement { - AntElementRole getRole(); - boolean canRename(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/ReflectedProject.java b/plugins/ant/src/com/intellij/lang/ant/ReflectedProject.java similarity index 98% rename from plugins/ant/src/com/intellij/lang/ant/psi/impl/ReflectedProject.java rename to plugins/ant/src/com/intellij/lang/ant/ReflectedProject.java index db77f1b30ea9..083f0694ebe5 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/ReflectedProject.java +++ b/plugins/ant/src/com/intellij/lang/ant/ReflectedProject.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lang.ant.psi.impl; +package com.intellij.lang.ant; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; @@ -35,7 +35,7 @@ import java.util.concurrent.locks.ReentrantLock; * Date: Apr 9, 2010 */ public final class ReflectedProject { - private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.psi.impl.ReflectedProject"); + private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.ReflectedProject"); @NonNls private static final String INIT_METHOD_NAME = "init"; @NonNls private static final String GET_TASK_DEFINITIONS_METHOD_NAME = "getTaskDefinitions"; diff --git a/plugins/ant/src/com/intellij/lang/ant/config/actions/RunTargetAction.java b/plugins/ant/src/com/intellij/lang/ant/config/actions/RunTargetAction.java index 6e1478f7095a..bbfede6ff6e2 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/actions/RunTargetAction.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/actions/RunTargetAction.java @@ -31,6 +31,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.DomElement; @@ -85,26 +86,43 @@ public class RunTargetAction extends AnAction { final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); - if (project == null || editor == null) return null; + if (project == null || editor == null) { + return null; + } final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); - if (file == null) return null; + if (file == null) { + return null; + } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if (!(psiFile instanceof XmlFile)) return null; - - final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile); - if (antFile == null) return null; - + if (!(psiFile instanceof XmlFile)) { + return null; + } final XmlFile xmlFile = (XmlFile)psiFile; - PsiElement at = xmlFile.findElementAt(editor.getCaretModel().getOffset()); - while (at != null && !(at instanceof XmlTag)) at = at.getParent(); - if (at == null) return null; - DomElement dom = AntSupport.getAntDomElement((XmlTag)at); - while (dom != null && !(dom instanceof AntDomTarget)) dom = dom.getParent(); + final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); + if (antFile == null) { + return null; + } - final AntDomTarget tar = (AntDomTarget)dom; - if (tar == null) return null; - return Pair.create(antFile, tar); + 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); } } diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBreadcrumbsInfoProvider.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBreadcrumbsInfoProvider.java deleted file mode 100644 index 626dc22010ef..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBreadcrumbsInfoProvider.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.config.impl; - -import com.intellij.lang.Language; -import com.intellij.lang.ant.AntSupport; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.psi.PsiElement; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author Eugene Zhuravlev - * Date: Jun 22, 2007 - */ -public class AntBreadcrumbsInfoProvider extends BreadcrumbsInfoProvider { - private static final Language[] ourSupportedLanguages = new Language[] {AntSupport.getLanguage()}; - - public Language[] getLanguages() { - return ourSupportedLanguages; - } - - public boolean acceptElement(@NotNull final PsiElement e) { - return e instanceof AntStructuredElement && e.isValid(); - } - - @NotNull - public String getElementInfo(@NotNull final PsiElement e) { - AntStructuredElement se = (AntStructuredElement)e; - final AntTypeDefinition typeDef = se.getTypeDefinition(); - if (typeDef == null) { - return se.getSourceElement().getName(); - } - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - final AntTypeId typeId = typeDef.getTypeId(); - final String nsPrefix = typeId.getNamespacePrefix(); - if (nsPrefix != null) { - builder.append(nsPrefix); - builder.append(":"); - } - - builder.append(typeId.getName()); - - final String name = se.getName(); - if (name != null) { - builder.append(" "); - builder.append(name); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @Nullable - public String getElementTooltip(@NotNull final PsiElement e) { - final XmlTag tag = ((AntStructuredElement)e).getSourceElement(); - final StringBuilder result = StringBuilderSpinAllocator.alloc(); - try { - result.append("<"); - result.append(tag.getName()); - - for (final XmlAttribute attrib : tag.getAttributes()) { - result.append(" ").append(attrib.getText()); - } - if (tag.isEmpty()) { - result.append("/>"); - } - else { - result.append(">..."); - } - return result.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(result); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/doc/AntDomDocumentationProvider.java b/plugins/ant/src/com/intellij/lang/ant/doc/AntDomDocumentationProvider.java index 79106d9d2fb1..fc9b3e1937fd 100644 --- a/plugins/ant/src/com/intellij/lang/ant/doc/AntDomDocumentationProvider.java +++ b/plugins/ant/src/com/intellij/lang/ant/doc/AntDomDocumentationProvider.java @@ -15,12 +15,12 @@ */ package com.intellij.lang.ant.doc; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.lang.ant.AntSupport; import com.intellij.lang.ant.config.impl.AntInstallation; import com.intellij.lang.ant.dom.AntDomElement; import com.intellij.lang.ant.dom.AntDomProject; import com.intellij.lang.ant.dom.AntDomTarget; -import com.intellij.lang.ant.psi.AntFilesProvider; import com.intellij.lang.documentation.DocumentationProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomDirSet.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomDirSet.java index 9e8fa85bed9c..b9ff0941c650 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomDirSet.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomDirSet.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.xml.Attribute; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java index 9ea30d7449a2..fd5cf56d2b1d 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java @@ -15,8 +15,8 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.impl.AntIntrospector; -import com.intellij.lang.ant.psi.impl.ReflectedProject; +import com.intellij.lang.ant.AntIntrospector; +import com.intellij.lang.ant.ReflectedProject; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileList.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileList.java index d274c75cdd33..3d0ffe7aa7cb 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileList.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileList.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.text.StringTokenizer; import com.intellij.util.xml.Attribute; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileSet.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileSet.java index 207dbb6f57ac..0950052ece40 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileSet.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileSet.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.xml.Attribute; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFilesProviderImpl.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFilesProviderImpl.java index 1743062e7c60..f42453bec744 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFilesProviderImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFilesProviderImpl.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.util.PathUtil; import com.intellij.util.xml.Attribute; import com.intellij.util.xml.GenericAttributeValue; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPath.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPath.java index f8c42095acd0..30239d521cb9 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPath.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPath.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import org.jetbrains.annotations.NotNull; import java.io.File; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPathElement.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPathElement.java index 6d6975c82dbc..eb9c1b1f8a93 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPathElement.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPathElement.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.ant.dom; -import com.intellij.lang.ant.psi.AntFilesProvider; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.psi.PsiFileSystemItem; import com.intellij.util.xml.Attribute; import com.intellij.util.xml.Convert; diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProject.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProject.java index a29af57d87f6..d9de2a4d0aac 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProject.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomProject.java @@ -15,12 +15,12 @@ */ package com.intellij.lang.ant.dom; +import com.intellij.lang.ant.ReflectedProject; import com.intellij.lang.ant.config.AntConfigurationBase; import com.intellij.lang.ant.config.impl.AntBuildFileImpl; import com.intellij.lang.ant.config.impl.AntConfigurationImpl; import com.intellij.lang.ant.config.impl.AntInstallation; import com.intellij.lang.ant.config.impl.GlobalAntConfiguration; -import com.intellij.lang.ant.psi.impl.ReflectedProject; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; 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 ac614411971c..242722b4fa9b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntResolveInspection.java @@ -17,6 +17,7 @@ package com.intellij.lang.ant.dom; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.lang.ant.AntBundle; +import com.intellij.lang.ant.quickfix.AntChangeContextLocalFix; import com.intellij.lang.ant.validation.AntInspection; import com.intellij.psi.PsiPolyVariantReference; import com.intellij.psi.PsiReference; @@ -40,7 +41,7 @@ public class AntResolveInspection extends AntInspection { @NotNull public String getDisplayName() { - return "Reference resolve problems"; + return "Ant references resolve problems"; } @NotNull @@ -100,18 +101,15 @@ public class AntResolveInspection extends AntInspection { continue; } if (!isResolvable(ref)) { - holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement() /*todo add quickfixes*/); + + holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), new AntChangeContextLocalFix()); + if (ref instanceof AntDomFileReference) { if (processed == null) { processed = new HashSet(); } ContainerUtil.addAll(processed, ((AntDomFileReference)ref).getFileReferenceSet().getAllReferences()); } - - //final IntentionAction[] intentionActions = antRef.getFixes(); - //for (final IntentionAction action : intentionActions) { - // annotation.registerFix(action); - //} } } } diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java b/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java index 9f8390022809..cacc72011fbf 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java @@ -15,10 +15,10 @@ */ package com.intellij.lang.ant.dom; +import com.intellij.lang.ant.AntFilesProvider; import com.intellij.lang.ant.AntSupport; +import com.intellij.lang.ant.ReflectedProject; import com.intellij.lang.ant.config.impl.AntResourcesClassLoader; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.impl.ReflectedProject; import com.intellij.lang.properties.IProperty; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.openapi.diagnostic.Logger; diff --git a/plugins/ant/src/com/intellij/lang/ant/misc/AntPsiUtil.java b/plugins/ant/src/com/intellij/lang/ant/misc/AntPsiUtil.java deleted file mode 100644 index 4f76e2858612..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/misc/AntPsiUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.misc; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntProject; -import org.jetbrains.annotations.Nullable; - -public class AntPsiUtil { - - private AntPsiUtil() { - } - - /** - * Returns an element under Ant project which is an ancestor of the specified element. - * Returns null for AntProject and AntFile. - */ - @Nullable - public static AntElement getSubProjectElement(AntElement element) { - AntElement parent = element.getAntParent(); - while (true) { - if (parent == null) { - element = null; - break; - } - if (parent instanceof AntProject) break; - element = parent; - parent = parent.getAntParent(); - } - return element; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementSetSpinAllocator.java b/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementSetSpinAllocator.java deleted file mode 100644 index e2243531d165..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementSetSpinAllocator.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.misc; - -import com.intellij.psi.PsiElement; -import com.intellij.util.SpinAllocator; - -import java.util.HashSet; -import java.util.Set; - -public class PsiElementSetSpinAllocator { - - private PsiElementSetSpinAllocator() { - } - - private static class Creator implements SpinAllocator.ICreator> { - public Set createInstance() { - return new HashSet(); - } - } - - private static class Disposer implements SpinAllocator.IDisposer> { - public void disposeInstance(final Set instance) { - instance.clear(); - } - } - - private static final SpinAllocator> myAllocator = - new SpinAllocator>(new Creator(), new Disposer()); - - public static Set alloc() { - return myAllocator.alloc(); - } - - public static void dispose(Set instance) { - myAllocator.dispose(instance); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementWithValueSetSpinAllocator.java b/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementWithValueSetSpinAllocator.java deleted file mode 100644 index 9491227b3777..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/misc/PsiElementWithValueSetSpinAllocator.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.misc; - -import com.intellij.openapi.util.Pair; -import com.intellij.psi.PsiElement; -import com.intellij.util.SpinAllocator; - -import java.util.HashSet; -import java.util.Set; - -public class PsiElementWithValueSetSpinAllocator { - - private PsiElementWithValueSetSpinAllocator() { - } - - private static class Creator implements SpinAllocator.ICreator>> { - public Set> createInstance() { - return new HashSet>(); - } - } - - private static class Disposer implements SpinAllocator.IDisposer>> { - public void disposeInstance(final Set> instance) { - instance.clear(); - } - } - - private static final SpinAllocator>> myAllocator = - new SpinAllocator>>(new Creator(), new Disposer()); - - public static Set> alloc() { - return myAllocator.alloc(); - } - - public static void dispose(Set> instance) { - myAllocator.dispose(instance); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntAllTasksContainer.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntAllTasksContainer.java deleted file mode 100644 index d441b989585d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntAllTasksContainer.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -/** - * An element which can contain all tasks as nested elements and nothing else. - * Is used to wrap the Sequential and Parallel tasks. - */ -public interface AntAllTasksContainer extends AntTask { -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntAnt.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntAnt.java deleted file mode 100644 index acf56fb386f4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntAnt.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.Nullable; - -public interface AntAnt extends AntTask { - - @Nullable - PsiFile getCalledAntFile(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntCall.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntCall.java deleted file mode 100644 index f6e4b06ef28d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntCall.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntCall extends AntTask { - - @Nullable - AntTarget getTarget(); - - @NotNull - AntProperty[] getParams(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntComment.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntComment.java deleted file mode 100644 index 2e51d731a5ee..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntComment.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.psi.PsiComment; - -public interface AntComment extends PsiComment, AntElement { -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntDefTask.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntDefTask.java deleted file mode 100644 index 784dfbf3ad9d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntDefTask.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -/** - * @author Eugene Zhuravlev - * Date: Aug 8, 2008 - */ -public interface AntDefTask extends AntTask { - void clearClassesCache(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntElement.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntElement.java deleted file mode 100644 index f038e2a78c36..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntElement.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.PsiAntElement; -import com.intellij.psi.xml.XmlElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntElement extends PsiAntElement { - AntElement[] EMPTY_ARRAY = new AntElement[0]; - - XmlElement getSourceElement(); - - @Nullable - AntElement getAntParent(); - - AntFile getAntFile(); - - AntProject getAntProject(); - - void clearCaches(); - - /** - * Does the same as findElementAt() but without rebuilding cleared PSI. - * - * @param offset - * @return - */ - @Nullable - AntElement lightFindElementAt(int offset); - - void incModificationCount(); - - void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntElementVisitor.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntElementVisitor.java deleted file mode 100644 index 08ed7cc0832d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntElementVisitor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.PsiAntElement; -import com.intellij.psi.PsiElement; - -/** - * @author Eugene Zhuravlev - * Date: Apr 13, 2007 - */ -public class AntElementVisitor { - public void visitAntElement(final PsiAntElement antElement) { - final PsiElement[] psiElements = antElement.getChildren(); - for (PsiElement child : psiElements) { - if (child instanceof AntElement) { - ((AntElement)child).acceptAntElementVisitor(this); - } - } - } - - public void visitAntStructuredElement(final AntStructuredElement element) { - visitAntElement(element); - } - - public void visitAntTarget(final AntTarget target) { - visitAntElement(target); - } - - public void visitAntTask(final AntTask task) { - visitAntElement(task); - } - - public void visitAntCall(final AntCall antCall) { - visitAntElement(antCall); - } - - public void visitAntImport(final AntImport antImport) { - visitAntElement(antImport); - } - - public void visitAntProperty(final AntProperty antProperty) { - visitAntElement(antProperty); - } - - public void visitAntTypedef(final AntTypeDef typeDef) { - visitAntElement(typeDef); - } - - public void visitAntMacroDef(final AntMacroDef antMacroDef) { - visitAntElement(antMacroDef); - } - - public void visitAntScriptDef(final AntScriptDef antScriptDef) { - visitAntElement(antScriptDef); - } - - public void visitAntPresetDef(final AntPresetDef presetDef) { - visitAntElement(presetDef); - } - - public void visitAntProject(final AntProject antProject) { - visitAntElement(antProject); - } - - public void visitAntFile(final AntFile antFile) { - visitAntElement(antFile); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntFile.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntFile.java deleted file mode 100644 index 1d26c13719f9..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntFile.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.config.impl.AntInstallation; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.openapi.util.ModificationTracker; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlFile; -import com.intellij.util.Processor; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface AntFile extends PsiFile, AntElement, PsiNamedElement, ModificationTracker { - - AntFile[] EMPTY_ARRAY = new AntFile[0]; - - @NotNull - XmlFile getSourceElement(); - - ClassLoader getClassLoader(); - - @Nullable - AntInstallation getAntInstallation(); - - @NotNull - AntTypeDefinition[] getBaseTypeDefinitions(); - - @Nullable - AntTypeDefinition getBaseTypeDefinition(final String taskClassName); - - @Nullable /* will return null in case ant installation was not properly configured*/ - AntTypeDefinition getTargetDefinition(); - - void registerCustomType(final AntTypeDefinition def); - - void unregisterCustomType(final AntTypeDefinition def); - - VirtualFile getVirtualFile(); - - void clearExternalProperties(); - - void setExternalProperty(@NotNull final String name, @NotNull final String value); - - @Nullable - VirtualFile getContainingPath(); - - void clearCachesWithTypeDefinitions(); - - void addEnvironmentPropertyPrefix(@NotNull final String envPrefix); - - boolean isEnvironmentProperty(@NotNull final String propName); - - List getEnvironmentPrefixes(); - - @Nullable - AntProperty getProperty(@NonNls final String name); - - void processAllProperties(@NonNls final String name, Processor processor); - - void setProperty(final String name, final AntProperty element); - - @NotNull - AntProperty[] getProperties(); - - void invalidateProperties(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntImport.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntImport.java deleted file mode 100644 index fa16043b11b9..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntImport.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import org.jetbrains.annotations.Nullable; - -public interface AntImport extends AntTask { - - @Nullable - String getFileName(); - - @Nullable - AntFile getImportedFile(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntMacroDef.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntMacroDef.java deleted file mode 100644 index 5e70f756caa4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntMacroDef.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; - -public interface AntMacroDef extends AntDefTask { - AntTypeDefinition getMacroDefinition(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntNameIdentifier.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntNameIdentifier.java deleted file mode 100644 index a4a36a36f59f..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntNameIdentifier.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -/** - * @author Eugene Zhuravlev - * Date: Jun 20, 2007 - */ -public interface AntNameIdentifier extends AntElement { - String getIdentifierName(); - - void setIdentifierName(@NotNull String name) throws IncorrectOperationException; -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntPresetDef.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntPresetDef.java deleted file mode 100644 index de1506005b14..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntPresetDef.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; - -public interface AntPresetDef extends AntDefTask { - AntTypeDefinition getPresetDefinition(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntProject.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntProject.java deleted file mode 100644 index e8c1840a1cb4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntProject.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntProject extends AntStructuredElement { - - @Nullable - String getBaseDir(); - - @Nullable - String getDescription(); - - @NotNull - AntTarget[] getTargets(); - - @Nullable - AntTarget getTarget(final String name); - - @Nullable - AntTarget getDefaultTarget(); - - @NotNull - AntTarget[] getImportedTargets(); - - @NotNull - AntFile[] getImportedFiles(); - - void registerRefId(final String id, AntElement element); - - @Nullable - AntElement getElementByRefId(String refid); - - @NotNull - String[] getRefIds(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntProperty.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntProperty.java deleted file mode 100644 index a1444c967008..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntProperty.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.properties.psi.PropertiesFile; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -public interface AntProperty extends AntTask { - - AntProperty[] EMPTY_ARRAY = new AntProperty[0]; - @NonNls String TSTAMP_TAG = "tstamp"; - @NonNls String TSTAMP_PATTERN_ATTRIBUTE_NAME = "pattern"; - @NonNls String TSTAMP_TIMEZONE_ATTRIBUTE_NAME = "timezone"; - - /** - * Calculates property value. - * - * @param propName -- name of a property, some property elements may define several properties. - * @return - */ - @Nullable - String getValue(final String propName); - - @Nullable - String getFileName(); - - @Nullable - PropertiesFile getPropertiesFile(); - - @Nullable - String getPrefix(); - - @Nullable - String getEnvironment(); - - @Nullable - String[] getNames(); - - @Nullable - AntElement getFormatElement(final String propName); - - boolean isTstamp(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntScriptDef.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntScriptDef.java deleted file mode 100644 index 3524ef0645c3..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntScriptDef.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; - -public interface AntScriptDef extends AntDefTask { - AntTypeDefinition getScriptDefinition(); -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntStructuredElement.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntStructuredElement.java deleted file mode 100644 index 359b03131a6e..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntStructuredElement.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface AntStructuredElement extends AntElement, PsiNamedElement { - - @NotNull - XmlTag getSourceElement(); - - @Nullable - AntTypeDefinition getTypeDefinition(); - - void registerCustomType(final AntTypeDefinition def); - - void unregisterCustomType(final AntTypeDefinition def); - - boolean hasImportedTypeDefinition(); - - /** - * Finds psi file by specified name in the directory of current ant file. - * - * @param name - name of the file to find. - * @return psi file if it exists, else null. - */ - @Nullable - PsiFile findFileByName(final String name); - - /** - * Finds psi file by specified name and basedir. - * - * @param name - name of the file to find. - * @param baseDir - base directory where to find the file. If the parameter is specified as null, ant project's base directory property is used. - * @return psi file if it exists, else null. - */ - @Nullable - PsiFile findFileByName(final String name, @Nullable final String baseDir); - - @Nullable - String computeAttributeValue(@NonNls String value); - - boolean hasNameElement(); - - boolean hasIdElement(); - - @NonNls - @NotNull - List getFileReferenceAttributes(); - - /** - * @return true if is instance of a type defined by the or task. - */ - boolean isTypeDefined(); - - /** - * @return true if is instance of a type defined by the task. - */ - boolean isPresetDefined(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntTarget.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntTarget.java deleted file mode 100644 index 171d423d0351..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntTarget.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntTarget extends AntStructuredElement { - enum ConditionalAttribute { - IF("if"), UNLESS("unless"); - - private final String xmlName; - - ConditionalAttribute(@NonNls final String xmlName) { - this.xmlName = xmlName; - } - - public String getXmlName() { - return xmlName; - } - } - - AntTarget[] EMPTY_ARRAY = new AntTarget[0]; - - /** - * @return If project is named, target name prefixed with project name and the dot, - * otherwise target name equal to that returned by {@link #getName()}. - */ - @NotNull - String getQualifiedName(); - - @Nullable - String getDescription(); - - @NotNull - AntTarget[] getDependsTargets(); - - @Nullable - String getConditionalPropertyName(ConditionalAttribute attrib); - - void setDependsTargets(@NotNull AntTarget[] targets); - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntTask.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntTask.java deleted file mode 100644 index 9d5c0d1c7b1d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntTask.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -public interface AntTask extends AntStructuredElement { - - boolean isMacroDefined(); - - boolean isScriptDefined(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/AntTypeDef.java b/plugins/ant/src/com/intellij/lang/ant/psi/AntTypeDef.java deleted file mode 100644 index 6b08310d1292..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/AntTypeDef.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi; - -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntTypeDef extends AntDefTask { - - @Nullable - String getDefinedName(); - - @Nullable - String getClassName(); - - @Nullable - String getClassPath(); - - @Nullable - String getUri(); - - @Nullable - String getFile(); - - @Nullable - String getResource(); - - @NonNls - @Nullable - String getFormat(); - - @NotNull - AntTypeDefinition[] getDefinitions(); - - boolean typesLoaded(); - - @Nullable - String getLocalizedError(); - - @Nullable - String getAdapterName(); - - @Nullable - String getAdaptToName(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAllTasksContainerImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAllTasksContainerImpl.java deleted file mode 100644 index aee772f42d76..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAllTasksContainerImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntAllTasksContainer; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; - -public class AntAllTasksContainerImpl extends AntTaskImpl implements AntAllTasksContainer { - - public AntAllTasksContainerImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - /* - if (myDefinition != null && definition != null && myDefinition.getNestedClassName(definition.getTypeId()) == null) { - // allow all tasks as nested elements - for (final AntTypeDefinition def : getAntFile().getBaseTypeDefinitions()) { - if (def.isTask()) { - myDefinition.registerNestedType(def.getTypeId(), def.getClassName()); - } - } - } - */ - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntAllTasksContainer["); - builder.append(getSourceElement().getName()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAntImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAntImpl.java deleted file mode 100644 index ede2fafcfba0..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntAntImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntAnt; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.impl.reference.AntTargetReference; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class AntAntImpl extends AntTaskImpl implements AntAnt { - - @NonNls private static final String DEFAULT_ANTFILE = "build.xml"; - - public AntAntImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("Ant["); - builder.append(getFileName()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @NotNull - public List getFileReferenceAttributes() { - final ArrayList attribs = new ArrayList(super.getFileReferenceAttributes()); - attribs.add("antfile"); - attribs.add("output"); - return attribs; - } - - @Nullable - public PsiFile getCalledAntFile() { - return findFileByName(getFileName(), getDir()); - } - - @NotNull - public PsiReference[] getReferences() { - final PsiReference[] result = super.getReferences(); - for (final PsiReference reference : result) { - if (reference instanceof AntTargetReference) { - ((AntTargetReference)reference).setShouldBeSkippedByAnnotator(getCalledAntFile() == null); - } - } - return result; - } - - @NotNull - private String getFileName() { - final String result = getSourceElement().getAttributeValue("antfile"); - if (result == null) { - return DEFAULT_ANTFILE; - } - return result; - } - - @Nullable - private String getDir() { - return getSourceElement().getAttributeValue("dir"); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntBuildNumberImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntBuildNumberImpl.java deleted file mode 100644 index b3eb5ba30d35..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntBuildNumberImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProperty; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; - -public class AntBuildNumberImpl extends AntTaskImpl implements AntProperty { - - @NonNls private static final String BUILD_NUMBER_PROPERTY = "build.number"; - - public AntBuildNumberImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - final AntFile antFile = getAntFile(); - if (antFile != null) { - antFile.setProperty(BUILD_NUMBER_PROPERTY, this); - } - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntProperty["); - builder.append(getName()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public String getName() { - return BUILD_NUMBER_PROPERTY; - } - - @NotNull - public List getFileReferenceAttributes() { - return Collections.singletonList(AntFileImpl.FILE_ATTR); - } - - @Nullable - public String getValue(final String propName) { - return null; - } - - @Nullable - public String getFileName() { - return null; - } - - @Nullable - public PropertiesFile getPropertiesFile() { - return null; - } - - @Nullable - public String getPrefix() { - return null; - } - - @Nullable - public String getEnvironment() { - return null; - } - - @Nullable - public String[] getNames() { - return new String[]{getName()}; - } - - @Nullable - public AntElement getFormatElement(final String propName) { - return this; - } - - public boolean isTstamp() { - return false; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCallImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCallImpl.java deleted file mode 100644 index 06e923ee3f98..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCallImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class AntCallImpl extends AntTaskImpl implements AntCall { - - private AntTarget[] myDependsTargets = null; - private AntProperty[] myParams = null; - - public AntCallImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntCall(this); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntCall to "); - final AntTarget target = getTarget(); - builder.append((target == null) ? "null" : target.toString()); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @Nullable - public AntTarget getTarget() { - synchronized (PsiLock.LOCK) { - final String target = getSourceElement().getAttributeValue("target"); - final AntTarget result = (target == null) ? null : getAntProject().getTarget(target); - if (result != null) { - result.setDependsTargets(getDependsTargets()); - } - return result; - } - } - - @NotNull - public AntProperty[] getParams() { - synchronized (PsiLock.LOCK) { - if (myParams == null) { - final List properties = new ArrayList(); - for (AntElement element : getChildren()) { - if (element instanceof AntProperty) { - properties.add((AntProperty)element); - } - } - myParams = properties.toArray(new AntProperty[properties.size()]); - } - return myParams; - } - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myDependsTargets = null; - } - } - - @NotNull - private AntTarget[] getDependsTargets() { - synchronized (PsiLock.LOCK) { - if (myDependsTargets == null) { - final List targets = new ArrayList(); - for (AntElement element : getChildren()) { - if (element instanceof AntTarget) { - targets.add((AntTarget)element); - } - } - myDependsTargets = targets.toArray(new AntTarget[targets.size()]); - } - return myDependsTargets; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCommentImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCommentImpl.java deleted file mode 100644 index 3ae9022ab710..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntCommentImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntComment; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.xml.XmlComment; -import com.intellij.psi.xml.XmlElement; -import org.jetbrains.annotations.NotNull; - -public class AntCommentImpl extends AntElementImpl implements AntComment { - - public AntCommentImpl(final AntStructuredElement parent, final XmlElement sourceElement) { - super(parent, sourceElement); - } - - public IElementType getTokenType() { - return ((XmlComment) getSourceElement()).getTokenType(); - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - public String toString() { - return "AntComment"; - } - - @NotNull - public PsiReference[] getReferences() { - return PsiReference.EMPTY_ARRAY; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntDirSetImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntDirSetImpl.java deleted file mode 100644 index 23d581fd1c27..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntDirSetImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * @author Eugene Zhuravlev - * Date: May 4, 2007 - */ -public class AntDirSetImpl extends AntFilesProviderImpl{ - public AntDirSetImpl(final AntElement parent, final XmlTag sourceElement) { - super(parent, sourceElement); - } - - public AntDirSetImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition, @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntDirSetImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - @NotNull - protected List getFiles(final AntPattern pattern, final Set processed) { - final File singleFile = getCanonicalFile(computeAttributeValue(getSourceElement().getAttributeValue("file"))); - if (singleFile == null || pattern.hasIncludePatterns()) { - // if singleFile is specified, there are no implicit includes - final File root = getCanonicalFile(computeAttributeValue(getSourceElement().getAttributeValue("dir"))); - if (root != null) { - final ArrayList files = new ArrayList(); - if (singleFile != null && singleFile.isDirectory()) { - files.add(singleFile); - } - new FilesCollector().collectFiles(files, root, "", pattern); - return files; - } - } - - if (singleFile != null && singleFile.isDirectory()) { - Collections.singletonList(singleFile); - } - - return Collections.emptyList(); - } - - private static class FilesCollector { - private static final int MAX_DIRS_TO_PROCESS = 100; - private int myDirsProcessed = 0; - - public void collectFiles(List container, File from, String relativePath, final AntPattern pattern) { - if (myDirsProcessed > MAX_DIRS_TO_PROCESS) { - return; - } - myDirsProcessed++; - final File[] children = from.listFiles(); - if (children != null) { - for (File child : children) { - if (child.isDirectory()) { - final String childPath = makePath(relativePath, child.getName()); - if (pattern.acceptPath(childPath)) { - container.add(child); - } - if (pattern.couldBeIncluded(childPath)) { - collectFiles(container, child, childPath, pattern); - } - } - } - } - } - - private static String makePath(final String parentPath, final String name) { - if (parentPath.length() == 0) { - return name; - } - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - return builder.append(parentPath).append("/").append(name).toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementFactory.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementFactory.java deleted file mode 100644 index 51381b1dfc65..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementFactory.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlComment; -import com.intellij.psi.xml.XmlElement; -import com.intellij.psi.xml.XmlEntityRef; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.containers.HashMap; -import org.apache.tools.ant.Target; -import org.apache.tools.ant.taskdefs.*; -import org.apache.tools.ant.taskdefs.optional.extension.JarLibResolveTask; -import org.apache.tools.ant.taskdefs.optional.perforce.P4Counter; -import org.apache.tools.ant.taskdefs.optional.script.ScriptDef; -import org.apache.tools.ant.types.DirSet; -import org.apache.tools.ant.types.FileList; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -public class AntElementFactory { - - @NonNls private static final String RESULT_PROPERTY = "resultproperty"; - @NonNls private static final String TOTAL_PROPERTY = "totalproperty"; - - private static Map ourAntTypeToKnownAntElementCreatorMap = null; - - private AntElementFactory() { - } - - @Nullable - public static AntElement createAntElement(final AntStructuredElement parent, final XmlElement element) { - instantiate(); - - if (element instanceof XmlComment) { - return new AntCommentImpl(parent, element); - } - if (element instanceof XmlEntityRef) { - return new AntEntityRefImpl(parent, element); - } - if (!(element instanceof XmlTag)) return null; - - final XmlTag tag = (XmlTag)element; - AntTypeDefinition typeDef = null; - String typeName = tag.getLocalName(); - final String nsPrefix = tag.getNamespacePrefix(); - if (nsPrefix.length() == 0 ) { - /** - * Hardcode for task (IDEADEV-6731). - */ - if (typeName.equals(AntFileImpl.JAVADOC2_TAG)) { - typeName = AntFileImpl.JAVADOC2_TAG; - } - /** - * Hardcode for and tasks (IDEADEV-6830). - */ - if (typeName.equals(AntFileImpl.UNWAR_TAG) || typeName.equals(AntFileImpl.UNJAR_TAG)) { - typeName = AntFileImpl.UNZIP_TAG; - } - } - - final AntTypeId id = new AntTypeId(typeName, nsPrefix); - final AntFile file = parent.getAntFile(); - - final AntTypeDefinition parentDef = parent.getTypeDefinition(); - if (parentDef != null) { - final String className = parentDef.getNestedClassName(id); - if (className != null && file != null) { - typeDef = file.getBaseTypeDefinition(className); - } - } - - if (file != null) { - // try macrodef - if (typeDef == null) { - typeDef = file.getBaseTypeDefinition(AntMacroDefImpl.createMacroClassName(typeName)); - } - - // try preetDef - if (typeDef == null) { - typeDef = file.getBaseTypeDefinition(AntPresetDefImpl.createPresetDefClassName(typeName)); - } - - if (typeDef == null) { - final AntProject project = file.getAntProject(); - final AntTypeDefinition projectDef = project != null? project.getTypeDefinition() : null; - for (AntTypeDefinition def : file.getBaseTypeDefinitions()) { - if (id.equals(def.getTypeId())) { - if (projectDef != null) { // perform additional check if project exists - final boolean isRegisteredWithinProject = def.getClassName().equals(projectDef.getNestedClassName(def.getTypeId())); - if (!isRegisteredWithinProject) { - continue; - } - } - typeDef = def; - break; - } - } - } - - } - boolean importedType = false; - if (typeDef == null) { - final AntProject project = parent.getAntProject(); - for (final AntFile imported : project.getImportedFiles()) { - final AntProject importedProject = imported.getAntProject(); - if (!project.equals(importedProject)) { - importedProject.getChildren(); - for (AntTypeDefinition def : imported.getBaseTypeDefinitions()) { - if (id.equals(def.getTypeId())) { - importedType = true; - typeDef = def; - break; - } - } - } - } - } - AntStructuredElementImpl result = null; - if (typeDef != null) { - final AntElementCreator antElementCreator = ourAntTypeToKnownAntElementCreatorMap.get(typeDef.getClassName()); - if (antElementCreator != null) { - result = (AntStructuredElementImpl)antElementCreator.create(parent, tag); - } - else if (typeDef.isTask()) { - if (typeDef.isProperty()) { - result = new AntPropertyImpl(parent, tag, typeDef); - } - else if (typeDef.isAllTaskContainer()) { - result = new AntAllTasksContainerImpl(parent, tag, typeDef); - } - else { - result = new AntTaskImpl(parent, tag, typeDef); - } - } - } - if (result == null) { - // HACK for the properties - result = AntFileImpl.FORMAT_TAG.equals(tag.getName()) - ? new AntTimestampFormatImpl(parent, tag, typeDef) - : new AntStructuredElementImpl(parent, tag, typeDef); - } - result.setImportedTypeDefinition(importedType); - return result; - - } - - private static void instantiate() { - synchronized (PsiLock.LOCK) { - if (ourAntTypeToKnownAntElementCreatorMap == null) { - ourAntTypeToKnownAntElementCreatorMap = new HashMap(); - final AntElementCreator targetCreator = new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntTargetImpl(parent, tag); - } - }; - ourAntTypeToKnownAntElementCreatorMap.put(Target.class.getName(), targetCreator); - ourAntTypeToKnownAntElementCreatorMap.put(Ant.TargetElement.class.getName(), targetCreator); - - // properties - ourAntTypeToKnownAntElementCreatorMap.put(Property.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPropertyImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Property.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Tstamp.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPropertyImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Tstamp.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Checksum.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - final AntTypeDefinition checksumDef = parent.getAntFile().getBaseTypeDefinition(Checksum.class.getName()); - if (tag.getAttributeValue(TOTAL_PROPERTY) != null) { - return new AntPropertyImpl(parent, tag, checksumDef, TOTAL_PROPERTY); - } - return new AntPropertyImpl(parent, tag, checksumDef, AntFileImpl.PROPERTY); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(ExecTask.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - final AntTypeDefinition execDef = parent.getAntFile().getBaseTypeDefinition(ExecTask.class.getName()); - if (tag.getAttributeValue(RESULT_PROPERTY) != null) { - return new AntPropertyImpl(parent, tag, execDef, RESULT_PROPERTY); - } - return new AntPropertyImpl(parent, tag, execDef, "outputproperty"); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Java.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - final AntTypeDefinition execDef = parent.getAntFile().getBaseTypeDefinition(Java.class.getName()); - return new AntPropertyImpl(parent, tag, execDef, RESULT_PROPERTY); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Input.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - final AntTypeDefinition execDef = parent.getAntFile().getBaseTypeDefinition(Input.class.getName()); - return new AntPropertyImpl(parent, tag, execDef, "addproperty"); - } - }); - /* - ourAntTypeToKnownAntElementCreatorMap.put(Exit.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - final AntTypeDefinition failTaskDefinition = parent.getAntFile().getBaseTypeDefinition(Exit.class.getName()); - if (tag.getAttributeValue(AntFileImpl.IF_ATTR) != null) { - return new AntPropertyImpl(parent, tag, failTaskDefinition, AntFileImpl.IF_ATTR); - } - return new AntPropertyImpl(parent, tag, failTaskDefinition, AntFileImpl.UNLESS_ATTR); - } - }); - */ - for (final String clazz : PROPERTY_CLASSES) { - addPropertyCreator(clazz); - } - - // sequential and parallel tasks can contain all other tasks - for (final String clazz : ALL_TASKS_CONTAINER_CLASSES) { - addAllTasksContainerCreator(clazz); - } - ourAntTypeToKnownAntElementCreatorMap.put(CallTarget.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntCallImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(CallTarget.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Taskdef.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntTypeDefImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Taskdef.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Typedef.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntTypeDefImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Typedef.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(MacroDef.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntMacroDefImpl((AntStructuredElement)parent, tag, - parent.getAntFile().getBaseTypeDefinition(MacroDef.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(PreSetDef.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPresetDefImpl((AntStructuredElement)parent, tag, - parent.getAntFile().getBaseTypeDefinition(PreSetDef.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(ScriptDef.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntScriptDefImpl((AntStructuredElement)parent, tag, - parent.getAntFile().getBaseTypeDefinition(ScriptDef.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(ImportTask.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntImportImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(ImportTask.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Ant.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntAntImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Ant.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(BuildNumber.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntBuildNumberImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(BuildNumber.class.getName())); - } - }); - - ourAntTypeToKnownAntElementCreatorMap.put(DirSet.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntDirSetImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(DirSet.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(FileList.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntFileListImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(FileList.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(FileSet.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntFileSetImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(FileSet.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Path.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPathImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Path.class.getName())); - } - }); - ourAntTypeToKnownAntElementCreatorMap.put(Path.PathElement.class.getName(), new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPathImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(Path.PathElement.class.getName())); - } - }); - - } - } - } - - private static void addPropertyCreator(final String className) { - ourAntTypeToKnownAntElementCreatorMap.put(className, new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntPropertyImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(className), AntFileImpl.PROPERTY); - } - }); - } - - private static void addAllTasksContainerCreator(final String className) { - ourAntTypeToKnownAntElementCreatorMap.put(className, new AntElementCreator() { - public AntStructuredElement create(final AntElement parent, final XmlTag tag) { - return new AntAllTasksContainerImpl(parent, tag, parent.getAntFile().getBaseTypeDefinition(className)); - } - }); - } - - private final static String[] PROPERTY_CLASSES = {Available.class.getName(), ConditionTask.class.getName(), UpToDate.class.getName(), - Dirname.class.getName(), Basename.class.getName(), LoadFile.class.getName(), TempFile.class.getName(), PathConvert.class.getName(), - Length.class.getName(), WhichResource.class.getName(), JarLibResolveTask.class.getName(), P4Counter.class.getName(), ManifestClassPath.class.getName()}; - - private final static String[] ALL_TASKS_CONTAINER_CLASSES = - {MacroDef.NestedSequential.class.getName(), Sequential.class.getName(), Parallel.class.getName()}; - - private static interface AntElementCreator { - AntStructuredElement create(final AntElement parent, final XmlTag tag); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementImpl.java deleted file mode 100644 index a023784ba03a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntElementImpl.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.extapi.psi.MetadataPsiElementBase; -import com.intellij.lang.ASTNode; -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.AntLanguage; -import com.intellij.lang.ant.AntSupport; -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.impl.reference.AntReferenceProvidersRegistry; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.*; -import com.intellij.psi.xml.XmlElement; -import com.intellij.util.ProcessingContext; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.List; - -public class AntElementImpl extends MetadataPsiElementBase implements AntElement { - - protected static final AntElement ourNull = new AntElementImpl(null, null) { - @NonNls - public String getName() { - return "AntNull"; - } - - public boolean isValid() { - return true; - } - }; - - private final AntElement myParent; - private volatile AntElement[] myChildren; - private volatile PsiReference[] myReferences; - private volatile PsiElement myPrev; - private volatile PsiElement myNext; - - public AntElementImpl(final AntElement parent, final XmlElement sourceElement) { - super(sourceElement); - myParent = parent; - } - - @NotNull - public AntLanguage getLanguage() { - return AntSupport.getLanguage(); - } - - public XmlElement getSourceElement() { - return (XmlElement)super.getSourceElement(); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntElement["); - builder.append(this == ourNull ? "null" : getSourceElement().toString()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @Nullable - public AntElement getAntParent() { - return myParent; - } - - public AntProject getAntProject() { - PsiElement element = this; - - while (!(element instanceof AntProject)) { - if (element == null || element instanceof PsiFile ) { - return null; - } - element = element.getParent(); - } - - return (AntProject)element; - } - - public AntFile getAntFile() { - PsiElement element = getParent(); - - while (!(element instanceof AntFile)) { - if (element == null || element instanceof PsiFile ) { - return null; - } - element = element.getParent(); - } - - return (AntFile)element; - } - - public AntElement getParent() { - return myParent; - } - - @NotNull - public AntElement[] getChildren() { - synchronized (PsiLock.LOCK) { - if (myChildren == null) { - final AntFileImpl antFile = (AntFileImpl)getAntFile(); - if (antFile != null) { - antFile.buildPropertiesIfNeeded(); - } - } - if (myChildren != null) { - return myChildren; - } - return myChildren = getChildrenInner(); - } - } - - @Nullable - public AntElement getFirstChild() { - final AntElement[] children = getChildren(); - return children.length == 0 ? null : children[0]; - } - - @Nullable - public PsiElement getLastChild() { - final PsiElement[] children = getChildren(); - return children.length == 0 ? null : children[children.length - 1]; - } - - @Nullable - public PsiElement getNextSibling() { - if (myNext == null) { - final PsiElement parent = getAntParent(); - if (parent != null) { - PsiElement temp = null; - for (final PsiElement element : parent.getChildren()) { - if (temp != null) { - myNext = element; - break; - } - if (element == this) { - temp = element; - } - } - } - } - return myNext; - } - - @Nullable - public PsiElement getPrevSibling() { - if (myPrev == null) { - PsiElement prev = null; - final PsiElement parent = getAntParent(); - if (parent != null) { - for (final PsiElement element : parent.getChildren()) { - if (element == this) { - break; - } - prev = element; - } - } - myPrev = prev; - } - return myPrev; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - myChildren = null; - myReferences = null; - myPrev = null; - myNext = null; - incModificationCount(); - } - } - - public void incModificationCount() { - getAntFile().incModificationCount(); - } - - @Nullable - public AntElement lightFindElementAt(int offset) { - synchronized (PsiLock.LOCK) { - if (myChildren == null) { - return this; - } - final TextRange ownRange = getTextRange(); - final int offsetInFile = offset + ownRange.getStartOffset(); - for (final AntElement element : getChildren()) { - final TextRange textRange = element.getTextRange(); - if (textRange.contains(offsetInFile)) { - return element.lightFindElementAt(offsetInFile - textRange.getStartOffset()); - } - } - return ownRange.contains(offsetInFile) ? this : null; - } - } - - public PsiElement findElementAt(int offset) { - if (!isValid()) { - return null; - } - final TextRange ownRange = getTextRange(); - final int offsetInFile = offset + ownRange.getStartOffset(); - - for (final AntElement element : getChildren()) { - final TextRange textRange = element.getTextRange(); - if (textRange.contains(offsetInFile)) { - PsiElement elementAt = element.findElementAt(offsetInFile - textRange.getStartOffset()); - assert elementAt == null || elementAt.isValid() : element + ": " + offset; - return elementAt; - } - } - return ownRange.contains(offsetInFile)? this : null; - } - - public ASTNode getNode() { - return null; - } - - @NotNull - public PsiReference[] getReferences() { - if (myReferences != null) { - return myReferences; - } - final PsiReferenceProvider[] providers = AntReferenceProvidersRegistry.getProvidersByElement(this); - final List result = PsiReferenceListSpinAllocator.alloc(); - try { - for (final PsiReferenceProvider provider : providers) { - ContainerUtil.addAll(result, provider.getReferencesByElement(this, new ProcessingContext())); - } - return myReferences = result.toArray(new PsiReference[result.size()]); - } - finally { - PsiReferenceListSpinAllocator.dispose(result); - } - } - - public AntElementRole getRole() { - return AntElementRole.NULL_ROLE; - } - - public boolean canRename() { - return isPhysical(); - } - - public boolean isPhysical() { - return getSourceElement().isPhysical(); - } - - public boolean isValid() { - return getSourceElement().isValid(); - } - - - PsiManager myCachedManager; - public PsiManager getManager() { - PsiManager manager = myCachedManager; - if (manager == null) { - manager = getSourceElement().getManager(); - myCachedManager = manager; - } - return manager; - } - - protected AntElement[] getChildrenInner() { - return AntElement.EMPTY_ARRAY; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntElement(this); - } - - protected AntElement clone() { - final AntElementImpl element = (AntElementImpl)super.clone(); - element.clearCaches(); - return element; - } - - public Icon getElementIcon(int flags) { - return getRole().getIcon(); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntEntityRefImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntEntityRefImpl.java deleted file mode 100644 index b93c15cf33e6..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntEntityRefImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntEntityReference; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlElement; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class AntEntityRefImpl extends AntElementImpl { - - private PsiReference[] myRefs; - - public AntEntityRefImpl(final AntStructuredElement parent, final XmlElement sourceElement) { - super(parent, sourceElement); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myRefs = null; - } - } - - @NotNull - public PsiReference[] getReferences() { - synchronized (PsiLock.LOCK) { - if (myRefs == null) { - final List refList = PsiReferenceListSpinAllocator.alloc(); - try { - for (final PsiReference ref : getSourceElement().getReferences()) { - refList.add(new AntEntityReference(this, ref)); - } - myRefs = refList.toArray(new PsiReference[refList.size()]); - } - finally { - PsiReferenceListSpinAllocator.dispose(refList); - } - } - return myRefs; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileImpl.java deleted file mode 100644 index 058fbaee13c8..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileImpl.java +++ /dev/null @@ -1,1017 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.extapi.psi.LightPsiFileBase; -import com.intellij.lang.StdLanguages; -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.AntSupport; -import com.intellij.lang.ant.config.AntConfiguration; -import com.intellij.lang.ant.config.AntConfigurationBase; -import com.intellij.lang.ant.config.impl.AntBuildFileImpl; -import com.intellij.lang.ant.config.impl.AntConfigurationImpl; -import com.intellij.lang.ant.config.impl.AntInstallation; -import com.intellij.lang.ant.config.impl.GlobalAntConfiguration; -import com.intellij.lang.ant.misc.AntStringInterner; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.projectRoots.ProjectJdkTable; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiUtilBase; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.LocalTimeCounter; -import com.intellij.util.Processor; -import com.intellij.util.StringBuilderSpinAllocator; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.TaskContainer; -import org.apache.tools.ant.taskdefs.Property; -import org.apache.tools.ant.types.DataType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.io.File; -import java.io.IOException; -import java.util.*; - -@SuppressWarnings({"UseOfObsoleteCollectionType"}) -public class AntFileImpl extends LightPsiFileBase implements AntFile { - private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.psi.impl.AntFileImpl"); - @NonNls public static final String PROJECT_TAG = "project"; - @NonNls public static final String TARGET_TAG = "target"; - @NonNls public static final String IMPORT_TAG = "import"; - @NonNls public static final String FORMAT_TAG = "format"; - @NonNls public static final String JAVADOC2_TAG = "javadoc2"; - @NonNls public static final String JAVADOC_TAG = "javadoc"; - @NonNls public static final String UNWAR_TAG = "unwar"; - @NonNls public static final String UNJAR_TAG = "unjar"; - @NonNls public static final String PROPERTY = "property"; - - @NonNls public static final String UNZIP_TAG = "unzip"; - @NonNls public static final String NAME_ATTR = "name"; - @NonNls public static final String ID_ATTR = "id"; - @NonNls public static final String DEPENDS_ATTR = "depends"; - @NonNls public static final String IF_ATTR = "if"; - @NonNls public static final String UNLESS_ATTR = "unless"; - @NonNls public static final String DESCRIPTION_ATTR = "description"; - @NonNls public static final String DEFAULT_ATTR = "default"; - @NonNls public static final String BASEDIR_ATTR = "basedir"; - @NonNls public static final String FILE_ATTR = "file"; - @NonNls public static final String PREFIX_ATTR = "prefix"; - - @NonNls public static final String DEFAULT_ENVIRONMENT_PREFIX = "env."; - - private AntProject myProject; - private AntElement myPrologElement; - private AntElement myEpilogueElement; - private PsiElement[] myChildren; - - private ClassLoader myClassLoader; - private Hashtable myProjectProperties; - private boolean myNeedPropertiesRebuild = false; - private Map> myProperties; - private volatile AntProperty[] myPropertiesArray; - private volatile PropertiesWatcher myDependentFilesWatcher; - private List myEnvPrefixes; - - - /** - * Map of propeties set outside. - */ - private volatile Map myExternalProperties; - /** - * Map of class names to task definitions. - */ - private volatile Map myTypeDefinitions; - private volatile AntTypeDefinition[] myTypeDefinitionArray; - private volatile AntTypeDefinition myTargetDefinition; - /** - * Map of nested elements specially for the project element. - * It's updated together with the set of custom definitons. - */ - private volatile HashMap myProjectElements; - private long myModificationCount = 0; - - public AntFileImpl(final FileViewProvider viewProvider) { - super(viewProvider, AntSupport.getLanguage()); - AntConfiguration.initAntSupport(getProject()); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntFile(this); - } - - @NotNull - public FileType getFileType() { - return getViewProvider().getVirtualFile().getFileType(); - } - - public PsiElement getOriginalElement() { - return getSourceElement().getOriginalElement(); - } - - public VirtualFile getVirtualFile() { - return getSourceElement().getOriginalFile().getVirtualFile(); - } - - public AntElementRole getRole() { - return AntElementRole.NULL_ROLE; - } - - public boolean canRename() { - return isPhysical(); - } - - public void clearExternalProperties() { - synchronized (PsiLock.LOCK) { - myExternalProperties = null; - } - } - - public void setExternalProperty(@NotNull final String name, @NotNull final String value) { - synchronized (PsiLock.LOCK) { - if (myExternalProperties == null) { - myExternalProperties = new HashMap(); - } - myExternalProperties.put(name, value); - } - } - - @NotNull - public PsiElement[] getChildren() { - synchronized (PsiLock.LOCK) { - buildPropertiesIfNeeded(); - if (myChildren == null) { - final AntProject project = getAntProject(); - final ArrayList children = new ArrayList(3); - if (myPrologElement != null) { - children.add(myPrologElement); - } - children.add(project); - if (myEpilogueElement != null) { - children.add(myEpilogueElement); - } - myChildren = PsiUtilBase.toPsiElementArray(children); - } - return myChildren; - } - } - - public PsiElement getFirstChild() { - return getChildren()[0]; - } - - public PsiElement getLastChild() { - final PsiElement[] psiElements = getChildren(); - return psiElements[psiElements.length - 1]; - } - - public AntFileImpl copyLight(final FileViewProvider viewProvider) { - synchronized (PsiLock.LOCK) { - final AntFileImpl copy = new AntFileImpl(viewProvider); - - final HashMap defs; - if (myTypeDefinitions != null) { - defs = new HashMap(); - for (Map.Entry entry : myTypeDefinitions.entrySet()) { - final AntTypeDefinitionImpl original = (AntTypeDefinitionImpl)entry.getValue(); - if (original != null) { - defs.put(entry.getKey(), new AntTypeDefinitionImpl(original)); - } - } - } else { - defs = null; - } - copy.myTypeDefinitions = defs; - copy.myProjectElements = myProjectElements == null ? null : new HashMap(myProjectElements); - copy.myClassLoader = myClassLoader; - copy.myExternalProperties = myExternalProperties != null? new HashMap(myExternalProperties) : null; - if (myProperties != null) { - final HashMap> map = new HashMap>(); - for (Map.Entry> entry : myProperties.entrySet()) { - map.put(entry.getKey(), new ArrayList(entry.getValue())); - } - copy.myProperties = map; - } - else { - copy.myProperties = null; - } - - return copy; - } - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - public String toString() { - return "AntFile[" + getName() + "]"; - } - - @Nullable - public VirtualFile getContainingPath() { - VirtualFile result = getVirtualFile(); - return (result == null) ? null : result.getParent(); - } - - public void clearCachesWithTypeDefinitions() { - synchronized (PsiLock.LOCK) { - myTypeDefinitions = null; - myTypeDefinitionArray = null; - myTargetDefinition = null; - myProjectElements = null; - clearCaches(); - } - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - if (myChildren != null || myPrologElement != null || myProject != null || myEpilogueElement != null || myTargetDefinition != null || myClassLoader != null || myEnvPrefixes != null) { - myChildren = null; - myPrologElement = null; - myProject = null; - myEpilogueElement = null; - myTargetDefinition = null; - myClassLoader = null; - myEnvPrefixes = null; - incModificationCount(); - } - } - } - - public void invalidateProperties() { - synchronized (PsiLock.LOCK) { - myProperties = null; - myPropertiesArray = null; - myNeedPropertiesRebuild = true; - } - } - - public void incModificationCount() { - synchronized (PsiLock.LOCK) { - ++myModificationCount; - for (final AntFile file : AntSupport.getImportingFiles(this)) { - file.clearCaches(); - } - } - } - - public long getModificationCount() { - synchronized (PsiLock.LOCK) { - return myModificationCount; - } - } - - public void subtreeChanged() { - clearCaches(); - } - - @NotNull - public XmlFile getSourceElement() { - return (XmlFile)getViewProvider().getPsi(StdLanguages.XML); - } - - @NotNull - public ClassLoader getClassLoader() { - if (myClassLoader == null) { - final XmlFile xmlFile = getSourceElement(); - final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(xmlFile.getProject()).getAntBuildFile(xmlFile); - if (buildFile != null) { - myClassLoader = buildFile.getClassLoader(); - } - else { - final AntConfigurationBase configuration = AntConfigurationBase.getInstance(getProject()); - AntInstallation antInstallation = null; - if (configuration != null) { - antInstallation = configuration.getProjectDefaultAnt(); - } - if (antInstallation == null) { - antInstallation = GlobalAntConfiguration.getInstance().getBundledAnt(); - } - assert antInstallation != null; - myClassLoader = antInstallation.getClassLoader(); - } - } - return myClassLoader; - } - - @NotNull - public AntInstallation getAntInstallation() { - final XmlFile xmlFile = getSourceElement(); - final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(xmlFile.getProject()).getAntBuildFile(xmlFile); - if (buildFile != null) { - final AntInstallation assignedInstallation = AntBuildFileImpl.ANT_INSTALLATION.get(buildFile.getAllOptions()); - if (assignedInstallation != null) { - return assignedInstallation; - } - } - - final AntConfigurationBase configuration = AntConfigurationBase.getInstance(getProject()); - if (configuration != null) { - final AntInstallation projectDefaultInstallation = configuration.getProjectDefaultAnt(); - if (projectDefaultInstallation != null) { - return projectDefaultInstallation; - } - } - - return GlobalAntConfiguration.getInstance().getBundledAnt(); - } - - @Nullable - public Sdk getTargetJdk() { - final XmlFile xmlFile = getSourceElement(); - final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(xmlFile.getProject()).getAntBuildFile(xmlFile); - if (buildFile == null) { - return ProjectRootManager.getInstance(getProject()).getProjectSdk(); - } - - String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(buildFile.getAllOptions()); - if (jdkName == null || jdkName.length() == 0) { - jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(buildFile.getAllOptions()); - } - if (jdkName != null && jdkName.length() > 0) { - return ProjectJdkTable.getInstance().findJdk(jdkName); - } - return ProjectRootManager.getInstance(getProject()).getProjectSdk(); - } - - @Nullable - public AntElement getAntParent() { - return null; - } - - public AntFile getAntFile() { - return this; - } - - @Nullable - public AntProject getAntProject() { - boolean updateBuilFile = false; - try { - synchronized (PsiLock.LOCK) { - if (myProject == null) { - final XmlFile baseFile = getSourceElement(); - final XmlDocument document = baseFile.getDocument(); - assert document != null; - final XmlTag tag = document.getRootTag(); - if (tag == null) return null; - final CharSequence fileText = baseFile.getViewProvider().getContents(); - final TextRange tagRange = tag.getTextRange(); - final int projectStart = tagRange.getStartOffset(); - if (projectStart > 0) { - myPrologElement = new AntOuterProjectElement(this, 0, fileText.subSequence(0, projectStart).toString()); - } - final int projectEnd = tagRange.getEndOffset(); - if (projectEnd < fileText.length()) { - myEpilogueElement = new AntOuterProjectElement(this, projectEnd, fileText.subSequence(projectEnd, fileText.length()).toString()); - } - final AntProjectImpl project = new AntProjectImpl(this, tag, createProjectDefinition()); - myProject = project; - if (getSourceElement().isPhysical() || myProperties == null) { - buildPropertiesMap(); - } - for (final AntFile imported : project.getImportedFiles()) { - if (imported.isPhysical()) { - AntSupport.registerDependency(this, imported); - } - } - updateBuilFile = true; - } - return myProject; - } - } - finally { - if (updateBuilFile) { - //AntChangeVisitor.updateBuildFile(this); - } - } - } - - @Nullable - public AntProperty getProperty(final String name) { - return getPropertyRecursively(name, new HashSet()); - } - - public void processAllProperties(@NonNls String name, Processor processor) { - processAllPropertiesRecursively(name, new HashSet(), processor); - } - - @Nullable - private AntProperty getPropertyRecursively(final String name, final Set processed) { - if (name == null || processed.contains(this)) { - return null; - } - processed.add(this); - - try { - AntProperty antProperty; - - synchronized (PsiLock.LOCK) { - if (myProperties != null) { - final List antProperties = myProperties.get(name); - antProperty = antProperties != null && !antProperties.isEmpty()? antProperties.get(0) : null; - } - else { - antProperty = null; - } - } - - if (antProperty == null) { - final AntProject antProject = getAntProject(); - if (antProject != null) { - for (AntFile imported : antProject.getImportedFiles()) { - antProperty = (imported instanceof AntFileImpl) ? ((AntFileImpl)imported).getPropertyRecursively(name, processed) : imported.getProperty(name); - if (antProperty != null) { - break; - } - } - } - } - - return antProperty; - } - finally { - processed.remove(this); - } - } - - private void processAllPropertiesRecursively(final String name, final Set processed, Processor processor) { - if (name == null || processed.contains(this)) { - return; - } - processed.add(this); - - try { - synchronized (PsiLock.LOCK) { - if (myProperties != null) { - final List antProperties = myProperties.get(name); - if (antProperties != null) { - for (AntProperty property : antProperties) { - if (!processor.process(property)) { - return; - } - } - } - } - } - - final AntProject antProject = getAntProject(); - if (antProject != null) { - for (AntFile imported : antProject.getImportedFiles()) { - if (imported instanceof AntFileImpl) { - ((AntFileImpl)imported).processAllPropertiesRecursively(name, processed, processor); - } - else { - imported.processAllProperties(name, processor); - } - } - } - } - finally { - processed.remove(this); - } - } - - public void buildPropertiesIfNeeded() { - if (myNeedPropertiesRebuild || (myDependentFilesWatcher != null && myDependentFilesWatcher.needRebuildProperties())) { - buildPropertiesMap(); - } - } - - private void buildPropertiesMap() { - myNeedPropertiesRebuild = false; - myDependentFilesWatcher = null; - myProperties = new HashMap>(); - myPropertiesArray = null; - loadPredefinedProperties(myProjectProperties, myExternalProperties); - final List dependentFiles = PropertiesBuilder.defineProperties(this); - myDependentFilesWatcher = new PropertiesWatcher(dependentFiles); - } - - @SuppressWarnings({"UseOfObsoleteCollectionType"}) - private void loadPredefinedProperties(final Hashtable properties, final Map externalProps) { - final Enumeration props = (properties != null) ? properties.keys() : (new Hashtable()).keys(); - final @NonNls StringBuilder builder = StringBuilderSpinAllocator.alloc(); - builder.append(""); - try { - while (props.hasMoreElements()) { - final String name = (String)props.nextElement(); - final String value = (String)properties.get(name); - builder.append(""); - } - final Map envMap = System.getenv(); - for (final String name : envMap.keySet()) { - final String value = envMap.get(name); - if (name.length() > 0) { - builder.append(""); - } - } - if (externalProps != null) { - for (final String name : externalProps.keySet()) { - final String value = externalProps.get(name); - builder.append(""); - } - } - final VirtualFile file = getVirtualFile(); - final AntProject antProject = getAntProject(); - String basedir = antProject.getBaseDir(); - if (basedir == null) { - basedir = "."; - } - if (file != null && !FileUtil.isAbsolute(basedir)) { - final VirtualFile dir = file.getParent(); - if (dir != null) { - try { - basedir = new File(dir.getPath(), basedir).getCanonicalPath(); - } - catch (IOException e) { - // ignore - } - } - } - if (basedir != null) { - builder.append(""); - } - final AntInstallation installation = getAntInstallation(); - - builder.append(""); - builder.append(""); - builder.append(""); - builder.append(""); - if (file != null) { - final String path = file.getPath(); - builder.append(""); - if (name != null) { - builder.append(""); - } - } - builder.append(""); - final XmlFile xmlFile = (XmlFile)PsiFileFactory.getInstance(getProject()) - .createFileFromText("dummy.xml", StdFileTypes.XML, builder, LocalTimeCounter.currentTime(), false, false); - final XmlDocument document = xmlFile.getDocument(); - if (document == null) return; - final XmlTag rootTag = document.getRootTag(); - if (rootTag == null) return; - final AntTypeDefinition propertyDef = getAntFile().getBaseTypeDefinition(Property.class.getName()); - AntProject fakeProject = new AntProjectImpl(this, rootTag, antProject.getTypeDefinition()); - for (final XmlTag tag : rootTag.getSubTags()) { - final AntPropertyImpl property = new AntPropertyImpl(fakeProject, tag, propertyDef) { - public PsiFile getContainingFile() { - return getSourceElement().getContainingFile(); - } - - public PsiElement getNavigationElement() { - if (AntFileImpl.BASEDIR_ATTR.equals(getName())) { - final XmlAttribute attr = antProject.getSourceElement().getAttribute(AntFileImpl.BASEDIR_ATTR, null); - if (attr != null) { - return attr; - } - } - return super.getNavigationElement(); - } - }; - appendProperty(property.getName(), property); - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - - public void setProperty(final String name, final AntProperty element) { - synchronized (PsiLock.LOCK) { - if (myNeedPropertiesRebuild) { - buildPropertiesMap(); - } - appendProperty(name, element); - } - } - - private void appendProperty(String name, AntProperty element) { - if (myProperties == null) { - myProperties = new HashMap>(); - } - List props = myProperties.get(name); - if (props == null) { - myProperties.put(name, props = new ArrayList()); - } - props.add(element); - myPropertiesArray = null; - } - - @NotNull - public AntProperty[] getProperties() { - synchronized (PsiLock.LOCK) { - if (myNeedPropertiesRebuild) { - buildPropertiesMap(); - } - if (myProperties == null) { - return AntProperty.EMPTY_ARRAY; - } - if (myPropertiesArray == null) { - final List props = new ArrayList(myProperties.size()); - for (List list : myProperties.values()) { - if (!list.isEmpty()) { - props.add(list.get(0)); - } - } - myPropertiesArray = props.toArray(new AntProperty[props.size()]); - } - return myPropertiesArray; - } - } - - public void addEnvironmentPropertyPrefix(@NotNull final String envPrefix) { - synchronized (PsiLock.LOCK) { - checkEnvList(); - final String env = (envPrefix.endsWith(".")) ? envPrefix : envPrefix + '.'; - if (myEnvPrefixes.indexOf(env) < 0) { - myEnvPrefixes.add(env); - for (final AntProperty element : getProperties()) { - final String name = element.getName(); - if (name != null && name.startsWith(DEFAULT_ENVIRONMENT_PREFIX)) { - setProperty(env + name.substring(DEFAULT_ENVIRONMENT_PREFIX.length()), element); - } - } - } - } - } - - public boolean isEnvironmentProperty(@NotNull final String propName) { - synchronized (PsiLock.LOCK) { - checkEnvList(); - if (!propName.endsWith(".")) { - for (final String prefix : myEnvPrefixes) { - if (propName.startsWith(prefix)) { - return true; - } - } - } - return false; - } - } - - public List getEnvironmentPrefixes() { - synchronized (PsiLock.LOCK) { - checkEnvList(); - return myEnvPrefixes; - } - } - - - private void checkEnvList() { - if (myEnvPrefixes == null) { - myEnvPrefixes = new ArrayList(); - myEnvPrefixes.add(DEFAULT_ENVIRONMENT_PREFIX); - } - } - - public AntElement lightFindElementAt(int offset) { - synchronized (PsiLock.LOCK) { - if (myProject == null) return this; - final TextRange projectRange = myProject.getTextRange(); - if (offset < projectRange.getStartOffset() || offset >= projectRange.getEndOffset()) return this; - final AntElement prolog = myPrologElement; - return myProject.lightFindElementAt(offset - ((prolog == null) ? 0 : prolog.getTextLength())); - } - } - - @NotNull - public AntTypeDefinition[] getBaseTypeDefinitions() { - synchronized (PsiLock.LOCK) { - if (myTypeDefinitionArray == null || myTypeDefinitions == null || myTypeDefinitionArray.length != myTypeDefinitions.size()) { - buildTypeDefinitions(); - myTypeDefinitionArray = myTypeDefinitions.values().toArray(new AntTypeDefinition[myTypeDefinitions.size()]); - } - return myTypeDefinitionArray; - } - } - - @Nullable - public AntTypeDefinition getBaseTypeDefinition(final String className) { - synchronized (PsiLock.LOCK) { - buildTypeDefinitions(); - return lookupTypeDefinition(className); - } - } - - private void buildTypeDefinitions() { - if (myTypeDefinitions == null) { - myTypeDefinitions = new HashMap(); - myProjectElements = new HashMap(); - final ReflectedProject reflectedProject = ReflectedProject.getProject(getClassLoader()); - if (reflectedProject.getProject() != null) { - //first, create task definitons - updateTypeDefinitions(reflectedProject.getTaskDefinitions(), true); - // second, create definitions of data types - updateTypeDefinitions(reflectedProject.getDataTypeDefinitions(), false); - myProjectProperties = reflectedProject.getProperties(); - } - } - } - - @Nullable /*will return null in case ant installation is not properly configured*/ - public AntTypeDefinition getTargetDefinition() { - synchronized (PsiLock.LOCK) { - buildTypeDefinitions(); - if (myTargetDefinition == null) { - final Class targetClass = ReflectedProject.getProject(getClassLoader()).getTargetClass(); - final AntTypeDefinition targetDef = createTypeDefinition(new AntTypeId(TARGET_TAG), targetClass, false); - if (targetDef != null) { - for (final AntTypeDefinition def : getBaseTypeDefinitions()) { - final AntTypeId id = def.getTypeId(); - if (canBeUsedInTarget(def)) { - targetDef.registerNestedType(id, def.getClassName()); - } - } - myTargetDefinition = targetDef; - registerCustomType(targetDef); - } - } - return myTargetDefinition; - } - } - - private boolean canBeUsedInTarget(final AntTypeDefinition def) { - // if type definition is a task _and_ is visible at the project level - // custom tasks can define nested types with the same typeId (e.g. "property") but different implementation class - // such nested types can be used only inside tasks which defined them, but not at a project level - return (def.isTask() || isDataDype(def)) && isProjectNestedElement(def); - } - - private boolean isDataDype(final AntTypeDefinition def) { - try { - final ClassLoader loader = getClassLoader(); - final String className = def.getClassName(); - if (className.startsWith(AntMacroDefImpl.ANT_MACRODEF_NAME) || className.startsWith(AntPresetDefImpl.ANT_PRESETDEF_NAME)) { - return false; - } - final Class defClass = loader.loadClass(className); - final Class dataTypeClass = loader.loadClass(DataType.class.getName()); - return dataTypeClass.isAssignableFrom(defClass); - } - catch (ClassNotFoundException e) { - return false; - } - } - - private boolean isProjectNestedElement(final AntTypeDefinition def) { - final AntTypeId id = def.getTypeId(); - if (myProject != null) { - final AntTypeDefinition projectDef = myProject.getTypeDefinition(); - if (projectDef != null) { - return def.getClassName().equals(projectDef.getNestedClassName(id)); - } - } - return def.getClassName().equals(myProjectElements.get(id)); - } - - public void registerCustomType(final AntTypeDefinition def) { - synchronized (PsiLock.LOCK) { - buildTypeDefinitions(); - addTypeDefinition(def); - if (myTargetDefinition != null && myTargetDefinition != def) { - if (canBeUsedInTarget(def)) { - myTargetDefinition.registerNestedType(def.getTypeId(), def.getClassName()); - } - } - } - } - - private AntTypeDefinition lookupTypeDefinition(final String className) { - return myTypeDefinitions.get(className); - } - - private void addTypeDefinition(final AntTypeDefinition def) { - myTypeDefinitions.put(def.getClassName(), def); - myTypeDefinitionArray = null; - } - - private void removeTypeDefinition(final AntTypeDefinition def) { - final AntTypeDefinition definition = myTypeDefinitions.remove(def.getClassName()); - if (definition != null) { - definition.setOutdated(true); - } - myTypeDefinitionArray = null; - } - - public void unregisterCustomType(final AntTypeDefinition def) { - synchronized (PsiLock.LOCK) { - if (myTypeDefinitions != null) { - removeTypeDefinition(def); - } - if (myProjectElements != null) { - final String registeredClassName = myProjectElements.get(def.getTypeId()); - if (registeredClassName != null && registeredClassName.equals(def.getClassName())) { - myProjectElements.remove(def.getTypeId()); - } - } - if (myTargetDefinition != null && myTargetDefinition != def) { - myTargetDefinition.unregisterNestedType(def.getTypeId()); - } - } - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private void updateTypeDefinitions(final Hashtable ht, final boolean isTask) { - if (ht == null) return; - final Enumeration types = ht.keys(); - while (types.hasMoreElements()) { - String typeName = (String)types.nextElement(); - /** - * Hardcode for task (IDEADEV-6731). - */ - if (isTask && typeName.equals(JAVADOC2_TAG)) { - typeName = JAVADOC_TAG; - } - /** - * Hardcode for and tasks (IDEADEV-6830). - */ - if (isTask && (typeName.equals(UNWAR_TAG) || typeName.equals(UNJAR_TAG))) { - typeName = UNZIP_TAG; - } - - final Class typeClass = (Class)ht.get(typeName); - final AntTypeId typeId = new AntTypeId(typeName); - final AntTypeDefinition def = createTypeDefinition(typeId, typeClass, isTask); - if (def != null) { - final String className = def.getClassName(); - addTypeDefinition(def); - myProjectElements.put(typeId, className); - /** - * some types are defined only as nested elements, project doesn't return their classes - * these elements can exist only in context of another element and are defined as subclasses of its class - * so we should manually update our type definitions map with such elements - */ - registerNestedDefinitionsRecursively(typeClass); - } - } - } - - private void registerNestedDefinitionsRecursively(final Class parentClass) { - final AntIntrospector helper = getHelperExceptionSafe(parentClass); - if (helper != null) { - final Enumeration nestedEnum = helper.getNestedElements(); - while (nestedEnum.hasMoreElements()) { - final String nestedElement = (String)nestedEnum.nextElement(); - final Class nestedElementClass = helper.getElementType(nestedElement); - if (nestedElementClass != null && lookupTypeDefinition(nestedElementClass.getName()) == null) { - final AntTypeDefinition nestedDef = createTypeDefinition(new AntTypeId(nestedElement), nestedElementClass, false); - if (nestedDef != null) { - addTypeDefinition(nestedDef); - registerNestedDefinitionsRecursively(nestedElementClass); - } - } - } - } - } - - private AntTypeDefinition createProjectDefinition() { - buildTypeDefinitions(); - @NonNls final HashMap projectAttrs = new HashMap(); - projectAttrs.put(NAME_ATTR, AntAttributeType.STRING); - projectAttrs.put(DEFAULT_ATTR, AntAttributeType.STRING); - projectAttrs.put(BASEDIR_ATTR, AntAttributeType.STRING); - final AntTypeDefinition def = getTargetDefinition(); - if (def != null) { - myProjectElements.put(def.getTypeId(), def.getClassName()); - } - return new AntTypeDefinitionImpl(new AntTypeId(PROJECT_TAG), Project.class.getName(), false, false, projectAttrs, myProjectElements); - } - - @Nullable - static AntTypeDefinition createTypeDefinition(final AntTypeId id, final Class typeClass, final boolean isTask) { - final AntIntrospector helper = getHelperExceptionSafe(typeClass); - if (helper == null) { - return null; - } - final HashMap attributes = new HashMap(); - final Enumeration attrEnum = helper.getAttributes(); - while (attrEnum.hasMoreElements()) { - final String attr = AntStringInterner.intern(((String)attrEnum.nextElement()).toLowerCase(Locale.US)); - attributes.put(attr, AntAttributeType.create(helper.getAttributeType(attr))); - } - final HashMap nestedDefinitions = new HashMap(); - final Enumeration nestedEnum = helper.getNestedElements(); - while (nestedEnum.hasMoreElements()) { - final String nestedElement = (String)nestedEnum.nextElement(); - final Class elementType = helper.getElementType(nestedElement); - if (elementType != null) { - final String className = AntStringInterner.intern((elementType.getName())); - nestedDefinitions.put(new AntTypeId(nestedElement), className); - } - } - - boolean isAllTasksContainer = false; - final ClassLoader loader = typeClass.getClassLoader(); - try { - final Class containerClass = loader != null? loader.loadClass(TaskContainer.class.getName()) : TaskContainer.class; - isAllTasksContainer = containerClass.isAssignableFrom(typeClass); - } - catch (ClassNotFoundException ignored) { - } - return new AntTypeDefinitionImpl(id, typeClass.getName(), isTask, isAllTasksContainer, attributes, nestedDefinitions, helper.getExtensionPointTypes(), null); - } - - @Nullable - private static AntIntrospector getHelperExceptionSafe(Class c) { - try { - return AntIntrospector.getInstance(c); - } - catch (Throwable ignored) { - } - return null; - } - - public Icon getElementIcon(int flags) { - return getRole().getIcon(); - } - - private static class PropertiesWatcher { - private final List myDependentFiles; - private final long[] myStamps; - - public PropertiesWatcher(List dependentFiles) { - myDependentFiles = dependentFiles; - myStamps = new long[dependentFiles.size()]; - - int index = 0; - for (PsiFile file : dependentFiles) { - myStamps[index++] = file.getModificationStamp(); - } - } - - public boolean needRebuildProperties() { - int idx = 0; - for (PsiFile file : myDependentFiles) { - if (myStamps[idx++] != file.getModificationStamp()) { - return true; - } - } - return false; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileListImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileListImpl.java deleted file mode 100644 index de9af18e095b..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileListImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.*; - -/** - * @author Eugene Zhuravlev - * Date: May 4, 2007 - */ -public class AntFileListImpl extends AntFilesProviderImpl{ - public AntFileListImpl(final AntElement parent, final XmlTag sourceElement) { - super(parent, sourceElement); - } - - public AntFileListImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition, @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntFileListImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - protected AntPattern getPattern() { - return null; // not available for this data type - } - - @NotNull - protected List getFiles(final AntPattern pattern, final Set processed) { - final File root = getCanonicalFile(computeAttributeValue(getSourceElement().getAttributeValue("dir"))); - if (root == null) { - return Collections.emptyList(); - } - - final ArrayList files = new ArrayList(); - - final String filenames = getSourceElement().getAttributeValue("files"); - if (filenames != null) { - final StringTokenizer tokenizer = new StringTokenizer(filenames, ", \t\n\r\f", false); - while (tokenizer.hasMoreTokens()) { - files.add(new File(root, tokenizer.nextToken())); - } - } - - final AntElement[] children = getChildren(); - final AntTypeDefinition selfTypeDef = getTypeDefinition(); - if (selfTypeDef != null) { - for (AntElement child : children) { - if (child instanceof AntStructuredElement) { - final AntStructuredElement se = (AntStructuredElement)child; - final AntTypeDefinition typeDef = se.getTypeDefinition(); - if (typeDef != null && selfTypeDef.getNestedClassName(typeDef.getTypeId()) != null) { - final String fileName = computeAttributeValue(se.getSourceElement().getAttributeValue("name")); - if (fileName != null) { - files.add(new File(root, fileName)); - } - } - } - } - } - return files; - } -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileSetImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileSetImpl.java deleted file mode 100644 index 92ccfbc5caa7..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFileSetImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * @author Eugene Zhuravlev - * Date: May 4, 2007 - */ -public class AntFileSetImpl extends AntFilesProviderImpl{ - public AntFileSetImpl(final AntElement parent, final XmlTag sourceElement) { - super(parent, sourceElement); - } - - public AntFileSetImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition, @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntFileSetImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - @NotNull - protected List getFiles(final AntPattern pattern, final Set processed) { - final File singleFile = getCanonicalFile(computeAttributeValue(getSourceElement().getAttributeValue("file"))); - if (singleFile == null || pattern.hasIncludePatterns()) { - // if singleFile is specified, there are no implicit includes - final File root = getCanonicalFile(computeAttributeValue(getSourceElement().getAttributeValue("dir"))); - if (root != null) { - final ArrayList files = new ArrayList(); - if (singleFile != null) { - files.add(singleFile); - } - new FilesCollector().collectFiles(files, root, "", pattern); - return files; - } - } - if (singleFile != null) { - return Collections.singletonList(singleFile); - } - return Collections.emptyList(); - } - - private static class FilesCollector { - private static final int MAX_DIRS_TO_PROCESS = 100; - private int myDirsProcessed = 0; - private boolean myDirCheckEnabled = false; - - public void collectFiles(List container, File from, String relativePath, final AntPattern pattern) { - if (myDirsProcessed > MAX_DIRS_TO_PROCESS) { - return; - } - final File[] children = from.listFiles(); - if (children != null && children.length > 0) { - if (myDirCheckEnabled) { - if (!pattern.couldBeIncluded(relativePath)) { - return; - } - } - else { - myDirCheckEnabled = true; - } - myDirsProcessed++; - for (File child : children) { - final String childPath = makePath(relativePath, child.getName()); - if (pattern.acceptPath(childPath)) { - container.add(child); - } - collectFiles(container, child, childPath, pattern); - } - } - } - - private static String makePath(final String parentPath, final String name) { - if (parentPath.length() == 0) { - return name; - } - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - return builder.append(parentPath).append("/").append(name).toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFilesProviderImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFilesProviderImpl.java deleted file mode 100644 index 4c18be5418e2..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntFilesProviderImpl.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.impl.reference.AntRefIdReference; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiLock; -import com.intellij.psi.PsiReference; -import com.intellij.psi.xml.XmlTag; -import com.intellij.reference.SoftReference; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * @author Eugene Zhuravlev - * Date: May 4, 2007 - */ -public class AntFilesProviderImpl extends AntStructuredElementImpl implements AntFilesProvider { - - private AntPattern myPattern; - private volatile SoftReference> myCachedFiles; - - public AntFilesProviderImpl(final AntElement parent, final XmlTag sourceElement) { - super(parent, sourceElement); - } - - public AntFilesProviderImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition, @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntFilesProviderImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myPattern = null; - clearCachedFiles(); - final AntElement parent = getAntParent(); - if (parent != null) { - parent.clearCaches(); - } - } - } - - public void clearCachedFiles() { - synchronized (PsiLock.LOCK) { - myCachedFiles = null; - } - } - - @NotNull - public final List getFiles(final Set processed) { - if (processed.contains(this)) { - return Collections.emptyList(); - } - List result = myCachedFiles == null? null : myCachedFiles.get(); - if (result == null) { - result = getFilesImpl(processed); - myCachedFiles = new SoftReference>(result); - } - return result; - } - - private List getFilesImpl(final Set processed) { - processed.add(this); - try { - final AntFilesProvider referenced = getReferencedProvider(); - if (referenced != null) { - return referenced.getFiles(processed); - } - return getFiles(getPattern(), processed); - } - finally { - processed.remove(this); - } - } - - @NotNull - protected List getFiles(AntPattern pattern, final Set processed) { - return Collections.emptyList(); - } - - protected AntPattern getPattern() { - synchronized (PsiLock.LOCK) { - if (myPattern == null) { - myPattern = AntPattern.create(this, shouldHonorDefaultExcludes(), matchPatternsCaseSensitive()); - } - return myPattern; - } - } - - - @Nullable - private AntFilesProvider getReferencedProvider() { - final PsiReference[] references = getReferences(); - for (PsiReference reference : references) { - if (reference instanceof AntRefIdReference) { - final PsiElement psiElement = reference.resolve(); - if (psiElement instanceof AntFilesProvider) { - return (AntFilesProvider)psiElement; - } - } - } - return null; - } - - private boolean shouldHonorDefaultExcludes() { - @NonNls final String value = getSourceElement().getAttributeValue("defaultexcludes"); - return value == null || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true"); - } - - private boolean matchPatternsCaseSensitive() { - @NonNls final String value = getSourceElement().getAttributeValue("casesensitive"); - return value == null || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true"); - } - - @Nullable - protected File getCanonicalFile(final String path) { - if (path == null) { - return null; - } - try { - final File file = new File(path); - if (file.isAbsolute()) { - return file.getCanonicalFile(); - } - final String baseDir = computeAttributeValue("${" + AntFileImpl.BASEDIR_ATTR + "}"); - if (baseDir == null) { - return null; - } - return new File(baseDir, path).getCanonicalFile(); - } - catch (IOException e) { - return null; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportImpl.java deleted file mode 100644 index a0313359c1e3..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntImportImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntSupport; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntImport; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; - -public class AntImportImpl extends AntTaskImpl implements AntImport { - - public AntImportImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntImport(this); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntImport["); - builder.append(getSourceElement().getAttributeValue(AntFileImpl.FILE_ATTR)); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @NotNull - public List getFileReferenceAttributes() { - return Collections.singletonList(AntFileImpl.FILE_ATTR); - } - - @Nullable - public String getFileName() { - return computeAttributeValue(getSourceElement().getAttributeValue(AntFileImpl.FILE_ATTR)); - } - - public AntFile getImportedFile() { - return getImportedFile(getFileName(), this); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - getAntFile().clearCaches(); - } - } - - @Nullable - static AntFile getImportedFile(final String name, final AntStructuredElementImpl element) { - if (name == null) return null; - final PsiFile psiFile = element.findFileByName(name); - if (psiFile != null) { - if (psiFile instanceof XmlFile) { - final VirtualFile file = psiFile.getVirtualFile(); - if (file != null) { - //AntSupport.markFileAsAntFile(file, psiFile.getViewProvider(), true); - } - return AntSupport.getAntFile(psiFile); - } - if (psiFile instanceof AntFile) return (AntFile)psiFile; - } - return null; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntMacroDefImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntMacroDefImpl.java deleted file mode 100644 index 7fb4463de69b..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntMacroDefImpl.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.psi.PsiLock; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -public class AntMacroDefImpl extends AntTaskImpl implements AntMacroDef { - - @NonNls public static final String ANT_MACRODEF_NAME = "AntMacroDef"; - - private AntTypeDefinitionImpl myMacroDefinition; - - public AntMacroDefImpl(final AntStructuredElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - invalidateMacroDefinition(); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntMacroDef(this); - } - - public String toString() { - return createMacroClassName(getName()); - } - - public static String createMacroClassName(final String macroName) { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(ANT_MACRODEF_NAME); - builder.append("["); - builder.append(macroName); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntElementRole getRole() { - return AntElementRole.MACRODEF_ROLE; - } - - - public AntTypeDefinition getMacroDefinition() { - return myMacroDefinition; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - clearClassesCache(); - getAntFile().clearCaches(); - } - } - - public void clearClassesCache() { - synchronized (PsiLock.LOCK) { - if (myMacroDefinition != null) { - final AntFile file = getAntFile(); - for (AntTypeId id : myMacroDefinition.getNestedElements()) { - final AntTypeDefinition nestedDef = file.getBaseTypeDefinition(myMacroDefinition.getNestedClassName(id)); - if (nestedDef != null) { - file.unregisterCustomType(nestedDef); - } - } - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.unregisterCustomType(myMacroDefinition); - } - myMacroDefinition = null; - } - } - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private void invalidateMacroDefinition() { - if (!hasNameElement()) { - myMacroDefinition = null; - return; - } - - final AntFile file = getAntFile(); - if (file == null) return; - - final String thisClassName = createMacroClassName(getName()); - myMacroDefinition = (AntTypeDefinitionImpl)file.getBaseTypeDefinition(thisClassName); - final Map attributes = - (myMacroDefinition == null) ? new HashMap() : myMacroDefinition.getAttributesMap(); - attributes.clear(); - final Map nestedElements = - (myMacroDefinition == null) ? new HashMap() : myMacroDefinition.getNestedElementsMap(); - for (AntElement child : getChildren()) { - if (child instanceof AntStructuredElement) { - final AntStructuredElement se = (AntStructuredElement)child; - final String name = se.getName(); - if (name != null) { - final String tagName = se.getSourceElement().getName(); - if (tagName.equals("attribute")) { - attributes.put(name.toLowerCase(Locale.US), AntAttributeType.STRING); - } - else if (tagName.equals("element")) { - final String elementClassName = thisClassName + '$' + name; - AntTypeDefinitionImpl nestedDef = (AntTypeDefinitionImpl)file.getBaseTypeDefinition(elementClassName); - if (nestedDef == null) { - final AntTypeDefinitionImpl targetDef = (AntTypeDefinitionImpl)file.getTargetDefinition(); - if (targetDef != null) { - nestedDef = new AntTypeDefinitionImpl(targetDef); - } - } - if (nestedDef != null) { - final AntTypeId typeId = new AntTypeId(name); - nestedDef.setTypeId(typeId); - nestedDef.setClassName(elementClassName); - nestedDef.setIsTask(false); - nestedDef.setDefiningElement(child); - file.registerCustomType(nestedDef); - nestedElements.put(typeId, nestedDef.getClassName()); - } - } - } - } - } - final AntTypeId definedTypeId = new AntTypeId(getName()); - if (myMacroDefinition == null) { - myMacroDefinition = new AntTypeDefinitionImpl(definedTypeId, thisClassName, true, false, attributes, nestedElements, this); - } - else { - myMacroDefinition.setTypeId(definedTypeId); - myMacroDefinition.setClassName(thisClassName); - myMacroDefinition.setIsTask(true); - myMacroDefinition.setDefiningElement(this); - } - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.registerCustomType(myMacroDefinition); - } - // define itself as nested task for sequential - final AntAllTasksContainerImpl sequential = PsiTreeUtil.getChildOfType(this, AntAllTasksContainerImpl.class); - if (sequential != null) { - sequential.registerCustomType(myMacroDefinition); - for (final AntTypeId id : myMacroDefinition.getNestedElements()) { - sequential.registerCustomType(file.getBaseTypeDefinition(myMacroDefinition.getNestedClassName(id))); - } - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntNameIdentifierImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntNameIdentifierImpl.java deleted file mode 100644 index 15ecc3aa4977..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntNameIdentifierImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntNameIdentifier; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiManager; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -public class AntNameIdentifierImpl extends AntElementImpl implements AntNameIdentifier { - - private String myCachedName; - private volatile long myModCount; - - public AntNameIdentifierImpl(final AntElement parent, final XmlAttributeValue sourceElement) { - super(parent, sourceElement); - } - - @NotNull - public XmlAttributeValue getSourceElement() { - return (XmlAttributeValue)super.getSourceElement(); - } - - public TextRange getTextRange() { - return getSourceElement().getValueTextRange(); - } - - public String getText() { - return getName(); - } - - public int getTextOffset() { - return getTextRange().getStartOffset(); - } - - public int getTextLength() { - return getText().length(); - } - - public String getName() { - return getIdentifierName(); - } - - public String getIdentifierName() { - String name = myCachedName; - final PsiManager psiManager = getManager(); - final long modificationCount = psiManager != null? psiManager.getModificationTracker().getModificationCount() : myModCount; - if (name != null && myModCount == modificationCount) { - return name; - } - myModCount = modificationCount; - name = getSourceElement().getValue(); - myCachedName = name; - return name; - } - - public void setIdentifierName(@NotNull String name) throws IncorrectOperationException { - final XmlAttribute attr = PsiTreeUtil.getParentOfType(getSourceElement(), XmlAttribute.class, true); - if (attr != null) { - attr.setValue(name); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntOuterProjectElement.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntOuterProjectElement.java deleted file mode 100644 index 0eb2f9d5e4a6..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntOuterProjectElement.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiManager; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -/** - * element for wrapping xml out of the project tag, that can be xml prolog or smth - */ -public class AntOuterProjectElement extends AntElementImpl { - private final int myStartOffset; - private final String myText; - - public AntOuterProjectElement(final AntFile parent, final int startOffset, final String text) { - super(parent, null); - myStartOffset = startOffset; - myText = text; - } - - @NonNls - public String toString() { - return "XmlText: " + myText; - } - - public boolean isPhysical() { - return getParent().isPhysical(); - } - - public boolean isValid() { - return getParent().isValid(); - } - - public PsiManager getManager() { - return getParent().getManager(); - } - - public TextRange getTextRange() { - return new TextRange(myStartOffset, myStartOffset + myText.length()); - } - - public int getTextLength() { - return myText.length(); - } - - public int getTextOffset() { - return myStartOffset; - } - - public String getText() { - return myText; - } - - @NotNull - public char[] textToCharArray() { - return myText.toCharArray(); - } - - public boolean textContains(char c) { - return myText.indexOf(c, 0) >= 0; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPathImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPathImpl.java deleted file mode 100644 index ea170152a718..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPathImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFilesProvider; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import org.apache.tools.ant.PathTokenizer; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * @author Eugene Zhuravlev - * Date: May 5, 2007 - */ -public class AntPathImpl extends AntFilesProviderImpl{ - public AntPathImpl(final AntElement parent, final XmlTag sourceElement) { - super(parent, sourceElement); - } - - public AntPathImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition, @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntPathImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - protected AntPattern getPattern() { - return null; // not available - } - - @NotNull - protected List getFiles(final AntPattern pattern, final Set processed) { - final List files = new ArrayList(); - final File baseDir = getCanonicalFile("."); - - addLocation(baseDir, files, computeAttributeValue(getSourceElement().getAttributeValue("location"))); - - final String pathString = computeAttributeValue(getSourceElement().getAttributeValue("path")); - if (pathString != null) { - final PathTokenizer tokenizer = new PathTokenizer(pathString); - while (tokenizer.hasMoreTokens()) { - addLocation(baseDir, files, tokenizer.nextToken()); - } - } - - final AntElement[] children = getChildren(); - for (AntElement child : children) { - if (child instanceof AntFilesProvider) { - files.addAll(((AntFilesProvider)child).getFiles(processed)); - } - } - return files; - } - - private static void addLocation(final File baseDir, final List files, final String locationPath) { - if (locationPath != null) { - File file = new File(locationPath); - if (file.isAbsolute()) { - files.add(file); - } - else { - files.add(new File(baseDir, locationPath)); - } - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPattern.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPattern.java deleted file mode 100644 index f23d8b27d6f6..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPattern.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntRefIdReference; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.NonNls; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.StringTokenizer; -import java.util.regex.Pattern; - -/** - * @author Eugene Zhuravlev - * Date: May 2, 2007 - */ -public class AntPattern extends AntElementVisitor { - private static final List ourDefaultExcludes = new ArrayList(getDefaultExcludes(true)); - private static final List ourCaseInsensitiveDefaultExcludes = new ArrayList(getDefaultExcludes(false)); - private final boolean myCaseSensitive; - private static final String ourSeparatorPattern = Pattern.quote("/"); - - private static List getDefaultExcludes(final boolean caseSensitive) { - return Arrays.asList( - convertToRegexPattern("**/*~", caseSensitive), - convertToRegexPattern("**/#*#", caseSensitive), - convertToRegexPattern("**/.#*", caseSensitive), - convertToRegexPattern("**/%*%", caseSensitive), - convertToRegexPattern("**/._*", caseSensitive), - convertToRegexPattern("**/CVS", caseSensitive), - convertToRegexPattern("**/CVS/**", caseSensitive), - convertToRegexPattern("**/.cvsignore", caseSensitive), - convertToRegexPattern("**/SCCS", caseSensitive), - convertToRegexPattern("**/SCCS/**", caseSensitive), - convertToRegexPattern("**/vssver.scc", caseSensitive), - convertToRegexPattern("**/.svn", caseSensitive), - convertToRegexPattern("**/.svn/**", caseSensitive), - convertToRegexPattern("**/_svn", caseSensitive), - convertToRegexPattern("**/_svn/**", caseSensitive), - convertToRegexPattern("**/.DS_Store", caseSensitive) - ); - } - - private final List myIncludePatterns = new ArrayList(); - private final List myExcludePatterns = new ArrayList(); - private final List myCouldBeIncludedPatterns = new ArrayList(); - - AntPattern(final boolean caseSensitive) { - myCaseSensitive = caseSensitive; - } - - public boolean hasIncludePatterns() { - return myIncludePatterns.size() > 0; - } - - @Override public void visitAntStructuredElement(final AntStructuredElement element) { - final AntTypeDefinition typeDef = element.getTypeDefinition(); - if (typeDef != null) { - final AntTypeId antTypeId = typeDef.getTypeId(); - // todo: add support to includefile and excludefile - if ("include".equals(antTypeId.getName())) { - if (isEnabled(element)) { - final String value = element.computeAttributeValue(element.getSourceElement().getAttributeValue("name")); - if (value != null) { - addIncludePattern(value); - } - } - } - else if ("exclude".equals(antTypeId.getName())) { - if (isEnabled(element)) { - final String value = element.computeAttributeValue(element.getSourceElement().getAttributeValue("name")); - if (value != null) { - addExcludePattern(value); - } - } - } - else { - // todo: add support to includesfile and excludesfile - final String includeAttribs = element.computeAttributeValue(element.getSourceElement().getAttributeValue("includes")); - if (includeAttribs != null) { - addPatterns(true, includeAttribs); - } - final String excludeAttribs = element.computeAttributeValue(element.getSourceElement().getAttributeValue("excludes")); - if (excludeAttribs != null) { - addPatterns(false, excludeAttribs); - } - } - final PsiReference[] refs = element.getReferences(); - for (PsiReference ref : refs) { - if (ref instanceof AntRefIdReference) { - final PsiElement psiElement = ref.resolve(); - if (psiElement instanceof AntStructuredElement) { - ((AntStructuredElement)psiElement).acceptAntElementVisitor(this); - } - } - } - } - - super.visitAntStructuredElement(element); - } - - public final void addExcludePattern(final String antPattern) { - myExcludePatterns.add(convertToRegexPattern(antPattern, myCaseSensitive)); - } - - public final void addIncludePattern(final String antPattern) { - myIncludePatterns.add(convertToRegexPattern(antPattern, myCaseSensitive)); - String normalizedPattern = antPattern.endsWith("/") || antPattern.endsWith(File.separator)? antPattern.replace(File.separatorChar, '/') + "**" : antPattern.replace(File.separatorChar, '/'); - if (normalizedPattern.startsWith("/") && normalizedPattern.length() > 1) { - // cut first leading slash if any - normalizedPattern = normalizedPattern.substring(1, normalizedPattern.length()); - } - if (!normalizedPattern.startsWith("/")) { - final String[] patDirs = normalizedPattern.split(ourSeparatorPattern); - final PrefixItem[] items = new PrefixItem[patDirs.length]; - for (int i = 0; i < patDirs.length; i++) { - items[i] = new PrefixItem(patDirs[i]); - } - myCouldBeIncludedPatterns.add(items); - } - } - - public boolean acceptPath(final String relativePath) { - final String path = relativePath.replace('\\', '/'); - boolean accepted = myIncludePatterns.size() == 0; - for (Pattern includePattern : myIncludePatterns) { - if (includePattern.matcher(path).matches()) { - accepted = true; - break; - } - } - if (accepted) { - for (Pattern excludePattern : myExcludePatterns) { - if (excludePattern.matcher(path).matches()) { - accepted = false; - break; - } - } - } - return accepted; - } - - private static boolean isEnabled(AntStructuredElement element) { - final XmlTag srcElem = element.getSourceElement(); - final AntFile antFile = element.getAntFile(); - final String ifProperty = srcElem.getAttributeValue("if"); - if (ifProperty != null && antFile.getProperty(ifProperty) == null) { - return false; - } - final String unlessProperty = srcElem.getAttributeValue("unless"); - if (unlessProperty != null && antFile.getProperty(unlessProperty) != null) { - return false; - } - return true; - } - - private void addPatterns(final boolean addToIncludes, final String patternString) { - final StringTokenizer tokenizer = new StringTokenizer(patternString, ", \t", false); - while (tokenizer.hasMoreTokens()) { - final String pattern = tokenizer.nextToken(); - if (pattern.length() > 0) { - if (addToIncludes) { - addIncludePattern(pattern); - } - else { - addExcludePattern(pattern); - } - } - } - } - - private static Pattern convertToRegexPattern(@NonNls final String antPattern, final boolean caseSensitive) { - return Pattern.compile(FileUtil.convertAntToRegexp(antPattern), caseSensitive? 0 : Pattern.CASE_INSENSITIVE); - } - - public static AntPattern create(AntStructuredElement element, final boolean honorDefaultExcludes, final boolean caseSensitive) { - final AntPattern antPattern = new AntPattern(caseSensitive); - element.acceptAntElementVisitor(antPattern); - if (honorDefaultExcludes) { - antPattern.myExcludePatterns.addAll(caseSensitive? ourDefaultExcludes : ourCaseInsensitiveDefaultExcludes); - } - return antPattern; - } - - // from org.apache.tools.ant.DirectoryScanner - protected static boolean matchPatternStart(PrefixItem[] patDirs, String str) { - final String[] strDirs = str.split(ourSeparatorPattern); - - int patIdxStart = 0; - final int patIdxEnd = patDirs.length-1; - int strIdxStart = 0; - final int strIdxEnd = strDirs.length-1; - - // up to first '**' - while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { - final AntPattern.PrefixItem item = patDirs[patIdxStart]; - if ("**".equals(item.getStrPattern())) { - break; - } - if (!item.getPattern().matcher(strDirs[strIdxStart]).matches()) { - return false; - } - patIdxStart++; - strIdxStart++; - } - - if (strIdxStart > strIdxEnd) { - // String is exhausted - return true; - } - - if (patIdxStart > patIdxEnd) { - // String not exhausted, but pattern is. Failure. - return false; - } - - // pattern now holds ** while string is not exhausted - // this will generate false positives but we can live with that. - return true; - } - - public boolean couldBeIncluded(String relativePath) { - if (myIncludePatterns.size() == 0) { - return true; - } - for (PrefixItem[] couldBeIncludedPattern : myCouldBeIncludedPatterns) { - if (matchPatternStart(couldBeIncludedPattern, relativePath)) { - return true; - } - } - return false; - } - - private class PrefixItem { - private final String myStrPattern; - private Pattern myCompiledPattern; - public PrefixItem(String strPattern) { - myStrPattern = strPattern; - } - - public String getStrPattern() { - return myStrPattern; - } - - public Pattern getPattern() { - if (myCompiledPattern == null) { - myCompiledPattern = Pattern.compile(FileUtil.convertAntToRegexp(myStrPattern), myCaseSensitive ? 0 : Pattern.CASE_INSENSITIVE); - } - return myCompiledPattern; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPresetDefImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPresetDefImpl.java deleted file mode 100644 index db3674b34dd2..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPresetDefImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntPresetDef; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.psi.PsiLock; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; - -public class AntPresetDefImpl extends AntAllTasksContainerImpl implements AntPresetDef { - - @NonNls public static final String ANT_PRESETDEF_NAME = "AntPresetDef"; - - private AntTypeDefinitionImpl myPresetDefinition; - - public AntPresetDefImpl(final AntStructuredElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - invalidatePresetDefinition(); - } - - public String toString() { - return createPresetDefClassName(getName()); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntPresetDef(this); - } - - public static String createPresetDefClassName(final String presetDefName) { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(ANT_PRESETDEF_NAME); - builder.append("["); - builder.append(presetDefName); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntTypeDefinition getPresetDefinition() { - return myPresetDefinition; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - clearClassesCache(); - getAntFile().clearCaches(); - } - } - - public void clearClassesCache() { - synchronized (PsiLock.LOCK) { - if (myPresetDefinition != null) { - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.unregisterCustomType(myPresetDefinition); - } - myPresetDefinition = null; - } - } - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private void invalidatePresetDefinition() { - myPresetDefinition = null; - if (!hasNameElement()) return; - final String thisClassName = createPresetDefClassName(getName()); - final AntStructuredElementImpl extented = PsiTreeUtil.getChildOfType(this, AntStructuredElementImpl.class); - final AntTypeId typeId = new AntTypeId(getName()); - if (extented != null) { - final AntTypeDefinitionImpl extentedDef = (AntTypeDefinitionImpl)extented.getTypeDefinition(); - if (extentedDef != null) { - myPresetDefinition = new AntTypeDefinitionImpl(typeId, thisClassName, extentedDef.isTask(), false, extentedDef.getAttributesMap(), - extentedDef.getNestedElementsMap(), this); - } - } - if (myPresetDefinition == null) { - myPresetDefinition = new AntTypeDefinitionImpl(typeId, thisClassName, false, false, new HashMap(), - new HashMap(), this); - } - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.registerCustomType(myPresetDefinition); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java deleted file mode 100644 index 48cd312437bd..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.misc.PsiElementSetSpinAllocator; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.impl.reference.AntTargetReference; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.LocalTimeCounter; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.ArrayUtil; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -@SuppressWarnings({"HardCodedStringLiteral"}) -public class AntProjectImpl extends AntStructuredElementImpl implements AntProject { - - private volatile AntTarget[] myTargets; - private volatile AntTarget[] myImportedTargets; - private volatile List myImports; - private AntFile[] myCachedImportsArray; - - private volatile Map myReferencedElements; - private volatile String[] myRefIdsArray; - - public AntProjectImpl(final AntFileImpl parent, final XmlTag tag, final AntTypeDefinition projectDefinition) { - super(parent, tag); - myDefinition = projectDefinition; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntProject(this); - } - - @NonNls - public String toString() { - final @NonNls StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntProject["); - final String name = getName(); - builder.append((name == null) ? "unnamed" : name); - builder.append("]"); - if (getDescription() != null) { - builder.append(" :"); - builder.append(getDescription()); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntElementRole getRole() { - return AntElementRole.PROJECT_ROLE; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myTargets = null; - clearImports(); - myReferencedElements = null; - myRefIdsArray = null; - final AntFile antFile = getAntFile(); - if (antFile != null) { - antFile.invalidateProperties(); - } - } - } - - public void clearImports() { - synchronized (PsiLock.LOCK) { - if (myBuildingImports == 0) { - myImports = null; - } - myCachedImportsArray = null; - myImportedTargets = null; - } - } - - @Nullable - public String getBaseDir() { - return computeAttributeValue(getSourceElement().getAttributeValue(AntFileImpl.BASEDIR_ATTR)); - } - - @Nullable - public String getDescription() { - final XmlTag tag = getSourceElement().findFirstSubTag(AntFileImpl.DESCRIPTION_ATTR); - return tag != null ? tag.getValue().getTrimmedText() : null; - } - - @NotNull - public AntTarget[] getTargets() { - synchronized (PsiLock.LOCK) { - if (myTargets != null) { - return myTargets; - } - //noinspection NonPrivateFieldAccessedInSynchronizedContext - if (myInGettingChildren) { - return AntTarget.EMPTY_ARRAY; - } - final List targets = new ArrayList(); - for (final AntElement child : getChildren()) { - if (child instanceof AntTarget) { - targets.add((AntTarget)child); - } - } - final int size = targets.size(); - return myTargets = (size == 0) ? AntTarget.EMPTY_ARRAY : targets.toArray(new AntTarget[size]); - } - } - - @Nullable - public AntTarget getDefaultTarget() { - for (final PsiReference ref : getReferences()) { - if (ref instanceof AntTargetReference) { - return (AntTarget)ref.resolve(); - } - } - return null; - } - - @NotNull - public AntTarget[] getImportedTargets() { - synchronized (PsiLock.LOCK) { - if (myImportedTargets == null) { - if (getImportedFiles().length == 0) { - myImportedTargets = AntTarget.EMPTY_ARRAY; - } - else { - final Set targets = PsiElementSetSpinAllocator.alloc(); - try { - final Set elementsDepthStack = PsiElementSetSpinAllocator.alloc(); - try { - getImportedTargets(this, targets, elementsDepthStack); - } - finally { - PsiElementSetSpinAllocator.dispose(elementsDepthStack); - } - final int size = targets.size(); - myImportedTargets = (size == 0) ? AntTarget.EMPTY_ARRAY : targets.toArray(new AntTarget[size]); - } - finally { - PsiElementSetSpinAllocator.dispose(targets); - } - } - } - } - return myImportedTargets; - } - - @Nullable - public AntTarget getTarget(final String name) { - for (final AntTarget target : getTargets()) { - if (name.equals(target.getName())) { - return target; - } - } - return null; - } - - /** - * This method returns not only files that could be included via the - * task, but also a fake file which aggregates definitions resolved from all - * entity references under the root tag. - */ - private int myBuildingImports = 0; - @NotNull - public AntFile[] getImportedFiles() { - synchronized (PsiLock.LOCK) { - if (myImports == null) { - // this is necessary to avoid recurrent getImportedFiles() and stack overflow - myImports = new ArrayList(); - final XmlTag se = getSourceElement(); - final PsiFile psiFile = se.getContainingFile(); - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - myBuildingImports++; - try { - for (final XmlTag tag : se.getSubTags()) { - // !!! a tag doesn't belong to the current file, so we decide it's resolved via an entity ref - if (!psiFile.equals(tag.getContainingFile())) { - buildTagText(tag, builder); - } - else if (AntFileImpl.IMPORT_TAG.equals(tag.getName())) { - final String fileName = tag.getAttributeValue(AntFileImpl.FILE_ATTR); - if (fileName != null) { - final AntFile imported = AntImportImpl.getImportedFile(fileName, this); - if (imported != null) { - addImportedFile(imported); - } - } - } - } - if (builder.length() > 0) { - builder.insert(0, "\">"); - final String baseDir = getBaseDir(); - if (baseDir != null && baseDir.length() > 0) { - builder.insert(0, baseDir); - } - builder.insert(0, ""); - final XmlFile xmlFile = (XmlFile)PsiFileFactory.getInstance(getProject()) - .createFileFromText("dummyEntities.xml", StdFileTypes.XML, builder.toString(), LocalTimeCounter.currentTime(), false, false); - addImportedFile(new AntFileImpl(xmlFile.getViewProvider()) { - // - // this is necessary for computing file paths in tags resolved as entity references - // - public VirtualFile getContainingPath() { - return AntProjectImpl.this.getAntFile().getContainingPath(); - } - }); - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - myBuildingImports--; - myCachedImportsArray = null; - myImportedTargets = null; - } - } - if (myCachedImportsArray == null) { - myCachedImportsArray = myImports.toArray(new AntFile[myImports.size()]); - } - return myCachedImportsArray; - } - } - - private void addImportedFile(final AntFile imported) { - try { - myImports.add(imported); - } - finally { - myCachedImportsArray = null; - } - } - - public void registerRefId(final String id, AntElement element) { - synchronized (PsiLock.LOCK) { - if (id == null || id.length() == 0) return; - if (myReferencedElements == null) { - myReferencedElements = new HashMap(); - } - myReferencedElements.put(id, element); - } - } - - @Nullable - public AntElement getElementByRefId(String refid) { - synchronized (PsiLock.LOCK) { - if (myReferencedElements == null) return null; - refid = computeAttributeValue(refid); - return myReferencedElements.get(refid); - } - } - - @NotNull - public String[] getRefIds() { - synchronized (PsiLock.LOCK) { - if (myRefIdsArray == null) { - if (myReferencedElements == null) { - myRefIdsArray = ArrayUtil.EMPTY_STRING_ARRAY; - } - else { - myRefIdsArray = myReferencedElements.keySet().toArray(new String[myReferencedElements.size()]); - } - } - return myRefIdsArray; - } - } - - private static void getImportedTargets(final AntProject project, - final Set targets, - final Set elementsDepthStack) { - if (elementsDepthStack.contains(project)) return; - elementsDepthStack.add(project); - try { - for (final AntFile imported : project.getImportedFiles()) { - final AntProject importedProject = imported.getAntProject(); - if (importedProject != null && !elementsDepthStack.contains(importedProject)) { - for (final AntTarget target : importedProject.getTargets()) { - targets.add(target); - } - } - getImportedTargets(importedProject, targets, elementsDepthStack); - } - } - finally { - elementsDepthStack.remove(project); - } - } - - private static void buildTagText(final XmlTag tag, final StringBuilder builder) { - // - // this quite strange creation of the tag text is necessary since - // tag.getText() removes whitespaces from source text - // - boolean firstChild = true; - for (final PsiElement tagChild : tag.getChildren()) { - if (!firstChild) { - builder.append(' '); - } - if (tagChild instanceof XmlTag) { - buildTagText((XmlTag)tagChild, builder); - } - else { - builder.append(tagChild.getText()); - } - firstChild = false; - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPropertyImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPropertyImpl.java deleted file mode 100644 index 485537fa2aaf..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntPropertyImpl.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.properties.IProperty; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.StringSetSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.*; - -public class AntPropertyImpl extends AntTaskImpl implements AntProperty { - - private PsiElement myPropertiesFile; - private static final Set ourPropertyDefiningTags = new HashSet(Arrays.asList( - AntFileImpl.PROPERTY, - "param", - "condition", - "input", - "available" - )); - - public AntPropertyImpl(final AntElement parent, - final XmlTag sourceElement, - final AntTypeDefinition definition, - @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public AntPropertyImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - this(parent, sourceElement, definition, AntFileImpl.NAME_ATTR); - } - - public PsiElement setName(@NotNull final String name) throws IncorrectOperationException { - final AntProperty element = (AntProperty)super.setName(name); - final AntFile antFile = getAntFile(); - antFile.invalidateProperties(); - return element; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntProperty(this); - } - - public String toString() { - final @NonNls StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntProperty["); - if (getName() != null) { - builder.append(getName()); - builder.append(" = "); - builder.append(getValue(null)); - } - else { - final String propFile = getFileName(); - if (propFile != null) { - builder.append("file: "); - builder.append(propFile); - } - else { - builder.append(getSourceElement().getName()); - } - } - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public String getName() { - final XmlAttributeValue[] values = getTstampPropertyAttributeValues(); - return (values.length == 1) ? values[0].getValue() : super.getName(); - } - - public AntElementRole getRole() { - return AntElementRole.PROPERTY_ROLE; - } - - public boolean canRename() { - return super.canRename() && (!isTstamp() || getTstampPropertyAttributeValues().length > 0); - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - @Nullable - public String getValue(final String propName) { - synchronized (PsiLock.LOCK) { - final XmlTag se = getSourceElement(); - final String tagName = se.getName(); - if (ourPropertyDefiningTags.contains(tagName)) { // todo: support conditions separately - String value = getPropertyValue(); - if (value == null && propName != null) { - final PropertiesFile propertiesFile = getPropertiesFile(); - if (propertiesFile != null) { - final IProperty fileProperty = propertiesFile.findPropertyByKey(cutPrefix(propName)); - if (fileProperty != null) { - value = fileProperty.getValue(); - } - } - } - return value; - } - else if ("dirname".equals(tagName)) { - return getDirnameValue(); - } - else if (isTstamp()) { - return getTstampValue(propName); - } - return null; - } - } - - private String cutPrefix(@NotNull final String propName) { - final String prefix = getPrefix(); - if (prefix != null && propName.startsWith(prefix) && prefix.length() < propName.length() && propName.charAt(prefix.length()) == '.') { - return propName.substring(prefix.length() + 1); - } - return propName; - } - - @Nullable - public String getFileName() { - return computeAttributeValue(getSourceElement().getAttributeValue(AntFileImpl.FILE_ATTR)); - } - - @Nullable - public PropertiesFile getPropertiesFile() { - synchronized (PsiLock.LOCK) { - if (myPropertiesFile == null) { - myPropertiesFile = AntElementImpl.ourNull; - final String name = getFileName(); - if (name != null) { - final PsiFile psiFile = findFileByName(name, null); - if (psiFile instanceof PropertiesFile) { - myPropertiesFile = psiFile; - } - } - } - return (myPropertiesFile == AntElementImpl.ourNull) ? null : (PropertiesFile)myPropertiesFile; - } - } - - @Nullable - public String getPrefix() { - return computeAttributeValue(getSourceElement().getAttributeValue(AntFileImpl.PREFIX_ATTR)); - } - - @Nullable - public String getEnvironment() { - return computeAttributeValue(getSourceElement().getAttributeValue("environment")); - } - - @Nullable - public String[] getNames() { - if (isTstamp()) { - return getTstampNames(); - } - final PropertiesFile propertiesFile = getPropertiesFile(); - if (propertiesFile != null) { - final List propList = propertiesFile.getProperties(); - final String prefix = getPrefix(); - final String[] names = ArrayUtil.newStringArray(propList.size()); - int idx = 0; - for (final IProperty importedProp : propList) { - names[idx++] = prefix != null? prefix + "." + importedProp.getName() : importedProp.getName(); - } - return names; - } - - final String name = getName(); - if (name != null) { - if (getAntFile().isEnvironmentProperty(name)) { - return getEnvironmentNames(name); - } - return new String[]{name}; - } - return null; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - final AntFile antFile = getAntFile(); - if (antFile != null) { - antFile.clearCaches(); - } - myPropertiesFile = null; - } - } - - public int getTextOffset() { - final XmlAttributeValue[] values = getTstampPropertyAttributeValues(); - return (values.length == 1) ? values[0].getTextOffset() : super.getTextOffset(); - } - - /** - * @return element for the property - * @param propName - */ - @Nullable - @SuppressWarnings({"HardCodedStringLiteral"}) - public AntElement getFormatElement(final String propName) { - for (final AntElement child : getChildren()) { - if (child instanceof AntStructuredElement) { - final AntStructuredElement se = (AntStructuredElement)child; - final XmlTag tag = se.getSourceElement(); - if (AntFileImpl.FORMAT_TAG.equals(tag.getName())) { - if (propName.equals(tag.getAttributeValue(AntFileImpl.PROPERTY))) { - return child; - } - } - } - } - return this; - } - - @Nullable - private String getPropertyValue() { - final XmlTag sourceElement = getSourceElement(); - final String tagName = sourceElement.getName(); - if ("available".equals(tagName)) { - // check only 'file' tag because others could be examined only at runtime - final String filePath = sourceElement.getAttributeValue("file"); - if (filePath != null) { - final String _filePath = computeAttributeValue(filePath); - if (_filePath != null) { - if (!new File(_filePath).exists()) { - return null; - } - } - } - } - - String value = sourceElement.getAttributeValue("value"); - if (value == null) { - value = sourceElement.getAttributeValue("location"); - if (value == null) { - value = sourceElement.getAttributeValue("defaultvalue"); - } - } - return value;/*computeAttributeValue(value);*/ - } - - @Nullable - private String getDirnameValue() { - final XmlTag sourceElement = getSourceElement(); - final String value = computeAttributeValue(sourceElement.getAttributeValue(AntFileImpl.FILE_ATTR)); - if (value != null) { - return new File(value).getParent(); - } - return value; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private String getTstampValue(final String propName) { - final XmlTag se = getSourceElement(); - Date d = new Date(); - final XmlTag formatTag = se.findFirstSubTag(AntFileImpl.FORMAT_TAG); - if (formatTag != null) { - final String offsetStr = formatTag.getAttributeValue("offset"); - int offset; - if (offsetStr != null) { - try { - offset = Integer.parseInt(offsetStr); - } - catch (NumberFormatException e) { - offset = 0; - } - final String unitStr = formatTag.getAttributeValue("unit"); - int unit = 0; - if (unitStr != null) { - if ("millisecond".equals(unitStr)) { - unit = Calendar.MILLISECOND; - } - else if ("second".equals(unitStr)) { - unit = Calendar.SECOND; - } - else if ("minute".equals(unitStr)) { - unit = Calendar.MINUTE; - } - else if ("hour".equals(unitStr)) { - unit = Calendar.HOUR_OF_DAY; - } - else if ("day".equals(unitStr)) { - unit = Calendar.DAY_OF_MONTH; - } - else if ("week".equals(unitStr)) { - unit = Calendar.WEEK_OF_YEAR; - } - else if ("year".equals(unitStr)) { - unit = Calendar.YEAR; - } - } - if (offset != 0 && unit != 0) { - final Calendar cal = Calendar.getInstance(); - cal.setTime(d); - cal.add(unit, offset); - d = cal.getTime(); - } - } - } - final String _propName = propName != null? cutPrefix(propName) : null; - if (_propName != null) { - if (_propName.equals("DSTAMP")) { - return new SimpleDateFormat("yyyyMMdd").format(d); - } - else if (_propName.equals("TSTAMP")) { - return new SimpleDateFormat("HHmm").format(d); - } - else if (_propName.equals("TODAY")) { - return new SimpleDateFormat("MMMM d yyyy", Locale.US).format(d); - } - } - - for (XmlAttributeValue value : getTstampPropertyAttributeValues()) { - if (value != null && (_propName == null || _propName.equals(value.getValue()))) { - if (formatTag != null) { - final String pattern = formatTag.getAttributeValue(TSTAMP_PATTERN_ATTRIBUTE_NAME); - try { - final DateFormat format = (pattern != null) ? new SimpleDateFormat(pattern) : DateFormat.getTimeInstance(); - final String tz = formatTag.getAttributeValue(TSTAMP_TIMEZONE_ATTRIBUTE_NAME); - if (tz != null) { - format.setTimeZone(TimeZone.getTimeZone(tz)); - } - return format.format(d); - } - catch (IllegalArgumentException ignored) { - return null; - } - } - } - } - return null; - } - - private XmlAttributeValue[] getTstampPropertyAttributeValues() { - if (isTstamp()) { - final List elements = new ArrayList(); - for (XmlTag formatTag : getSourceElement().findSubTags(AntFileImpl.FORMAT_TAG)) { - final XmlAttribute propAttr = formatTag.getAttribute(AntFileImpl.PROPERTY, null); - if (propAttr != null) { - final XmlAttributeValue value = propAttr.getValueElement(); - if (value != null) { - elements.add(value); - } - } - } - return elements.toArray(new XmlAttributeValue[elements.size()]); - } - return new XmlAttributeValue[0]; - } - - public boolean isTstamp() { - return TSTAMP_TAG.equals(getSourceElement().getName()); - } - - private String[] getTstampNames() { - @NonNls final Set strings = StringSetSpinAllocator.alloc(); - try { - String prefix = getSourceElement().getAttributeValue(AntFileImpl.PREFIX_ATTR); - if (prefix == null) { - strings.add("DSTAMP"); - strings.add("TSTAMP"); - strings.add("TODAY"); - } - else { - prefix += '.'; - strings.add(prefix + "DSTAMP"); - strings.add(prefix + "TSTAMP"); - strings.add(prefix + "TODAY"); - } - for (XmlAttributeValue value : getTstampPropertyAttributeValues()) { - if (value != null && value.getValue() != null) { - final String additionalProperty = value.getValue(); - if (prefix == null) { - strings.add(additionalProperty); - } - else { - strings.add(prefix + additionalProperty); - } - } - } - return ArrayUtil.toStringArray(strings); - } - finally { - StringSetSpinAllocator.dispose(strings); - } - } - - private String[] getEnvironmentNames(final String name) { - @NonNls final Set strings = StringSetSpinAllocator.alloc(); - try { - final String sourceName = name.substring(AntFileImpl.DEFAULT_ENVIRONMENT_PREFIX.length()); - for (final String prefix : getAntFile().getEnvironmentPrefixes()) { - strings.add(prefix + sourceName); - } - return ArrayUtil.toStringArray(strings); - } - finally { - StringSetSpinAllocator.dispose(strings); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntScriptDefImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntScriptDefImpl.java deleted file mode 100644 index 82bc387778e8..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntScriptDefImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.psi.PsiLock; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -public class AntScriptDefImpl extends AntTaskImpl implements AntScriptDef { - - @NonNls public static final String ANT_SCRIPTDEF_NAME = "AntScriptDef"; - - private AntTypeDefinitionImpl myScriptDefinition; - - public AntScriptDefImpl(final AntStructuredElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - invalidateScriptDefinition(); - } - - public String toString() { - return createScriptClassName(getName()); - } - - public static String createScriptClassName(final String macroName) { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(ANT_SCRIPTDEF_NAME); - builder.append("["); - builder.append(macroName); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntElementRole getRole() { - return AntElementRole.SCRIPTDEF_ROLE; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntScriptDef(this); - } - - public AntTypeDefinition getScriptDefinition() { - return myScriptDefinition; - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - final AntFile file = getAntFile(); - clearClassesCache(); - file.clearCaches(); - } - } - - public void clearClassesCache() { - synchronized (PsiLock.LOCK) { - if (myScriptDefinition != null) { - final AntFile file = getAntFile(); - final AntAllTasksContainerImpl sequential = PsiTreeUtil.getChildOfType(this, AntAllTasksContainerImpl.class); - if (sequential != null) { - sequential.unregisterCustomType(myScriptDefinition); - } - for (AntTypeId id : myScriptDefinition.getNestedElements()) { - final AntTypeDefinition nestedDef = file.getBaseTypeDefinition(myScriptDefinition.getNestedClassName(id)); - if (nestedDef != null) { - file.unregisterCustomType(nestedDef); - if (sequential != null) { - sequential.unregisterCustomType(nestedDef); - } - } - } - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.unregisterCustomType(myScriptDefinition); - } - myScriptDefinition = null; - } - } - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private void invalidateScriptDefinition() { - if (!hasNameElement()) { - myScriptDefinition = null; - return; - } - - final AntFile file = getAntFile(); - if (file == null) return; - - final String thisClassName = createScriptClassName(getName()); - myScriptDefinition = (AntTypeDefinitionImpl)file.getBaseTypeDefinition(thisClassName); - final Map attributes = - (myScriptDefinition == null) ? new HashMap() : myScriptDefinition.getAttributesMap(); - attributes.clear(); - final Map nestedElements = - (myScriptDefinition == null) ? new HashMap() : myScriptDefinition.getNestedElementsMap(); - for (AntElement child : getChildren()) { - if (child instanceof AntStructuredElement) { - final AntStructuredElement se = (AntStructuredElement)child; - final String name = se.getName(); - if (name != null) { - final XmlTag sourceElement = se.getSourceElement(); - final String tagName = sourceElement.getName(); - if (tagName.equals("attribute")) { - attributes.put(name.toLowerCase(Locale.US), AntAttributeType.STRING); - } - else if (tagName.equals("element")) { - final String classNameAttrib = sourceElement.getAttributeValue("classname"); - final String elementClassName = classNameAttrib != null? classNameAttrib : thisClassName + '$' + name; - AntTypeDefinitionImpl nestedDef = (AntTypeDefinitionImpl)file.getBaseTypeDefinition(elementClassName); - if (nestedDef == null) { - final AntTypeDefinitionImpl targetDef = (AntTypeDefinitionImpl)file.getTargetDefinition(); - if (targetDef != null) { - nestedDef = new AntTypeDefinitionImpl(targetDef); - } - } - if (nestedDef != null) { - final String typeAttrib = sourceElement.getAttributeValue("type"); - final String typeName = typeAttrib != null? typeAttrib : name; - final AntTypeId typeId = new AntTypeId(typeName); - nestedDef.setTypeId(typeId); - nestedDef.setClassName(elementClassName); - //nestedDef.setIsTask(false); - nestedDef.setDefiningElement(child); - file.registerCustomType(nestedDef); - nestedElements.put(typeId, nestedDef.getClassName()); - } - } - } - } - } - final AntTypeId definedTypeId = new AntTypeId(getName()); - if (myScriptDefinition == null) { - myScriptDefinition = new AntTypeDefinitionImpl(definedTypeId, thisClassName, true, false, attributes, nestedElements, this); - } - else { - myScriptDefinition.setTypeId(definedTypeId); - myScriptDefinition.setClassName(thisClassName); - myScriptDefinition.setIsTask(true); - myScriptDefinition.setDefiningElement(this); - } - final AntStructuredElement parent = getAntProject(); - if (parent != null) { - parent.registerCustomType(myScriptDefinition); - } - // define itself as nested task for sequential - final AntAllTasksContainerImpl sequential = PsiTreeUtil.getChildOfType(this, AntAllTasksContainerImpl.class); - if (sequential != null) { - sequential.registerCustomType(myScriptDefinition); - for (final AntTypeId id : myScriptDefinition.getNestedElements()) { - sequential.registerCustomType(file.getBaseTypeDefinition(myScriptDefinition.getNestedClassName(id))); - } - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java deleted file mode 100644 index 8f60b10ce4f0..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java +++ /dev/null @@ -1,653 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.config.AntConfigurationBase; -import com.intellij.lang.ant.misc.AntStringInterner; -import com.intellij.lang.ant.misc.PsiElementWithValueSetSpinAllocator; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlElement; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.*; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.InputStream; -import java.util.*; -import java.util.regex.Pattern; - -public class AntStructuredElementImpl extends AntElementImpl implements AntStructuredElement { - - private static final AntNameIdentifier ourNullIdentifier = new AntNameIdentifierImpl(null, null) { - @NonNls - public String getIdentifierName() { - return "AntNullIdentifier"; - } - - public boolean isValid() { - return true; - } - }; - protected volatile AntTypeDefinition myDefinition; - private boolean myDefinitionCloned; - private volatile AntNameIdentifier myIdElement; - private volatile AntNameIdentifier myNameElement; - @NonNls - private volatile String myNameElementAttribute; - private int myLastFoundElementOffset = -1; - private AntElement myLastFoundElement; - private volatile boolean myIsImported; - private StringSetHolder myComputingAttrValue; - protected volatile boolean myInGettingChildren; - @NonNls private static final String ANTLIB_NS_PREFIX = "antlib:"; - @NonNls private static final String ANTLIB_XML = "antlib.xml"; - private static final Pattern $$_PATTERN = Pattern.compile("\\$\\$"); - - private AntStructuredElementImpl(final AntElement parent, final XmlTag sourceElement, @NonNls final String nameElementAttribute) { - super(parent, sourceElement); - myNameElementAttribute = AntStringInterner.intern(nameElementAttribute); - getIdElement(); - getNameElement(); - invalidateAntlibNamespace(); - } - - public AntStructuredElementImpl(final AntElement parent, final XmlTag sourceElement) { - this(parent, sourceElement, AntFileImpl.NAME_ATTR); - } - - public AntStructuredElementImpl(final AntElement parent, - final XmlTag sourceElement, - final AntTypeDefinition definition, - @NonNls final String nameElementAttribute) { - this(parent, sourceElement, nameElementAttribute); - myDefinition = definition; - final AntTypeId id = new AntTypeId(sourceElement.getName()); - if (definition != null) { - if (!definition.getTypeId().equals(id)) { - myDefinition = new AntTypeDefinitionImpl((AntTypeDefinitionImpl)myDefinition); - myDefinition.setTypeId(id); - myDefinitionCloned = true; - } - } - else { - /** - * This branch reloads of type definition in case if it could be - * registered during invalidation of the "antlib:..." namespace - */ - final AntFile file = getAntFile(); - if (file != null) { - final AntTypeDefinition targetDef = file.getTargetDefinition(); - final String className = targetDef != null? targetDef.getNestedClassName(id) : null; - if (className != null) { - myDefinition = file.getBaseTypeDefinition(className); - } - } - } - } - - public AntStructuredElementImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - this(parent, sourceElement, definition, AntFileImpl.NAME_ATTR); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntStructuredElement(this); - } - - @NotNull - public XmlTag getSourceElement() { - return (XmlTag)super.getSourceElement(); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntStructuredElement["); - builder.append(getSourceElement().getName()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public String getName() { - if (hasNameElement()) { - return computeAttributeValue(getNameElement().getIdentifierName()); - } - if (hasIdElement()) { - return computeAttributeValue(getIdElement().getIdentifierName()); - } - final XmlTag sourceElement = getSourceElement(); - return sourceElement != null ? sourceElement.getName() : super.getName(); - } - - public PsiElement setName(@NotNull final String name) throws IncorrectOperationException { - try { - if (hasNameElement()) { - getNameElement().setIdentifierName(name); - } - else if (hasIdElement()) { - getIdElement().setIdentifierName(name); - } - return this; - } - finally { - clearCaches(); - } - } - - public boolean canRename() { - return super.canRename() && (hasNameElement() || hasIdElement()); - } - - public PsiElement findElementAt(int offset) { - synchronized (PsiLock.LOCK) { - if (offset != myLastFoundElementOffset || (myLastFoundElement != null && !myLastFoundElement.isValid())) { - final PsiElement foundElement = super.findElementAt(offset); - if (foundElement == null) { - return null; - } - myLastFoundElement = (AntElement)foundElement; - myLastFoundElementOffset = offset; - } - return myLastFoundElement; - } - } - - public AntTypeDefinition getTypeDefinition() { - synchronized (PsiLock.LOCK) { - if (myDefinition != null && !myDefinitionCloned && myDefinition.isOutdated()) { - final AntTypeDefinition currentDef = getAntFile().getBaseTypeDefinition(myDefinition.getClassName()); - if (currentDef != null) { - myDefinition = currentDef; - } - } - return myDefinition; - } - } - - public void registerCustomType(final AntTypeDefinition def) { - synchronized (PsiLock.LOCK) { - AntTypeDefinition definition = getTypeDefinition(); - if (definition != null) { - if (!myDefinitionCloned) { - definition = new AntTypeDefinitionImpl((AntTypeDefinitionImpl)definition); - myDefinition = definition; - myDefinitionCloned = true; - } - definition.registerNestedType(def.getTypeId(), def.getClassName()); - } - getAntFile().registerCustomType(def); - } - } - - public void unregisterCustomType(final AntTypeDefinition def) { - synchronized (PsiLock.LOCK) { - if (myDefinition != null && myDefinitionCloned) { - final AntTypeId typeId = def.getTypeId(); - // for the same typeId there might be different classes registered - // so unregister only that type that is really registered as a nested within this element - final String registeredClassName = myDefinition.getNestedClassName(typeId); - if (registeredClassName != null && registeredClassName.equals(def.getClassName())) { - myDefinition.unregisterNestedType(typeId); - } - } - getAntFile().unregisterCustomType(def); - } - } - - public boolean hasImportedTypeDefinition() { - return myIsImported; - } - - void setImportedTypeDefinition(boolean imported) { - myIsImported = imported; - } - - @Nullable - public PsiFile findFileByName(final String name) { - return findFileByName(name, ""); - } - - @Nullable - public PsiFile findFileByName(final String name, @Nullable final String baseDir) { - if (name == null) { - return null; - } - final AntFile antFile = getAntFile(); - if (antFile == null) { - return null; - } - VirtualFile vFile = antFile.getContainingPath(); - if (vFile == null) { - return null; - } - String projectPath = vFile.getPath(); - String dir = baseDir; - if (dir == null) { - final AntProject project = antFile.getAntProject(); - dir = project == null ? null : project.getBaseDir(); - } - if (dir != null && dir.length() > 0) { - projectPath = new File(projectPath, dir).getAbsolutePath(); - } - final String fileName = computeAttributeValue(name); - if (fileName == null) { - return null; - } - File file = new File(fileName); - if (!file.isAbsolute()) { - file = new File(projectPath, fileName); - } - vFile = LocalFileSystem.getInstance().findFileByPath(file.getAbsolutePath().replace(File.separatorChar, '/')); - if (vFile == null) { - return null; - } - return antFile.getViewProvider().getManager().findFile(vFile); - } - - @Nullable - public String computeAttributeValue(final String value) { - if (value == null || value.indexOf('$') < 0) { - return value; // optimization - } - synchronized (PsiLock.LOCK) { - if (value != null) { - if (myComputingAttrValue == null || !myComputingAttrValue.contains(value)) { - try { - if (myComputingAttrValue == null) { - myComputingAttrValue = new StringSetHolder(); - } - final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(getProject()); - myComputingAttrValue.add(value); - try { - final Set> set = PsiElementWithValueSetSpinAllocator.alloc(); - try { - return computeAttributeValue(value, set, antConfig); - } - finally { - PsiElementWithValueSetSpinAllocator.dispose(set); - } - } - catch (SpinAllocator.AllocatorExhaustedException e) { - return computeAttributeValue(value, new HashSet>(), antConfig); - } - } - finally { - myComputingAttrValue.remove(value); - if (myComputingAttrValue.size() == 0) { - myComputingAttrValue.dispose(); - myComputingAttrValue = null; - } - } - } - } - return null; - } - } - - public boolean hasNameElement() { - return getNameElement() != ourNullIdentifier; - } - - public boolean hasIdElement() { - return getIdElement() != ourNullIdentifier; - } - - @NotNull - public List getFileReferenceAttributes() { - final AntTypeDefinition typeDef = getTypeDefinition(); - if (typeDef == null) { - return Collections.emptyList(); - } - final String[] attribs = typeDef.getAttributes(); - if (attribs.length == 0) { - return Collections.emptyList(); - } - final List fileRefAttributes = new ArrayList(attribs.length); - for (String attrib : attribs) { - if (typeDef.getAttributeType(attrib) == AntAttributeType.FILE) { - fileRefAttributes.add(attrib); - } - } - return fileRefAttributes; - } - - public boolean isTypeDefined() { - final AntTypeDefinition def = getTypeDefinition(); - return def != null && def.getDefiningElement() instanceof AntTypeDefImpl; - } - - public boolean isPresetDefined() { - final AntTypeDefinition def = getTypeDefinition(); - return def != null && def.getClassName().startsWith(AntPresetDefImpl.ANT_PRESETDEF_NAME); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myIdElement = null; - myNameElement = null; - myLastFoundElementOffset = -1; - myLastFoundElement = null; - myLastProcessedChildren = null; - invalidateAntlibNamespace(); - } - } - - public AntElement lightFindElementAt(int offset) { - synchronized (PsiLock.LOCK) { - if (offset == myLastFoundElementOffset) { - return myLastFoundElement; - } - } - return super.lightFindElementAt(offset); - } - - public int getTextOffset() { - if (hasNameElement()) { - return getNameElement().getTextOffset(); - } - if (hasIdElement()) { - return getIdElement().getTextOffset(); - } - return super.getTextOffset(); - } - - protected AntElement[] getChildrenInner() { - synchronized (PsiLock.LOCK) { - if (!myInGettingChildren) { - myInGettingChildren = true; - try { - final List children = new ArrayList(); - if (hasIdElement()) { - children.add(getIdElement()); - } - if (hasNameElement()) { - children.add(getNameElement()); - } - for (final PsiElement element : getSourceElement().getChildren()) { - if (element instanceof XmlElement) { - final AntElement antElement = AntElementFactory.createAntElement(this, (XmlElement)element); - if (antElement != null) { - children.add(antElement); - /* - if (antElement instanceof AntStructuredElement) { - antElement.getChildren(); - } - */ - } - } - } - final int count = children.size(); - return count > 0 ? children.toArray(new AntElement[count]) : AntElement.EMPTY_ARRAY; - } - finally { - myInGettingChildren = false; - } - } - } - return AntElement.EMPTY_ARRAY; - } - - @NotNull - public AntElement[] getChildren() { - synchronized (PsiLock.LOCK) { - return fixUndefinedElements(super.getChildren()); - } - } - - private AntElement[] myLastProcessedChildren; - - private AntElement[] fixUndefinedElements(final AntElement[] elements) { - if (myLastProcessedChildren == elements) { - return elements; - } - myLastProcessedChildren = elements; - if (isValid()) { - for (int i = 0; i < elements.length; i++) { - final AntElement element = elements[i]; - if (element instanceof AntStructuredElement && element.isValid()) { - AntStructuredElement se = (AntStructuredElement)element; - if (se.getTypeDefinition() == null) { - final XmlTag sourceElement = se.getSourceElement(); - se = (AntStructuredElement)AntElementFactory.createAntElement(this, sourceElement); - if (se != null && se.getTypeDefinition() != null) { - elements[i] = se; - } - } - } - } - } - return elements; - } - - @NotNull - private AntNameIdentifier getIdElement() { - synchronized (PsiLock.LOCK) { - if (myIdElement == null) { - myIdElement = ourNullIdentifier; - final XmlTag se = getSourceElement(); - if (se.isValid()) { - final XmlAttribute idAttr = se.getAttribute(AntFileImpl.ID_ATTR, null); - if (idAttr != null) { - final XmlAttributeValue valueElement = idAttr.getValueElement(); - if (valueElement != null) { - final AntNameIdentifierImpl identifier = new AntNameIdentifierImpl(this, valueElement); - myIdElement = identifier; - getAntProject().registerRefId(identifier.getIdentifierName(), this); - } - } - } - } - return myIdElement; - } - } - - @NotNull - private AntNameIdentifier getNameElement() { - synchronized (PsiLock.LOCK) { - if (myNameElement == null) { - myNameElement = ourNullIdentifier; - final XmlTag se = getSourceElement(); - if (se.isValid()) { - final XmlAttribute nameAttr = se.getAttribute(myNameElementAttribute, null); - if (nameAttr != null) { - final XmlAttributeValue valueElement = nameAttr.getValueElement(); - if (valueElement != null) { - myNameElement = new AntNameIdentifierImpl(this, valueElement); - } - } - } - } - return myNameElement; - } - } - - @NonNls - protected String getNameElementAttribute() { - return myNameElementAttribute; - } - - /** - * Cycle-safe computation of an attribute value with resolving properties. - * - * @param value - * @param elementStack - * @param antConfig - * @return - */ - private String computeAttributeValue(String value, final Set> elementStack, final AntConfigurationBase antConfig) { - final Pair resolveStackEntry = new Pair(this, value); - elementStack.add(resolveStackEntry); - try { - int startProp = 0; - final AntFile self = getAntFile(); - final AntFile antFile = null/*antConfig.getEffectiveContextFile(self)*/; - while ((startProp = value.indexOf("${", startProp)) >= 0) { - if (startProp > 0 && value.charAt(startProp - 1) == '$') { - // the '$' is escaped - startProp += 2; - continue; - } - final int endProp = value.indexOf('}', startProp + 2); - if (endProp <= startProp + 2) { - startProp += 2; - continue; - } - final String prop = value.substring(startProp + 2, endProp); - final Ref resolvedValueRef = new Ref(null); - final Ref shouldReturnOriginalValue = new Ref(Boolean.FALSE); - antFile.processAllProperties(prop, new Processor() { - public boolean process(AntProperty antProperty) { - final String resolvedValue = antProperty.getValue(prop); - if (resolvedValue == null) { - return true; - } - if (elementStack.contains(new Pair(antProperty, resolvedValue))) { - shouldReturnOriginalValue.set(Boolean.TRUE); - } - else { - resolvedValueRef.set(((AntStructuredElementImpl)antProperty).computeAttributeValue(resolvedValue, elementStack, antConfig)); - } - return false; - } - }); - if (shouldReturnOriginalValue.get()) { - return value; // prevent cycles - } - if (resolvedValueRef.get() == null) { - startProp += 2; - } - else { - if (resolvedValueRef.get().equals(value) /*prevent tail recursion*/) { - return value; - } - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(value, 0, startProp); - builder.append(resolvedValueRef.get()); - if (endProp < value.length() - 1) { - builder.append(value, endProp + 1, value.length()); - } - final String substituted = builder.toString(); - if (!substituted.equals(value)) { - value = substituted; - } - else { - startProp += 2; - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - } - if (value.indexOf("$$") >= 0) { - return $$_PATTERN.matcher(value).replaceAll("\\$"); - } - return value; - } - finally { - elementStack.remove(resolveStackEntry); - } - } - - private String getNamespace() { - return getSourceElement().getNamespace(); - } - - private void invalidateAntlibNamespace() { - final AntFile file = getAntFile(); - if (file == null) return; - final ClassLoader loader = file.getClassLoader(); - if (loader == null) return; - final String ns = getNamespace(); - if (!ns.startsWith(ANTLIB_NS_PREFIX)) return; - final AntElement parent = getAntParent(); - if (!(this instanceof AntProject)) { - if (parent instanceof AntStructuredElementImpl && ns.equals(((AntStructuredElementImpl)parent).getNamespace())) return; - } - - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(ns.substring(ANTLIB_NS_PREFIX.length()).replace('.', '/')); - builder.append('/'); - builder.append(ANTLIB_XML); - final InputStream antlibStream = loader.getResourceAsStream(builder.toString()); - if (antlibStream != null) { - AntTypeDefImpl.loadAntlibStream(antlibStream, this, ns); - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - private static final class StringSetHolder { - @NotNull - private Set mySet; - private boolean myShouldDispose = true; - - public StringSetHolder() { - try { - mySet = StringSetSpinAllocator.alloc(); - } - catch (SpinAllocator.AllocatorExhaustedException e) { - mySet = new HashSet(); - myShouldDispose = false; - } - } - - public boolean contains(String str) { - return mySet.contains(str); - } - - public int size() { - return mySet.size(); - } - - public boolean add(final String s) { - return mySet.add(s); - } - - public boolean remove(final String s) { - return mySet.remove(s); - } - - public void dispose() { - if (myShouldDispose) { - StringSetSpinAllocator.dispose(mySet); - } - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTargetImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTargetImpl.java deleted file mode 100644 index c6a409aa5c3a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTargetImpl.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntTarget; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class AntTargetImpl extends AntStructuredElementImpl implements AntTarget { - - private AntTarget[] myDependsTargets; - - public AntTargetImpl(AntElement parent, final XmlTag tag) { - super(parent, tag); - myDefinition = getAntFile().getTargetDefinition(); - } - - @NonNls - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntTarget:["); - builder.append(getName()); - if (getDescription() != null) { - builder.append(" :"); - builder.append(getDescription()); - } - builder.append("]"); - final AntTarget[] targets = getDependsTargets(); - if (targets.length > 0) { - builder.append(" -> ["); - for (AntTarget target : targets) { - builder.append(' '); - builder.append(target.getName()); - } - builder.append(" ]"); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntElementRole getRole() { - return AntElementRole.TARGET_ROLE; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntTarget(this); - } - - @NotNull - public String getQualifiedName() { - final AntProject project = getAntProject(); - final String projectName = (project != null) ? project.getName() : null; - final String name = getName(); - final String result = (projectName == null || projectName.length() == 0) ? name : projectName + '.' + name; - return (result == null) ? "" : result; - } - - @Nullable - public String getDescription() { - return getSourceElement().getAttributeValue(AntFileImpl.DESCRIPTION_ATTR); - } - - @Nullable - public String getConditionalPropertyName(final ConditionalAttribute attrib) { - final XmlAttribute propNameAttribute = getSourceElement().getAttribute(attrib.getXmlName(), null); - if (propNameAttribute != null) { - final XmlAttributeValue valueElement = propNameAttribute.getValueElement(); - if (valueElement != null) { - return computeAttributeValue(valueElement.getValue()); - } - } - return null; - } - - @NotNull - public AntTarget[] getDependsTargets() { - synchronized (PsiLock.LOCK) { - if (myDependsTargets == null) { - final String depends = getSourceElement().getAttributeValue(AntFileImpl.DEPENDS_ATTR); - if (depends == null || depends.length() == 0) { - myDependsTargets = AntTarget.EMPTY_ARRAY; - } - else { - final AntProject project = getAntProject(); - final List targets = new ArrayList(); - for (final String name : depends.split(",|[\\s]+")) { - final AntTarget antTarget = project.getTarget(name); - if (antTarget != null) { - targets.add(antTarget); - } - } - myDependsTargets = targets.toArray(new AntTarget[targets.size()]); - } - } - return myDependsTargets; - } - } - - public void setDependsTargets(@NotNull AntTarget[] targets) { - synchronized (PsiLock.LOCK) { - myDependsTargets = targets; - } - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - myDependsTargets = null; - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTaskImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTaskImpl.java deleted file mode 100644 index 8fb4449512eb..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTaskImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntElementVisitor; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.AntTask; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class AntTaskImpl extends AntStructuredElementImpl implements AntTask { - - public AntTaskImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - } - - public AntTaskImpl(final AntElement parent, - final XmlTag sourceElement, - final AntTypeDefinition definition, - @NonNls final String nameElementAttribute) { - super(parent, sourceElement, definition, nameElementAttribute); - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntTask(this); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntTask["); - builder.append(getSourceElement().getName()); - builder.append("]"); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public AntElementRole getRole() { - return (!isMacroDefined() && !isPresetDefined() && !isTypeDefined()) ? AntElementRole.TASK_ROLE : AntElementRole.USER_TASK_ROLE; - } - - @Nullable - public AntStructuredElement getAntParent() { - return (AntStructuredElement)super.getAntParent(); - } - - public boolean isMacroDefined() { - final AntTypeDefinition def = getTypeDefinition(); - return def != null && def.getClassName().startsWith(AntMacroDefImpl.ANT_MACRODEF_NAME); - } - - public boolean isScriptDefined() { - final AntTypeDefinition def = getTypeDefinition(); - return def != null && def.getClassName().startsWith(AntScriptDefImpl.ANT_SCRIPTDEF_NAME); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTimestampFormatImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTimestampFormatImpl.java deleted file mode 100644 index 5c1bf0954d6f..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTimestampFormatImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.psi.PsiLock; -import com.intellij.psi.xml.XmlTag; - -/** - * @author Eugene Zhuravlev - * Date: May 14, 2007 - */ -public class AntTimestampFormatImpl extends AntStructuredElementImpl{ - public AntTimestampFormatImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition, AntFileImpl.PROPERTY); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - final AntElement parent = getAntParent(); - if (parent != null) { - parent.clearCaches(); - } - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTypeDefImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTypeDefImpl.java deleted file mode 100644 index e3df187137c4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntTypeDefImpl.java +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.config.impl.AntResourcesClassLoader; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.impl.reference.AntRefIdReference; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.lang.ant.psi.introspection.impl.AntTypeDefinitionImpl; -import com.intellij.lang.properties.IProperty; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.openapi.fileTypes.LanguageFileType; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.LocalTimeCounter; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.containers.ObjectCache; -import org.apache.tools.ant.PathTokenizer; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.TaskContainer; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.ref.SoftReference; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -public class AntTypeDefImpl extends AntTaskImpl implements AntTypeDef { - @NonNls private static final String CLASSPATH_ATTR = "classpath"; - @NonNls private static final String URI_ATTR = "uri"; - @NonNls private static final String RESOURCE_ATTR = "resource"; - @NonNls private static final String FILE_ATTR = AntFileImpl.FILE_ATTR; - @NonNls private static final String CLASSNAME_ATTR = "classname"; - @NonNls private static final String ADAPTER_ATTR = "adapter"; - @NonNls private static final String ADAPTTO_ATTR = "adaptto"; - @NonNls private static final String BASEDIR_ANT_REFERENCE = "${" + AntFileImpl.BASEDIR_ATTR + "}"; - - private static final ClassLoaderCache LOADERS_CACHE = new ClassLoaderCache(); - - private AntTypeDefinition[] myNewDefinitions; - private boolean myClassesLoaded; - private String myLocalizedError; - - public AntTypeDefImpl(final AntElement parent, final XmlTag sourceElement, final AntTypeDefinition definition) { - super(parent, sourceElement, definition); - getDefinitions(); - } - - public String toString() { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("AntTypeDef["); - builder.append(getSourceElement().getName()); - builder.append("]"); - final AntTypeDefinition[] defs = getDefinitions(); - if (defs.length != 0) { - builder.append(" classes={"); - builder.append(defs[0].getClassName()); - for (int i = 1; i < defs.length; ++i) { - builder.append(','); - builder.append(defs[i].getClassName()); - } - builder.append("}"); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - @NotNull - public List getFileReferenceAttributes() { - final List attribs = super.getFileReferenceAttributes(); - - final String cp = getClassPath(); - if (cp != null && cp.length() > 0 && !cp.contains(";") && !cp.contains(":")) { - // only single-entry classpath is accepted - final List _attribs = new ArrayList(attribs.size() + 1); - _attribs.addAll(attribs); - _attribs.add(CLASSPATH_ATTR); - return _attribs; - } - - return attribs; - } - - @Nullable - public String getDefinedName() { - return computeAttributeValue(getSourceElement().getAttributeValue(getNameElementAttribute())); - } - - @Nullable - public String getClassName() { - return computeAttributeValue(getSourceElement().getAttributeValue(CLASSNAME_ATTR)); - } - - @Nullable - public String getAdapterName() { - return computeAttributeValue(getSourceElement().getAttributeValue(ADAPTER_ATTR)); - } - - @Nullable - public String getAdaptToName() { - return computeAttributeValue(getSourceElement().getAttributeValue(ADAPTTO_ATTR)); - } - - @Nullable - public String getClassPath() { - return computeAttributeValue(getSourceElement().getAttributeValue(CLASSPATH_ATTR)); - } - - @Nullable - public String getUri() { - return computeAttributeValue(getSourceElement().getAttributeValue(URI_ATTR)); - } - - @Nullable - public String getFile() { - return computeAttributeValue(getSourceElement().getAttributeValue(FILE_ATTR)); - } - - @Nullable - public String getResource() { - return computeAttributeValue(getSourceElement().getAttributeValue(RESOURCE_ATTR)); - } - - @NonNls - @Nullable - public String getFormat() { - return computeAttributeValue(getSourceElement().getAttributeValue("format")); - } - - public void clearCaches() { - synchronized (PsiLock.LOCK) { - super.clearCaches(); - clearClassesCache(); - final AntFile file = getAntFile(); - if (file != null) { - file.clearCaches(); - } - } - } - - @NotNull - public AntTypeDefinition[] getDefinitions() { - synchronized (PsiLock.LOCK) { - if (myNewDefinitions == null || (!typesLoaded() && myLocalizedError == null /*don't give up loading until the error occurres or types are loaded*/)) { - myNewDefinitions = AntTypeDefinition.EMPTY_ARRAY; - final String classname = getClassName(); - if (classname != null) { - final AntStructuredElement parent = getAntParent(); - final AntFile antFile = parent != null? parent.getAntFile() : null; - loadClass(antFile, classname, getDefinedName(), getUri(),getAntParent()); - } - else { - final String resource = getResource(); - if (resource != null) { - loadResource(resource); - } - else { - final String file = getFile(); - if (file != null) { - loadFile(file); - } - } - } - } - return myNewDefinitions; - } - } - - public boolean typesLoaded() { - return myClassesLoaded; - } - - public void clearClassesCache() { - synchronized(PsiLock.LOCK) { - if (myNewDefinitions != null) { - final AntStructuredElement parent = getAntParent(); - if (parent != null) { - final AntProject antProject = !(parent instanceof AntProject)? parent.getAntProject() : null; - for (final AntTypeDefinition def : myNewDefinitions) { - parent.unregisterCustomType(def); - if (antProject != null) { - antProject.unregisterCustomType(def); - } - } - } - myNewDefinitions = null; - //myClassesLoaded = false; - } - } - } - - @Nullable - public String getLocalizedError() { - return myLocalizedError; - } - - public void acceptAntElementVisitor(@NotNull final AntElementVisitor visitor) { - visitor.visitAntTypedef(this); - } - - static void loadAntlibStream(@NotNull final InputStream antlibStream, final AntStructuredElement element, final String ns) { - final String nsPrefix = element.getSourceElement().getPrefixByNamespace(ns); - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - int nextByte; - while ((nextByte = antlibStream.read()) >= 0) { - builder.append((char)nextByte); - } - antlibStream.close(); - final XmlFile xmlFile = (XmlFile)createDummyFile("dummy.xml", StdFileTypes.XML, builder, element.getManager()); - final XmlDocument document = xmlFile.getDocument(); - if (document == null) return; - final XmlTag rootTag = document.getRootTag(); - if (rootTag == null) return; - for (final XmlTag tag : rootTag.getSubTags()) { - if (nsPrefix != null && nsPrefix.length() > 0) { - try { - tag.setName(nsPrefix + ':' + tag.getLocalName()); - } - catch (IncorrectOperationException e) { - continue; - } - } - final AntElement newElement = AntElementFactory.createAntElement(element, tag); - if (newElement instanceof AntTypeDef) { - for (final AntTypeDefinition def : ((AntTypeDef)newElement).getDefinitions()) { - if (element instanceof AntTypeDefImpl) { - final AntTypeDefImpl td = ((AntTypeDefImpl)element); - final AntTypeDefinition[] defs = td.myNewDefinitions != null ? td.myNewDefinitions : AntTypeDefinition.EMPTY_ARRAY; - td.myNewDefinitions = ArrayUtil.append(defs, def); - ((AntTypeDefinitionImpl)def).setDefiningElement(td); - } - } - } - } - } - catch (IOException e) { - if (element instanceof AntTypeDefImpl) { - final AntTypeDefImpl td = ((AntTypeDefImpl)element); - td.myClassesLoaded = false; - td.myLocalizedError = e.getLocalizedMessage(); - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - private void loadPropertiesStream(final InputStream propStream, final AntStructuredElement element) { - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - int nextByte; - while ((nextByte = propStream.read()) >= 0) { - builder.append((char)nextByte); - } - propStream.close(); - final PropertiesFile propFile = - (PropertiesFile)createDummyFile("dummy.properties", StdFileTypes.PROPERTIES, builder, element.getManager()); - final AntStructuredElement parent = getAntParent(); - final AntFile antFile = parent != null? parent.getAntFile() : null; - for (final IProperty property : propFile.getProperties()) { - loadClass(antFile, property.getValue(), property.getUnescapedKey(), getUri(),getAntParent()); - } - } - catch (IOException e) { - if (element instanceof AntTypeDefImpl) { - final AntTypeDefImpl td = ((AntTypeDefImpl)element); - td.myClassesLoaded = false; - td.myLocalizedError = e.getLocalizedMessage(); - } - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - private boolean isXmlFormat(@NonNls @NotNull final String resourceOfFileName) { - @NonNls final String format = getFormat(); - if (format != null) { - return format.equals("xml"); - } - return resourceOfFileName.endsWith(".xml"); - } - - private void loadResource(@NotNull final String resource) { - ClassLoader loader = getClassLoader(getClassPathUrls()); - if (loader != null) { - final InputStream stream = loader.getResourceAsStream(resource); - if (stream != null) { - myClassesLoaded = true; - if (!isXmlFormat(resource)) { - loadPropertiesStream(stream, this); - } - else { - loadAntlibStream(stream, this, getUri()); - } - } - } - } - - private void loadFile(final String file) { - final PsiFile psiFile = findFileByName(file, null); - if (psiFile != null) { - final VirtualFile vf = psiFile.getVirtualFile(); - if (vf != null) { - try { - final InputStream stream = vf.getInputStream(); - if (stream != null) { - myClassesLoaded = true; - if (!isXmlFormat(file)) { - loadPropertiesStream(stream, this); - } - else { - loadAntlibStream(stream, this, getUri()); - } - } - } - catch (IOException e) { - //ignore - } - } - } - } - - private AntTypeDefinitionImpl loadClass(final @Nullable AntFile antFile, - @Nullable final String classname, - @Nullable final String name, - @Nullable final String uri, - final AntStructuredElement parent) { - if (classname == null || name == null || name.length() == 0) { - return null; - } - ProgressManager.checkCanceled(); - final List urls = getClassPathUrls(); - Class clazz = null; - final ClassLoader loader = getClassLoader(urls); - if (loader != null) { - try { - clazz = loader.loadClass(classname); - } - catch (ClassNotFoundException e) { - myLocalizedError = e.getLocalizedMessage(); - clazz = null; - } - catch (NoClassDefFoundError e) { - myLocalizedError = e.getLocalizedMessage(); - clazz = null; - } - catch (UnsupportedClassVersionError e) { - myLocalizedError = e.getLocalizedMessage(); - clazz = null; - } - } - final String nsPrefix = (uri == null) ? null : getSourceElement().getPrefixByNamespace(uri); - final AntTypeId id = (nsPrefix == null) ? new AntTypeId(name) : new AntTypeId(name, nsPrefix); - AntTypeDefinitionImpl def; - if (clazz == null) { - def = new AntTypeDefinitionImpl(id, classname, isTask(), false); - } - else { - myClassesLoaded = true; - final boolean isTask = isTask(clazz); - def = (AntTypeDefinitionImpl)AntFileImpl.createTypeDefinition(id, clazz, isTask); - if (def == null) { // can be null if failed to introspect the class for some reason - def = new AntTypeDefinitionImpl(id, classname, isTask, isAssignableFrom(TaskContainer.class.getName(), clazz)); - } - else { - fixNestedDefinitions(def); - } - def.setIsProperty(isAssignableFrom(org.apache.tools.ant.taskdefs.Property.class.getName(), clazz)); - } - myNewDefinitions = ArrayUtil.append(myNewDefinitions, def); - def.setDefiningElement(this); - if (parent != null) { - if (!(parent instanceof AntProject)) { - // make custom definition available at project level first - final AntProject antProject = parent.getAntProject(); - if (antProject != null) { - antProject.registerCustomType(def); - } - } - parent.registerCustomType(def); - } - else { - if (antFile != null) { - antFile.registerCustomType(def); - } - } - if (antFile != null) { - for (final AntTypeId typeId : def.getNestedElements()) { - final String nestedClassName = def.getNestedClassName(typeId); - AntTypeDefinitionImpl nestedDef = (AntTypeDefinitionImpl)antFile.getBaseTypeDefinition(nestedClassName); - if (nestedDef == null) { - nestedDef = loadClass(antFile, nestedClassName, typeId.getName(), uri, null); - if (nestedDef != null) { - def.registerNestedType(nestedDef.getTypeId(), nestedDef.getClassName()); - } - } - } - } - return def; - } - - private void fixNestedDefinitions(final AntTypeDefinitionImpl def) { - // hack to overcome problems with poorly written custom tasks. - // For example: net.sf.antcontrib.logic.ForTask.createSequential() is defined to - // return java.langObject instead of org.apache.tools.ant.taskdefs.Sequential - - for (AntTypeId nestedTypeId : def.getNestedElements()) { - final String className = def.getNestedClassName(nestedTypeId); - if (CommonClassNames.JAVA_LANG_OBJECT.equals(className)) { - // check if such typeId is already mapped correct the definition's nested element - for (AntTypeDefinition typeDefinition : getAntFile().getBaseTypeDefinitions()) { - if (nestedTypeId.equals(typeDefinition.getTypeId()) && !CommonClassNames.JAVA_LANG_OBJECT.equals(typeDefinition.getClassName())) { - def.registerNestedType(nestedTypeId, typeDefinition.getClassName()); - break; - } - } - } - } - } - - private boolean isTask(final Class clazz) { - if (isTask()) { // in taskdef, the adapter is always set to Task - return true; - } - - final String adaptto = getAdaptToName(); - if (adaptto != null && isAssignableFrom(adaptto, clazz)) { - return isAssignableFrom(Task.class.getName(), clazz); - } - - final String adapter = getAdapterName(); - if (adapter != null) { - try { - final Class adapterClass = clazz.getClassLoader().loadClass(adapter); - return isAssignableFrom(Task.class.getName(), adapterClass); - } - catch (ClassNotFoundException ignored) { - } - catch (NoClassDefFoundError ignored) { - } - catch (UnsupportedClassVersionError ignored) { - } - } - - return isAssignableFrom(Task.class.getName(), clazz); - } - - private static boolean isAssignableFrom(final String baseClassName, final Class clazz) { - try { - final ClassLoader loader = clazz.getClassLoader(); - if (loader != null) { - final Class baseClass = loader.loadClass(baseClassName); - return baseClass.isAssignableFrom(clazz); - } - } - catch (ClassNotFoundException ignored) { - } - return false; - } - - private List getClassPathUrls() { - final List urls = getClassPathLocalUrls(); - AntElement parent = getAntParent(); - while (parent != null && !(parent instanceof AntProject)) { - if (parent instanceof AntTypeDefImpl) { - urls.addAll(((AntTypeDefImpl)parent).getClassPathLocalUrls()); - } - parent = parent.getAntParent(); - } - return urls; - } - - private List getClassPathLocalUrls() { - final List urls = new ArrayList(); - final String baseDir = computeAttributeValue(BASEDIR_ANT_REFERENCE); - // check classpath attribute - final String classpath = getClassPath(); - if (classpath != null) { - final PathTokenizer tokenizer = new PathTokenizer(classpath); - while (tokenizer.hasMoreTokens()) { - addUrl(baseDir, urls, tokenizer.nextToken()); - } - } - - final List files = new ArrayList(); - final HashSet processed = new HashSet(); // aux collection - // check 'classpathref' - for (PsiReference reference : getReferences()) { - ProgressManager.checkCanceled(); - if (reference instanceof AntRefIdReference) { - final PsiElement resolved = reference.resolve(); - if (resolved instanceof AntFilesProvider) { - files.addAll(((AntFilesProvider)resolved).getFiles(processed)); - } - } - } - // check nested elements - for (AntElement antElement : getChildren()) { - ProgressManager.checkCanceled(); - if (antElement instanceof AntFilesProvider) { - files.addAll(((AntFilesProvider)antElement).getFiles(processed)); - } - } - - for (File file : files) { - try { - //urls.add(file.toURL()); - // toURL() implementation invokes File.isDirectory() which, if called too often, may cause performance problems - urls.add(toLocalURL(file)); - } - catch (MalformedURLException e) { - } - } - - return urls; - } - - private static URL toLocalURL(final File file) throws MalformedURLException { - return new URL("file", "", FileUtil.toSystemIndependentName(file.getPath())); - } - - private static void addUrl(final String baseDir, final List urls, final String path) { - if (path != null) { - try { - File file = new File(path); - if (file.isAbsolute()) { - urls.add(toLocalURL(file)); - } - else { - if (baseDir != null) { - urls.add(toLocalURL(new File(baseDir, path))); - } - } - } - catch (MalformedURLException ignored) { - } - } - } - - @Nullable - private ClassLoader getClassLoader(final List urls) { - final AntFile file = getAntFile(); - final ClassLoader parentLoader = file != null ? file.getClassLoader() : null; - if (urls.size() == 0) { - return parentLoader; - } - - final ClassLoader cached = LOADERS_CACHE.getClassLoader(urls); - if (cached != null && parentLoader == cached.getParent()) { - return cached; - } - - final AntResourcesClassLoader loader = new AntResourcesClassLoader(urls, parentLoader, false, false); - LOADERS_CACHE.setClassLoader(urls, loader); - return loader; - } - - private boolean isTask() { - return "taskdef".equals(getSourceElement().getName()); - } - - private static PsiFile createDummyFile(@NonNls final String name, - final LanguageFileType type, - final CharSequence str, - final PsiManager manager) { - return PsiFileFactory.getInstance(manager.getProject()) - .createFileFromText(name, type, str, LocalTimeCounter.currentTime(), false, false); - } - - private static class CacheKey { - - public static final URL[] EMPTY_URL_ARRAY = new URL[0]; - private final List myUrls; - private final int myHashCode; - - public CacheKey(@NotNull final List urls) { - myUrls = urls; - int hashCode = 1; - for (URL url : urls) { - hashCode = 31 * hashCode + url.getPath().hashCode(); - } - myHashCode = hashCode; - } - - public final int hashCode() { - return myHashCode; - } - - public final boolean equals(Object obj) { - if (!(obj instanceof CacheKey)) { - return false; - } - final CacheKey entry = (CacheKey)obj; - final List urls = myUrls; - final List thatUrls = entry.myUrls; - if (urls.size() != thatUrls.size()) { - return false; - } - final Iterator urlsIt = urls.iterator(); - final Iterator thatUrlsIt = thatUrls.iterator(); - while (urlsIt.hasNext()) { - if (!FileUtil.pathsEqual(urlsIt.next().getPath(), thatUrlsIt.next().getPath())) { - return false; - } - } - return true; - } - } - - private static class ClassLoaderCache extends ObjectCache> { - - public ClassLoaderCache() { - super(256); - } - - @Nullable - public final synchronized ClassLoader getClassLoader(@NotNull final List urls) { - final CacheKey key = new CacheKey(urls); - final SoftReference ref = tryKey(key); - final ClassLoader result = (ref == null) ? null : ref.get(); - if (result == null && ref != null) { - remove(key); - } - return result; - } - - public final synchronized void setClassLoader(@NotNull final List urls, @NotNull final ClassLoader loader) { - cacheObject(new CacheKey(urls), new SoftReference(loader)); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/PropertiesBuilder.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/PropertiesBuilder.java deleted file mode 100644 index e865304455ba..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/PropertiesBuilder.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 13, 2007 - */ -public class PropertiesBuilder extends AntElementVisitor { - private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.psi.impl.PropertiesBuilder"); - - @NotNull private final AntFile myPropertyHolder; - private final Set myVisitedTargets = new HashSet(); - private final Set myVisitedFiles = new HashSet(); - private final Map> myPostponedProcessing = new HashMap>(); - private final List myDependentFiles = new ArrayList(); - - private PropertiesBuilder(@NotNull AntFile propertyHolder) { - myPropertyHolder = propertyHolder; - } - - @Override public void visitAntTypedef(final AntTypeDef def) { - // at this point all properties used in classpath for this typedef must be defined - // so to make sure the class set is complete, need to reload classes here - def.clearClassesCache(); - def.getDefinitions(); - } - - @Override public void visitAntFile(final AntFile antFile) { - if (!myVisitedFiles.contains(antFile)) { - myVisitedFiles.add(antFile); - final AntProject project = antFile.getAntProject(); - if (project != null) { - project.acceptAntElementVisitor(this); - ((AntProjectImpl)project).clearImports(); - } - } - } - - @Override public void visitAntTask(final AntTask task) { - if (task instanceof AntProperty) { - visitAntProperty((AntProperty)task); - } - else { - super.visitAntTask(task); - } - } - - public void visitAntStructuredElement(final AntStructuredElement element) { - if (element instanceof AntFilesProviderImpl) { - // need to clear cached files here - // because they might be cached at the moment when not all properties were loaded (e.g. because of antProject.getChildren()) - // and thus not all paths might resolve - ((AntFilesProviderImpl)element).clearCachedFiles(); - } - super.visitAntStructuredElement(element); - } - - @Override public void visitAntProject(final AntProject antProject) { - final Set projectTargets = new LinkedHashSet(); - for (PsiElement child : antProject.getChildren()) { - if (child instanceof AntElement) { - if (child instanceof AntTarget) { - final AntTarget antTarget = (AntTarget)child; - if (antProject.equals(antTarget.getAntProject())) { - // heuristic: do not collect imported targets - projectTargets.add(antTarget); - } - } - else { - ((AntElement)child).acceptAntElementVisitor(this); - } - } - } - - final AntTarget entryTarget = antProject.getDefaultTarget(); - if (entryTarget != null) { - entryTarget.acceptAntElementVisitor(this); - } - - projectTargets.removeAll(myVisitedTargets); - // process unvisited targets - for (AntTarget antTarget : projectTargets) { - antTarget.acceptAntElementVisitor(this); - } - // process postponed targets - final List list = myPostponedProcessing.get(antProject); - if (list != null) { - for (Runnable runnable : list) { - runnable.run(); - } - myPostponedProcessing.remove(antProject); - } - } - - @Override public void visitAntProperty(final AntProperty antProperty) { - final PropertiesFile propertiesFile = antProperty.getPropertiesFile(); - if (propertiesFile != null) { - myDependentFiles.add(propertiesFile.getContainingFile()); - } - - final String environment = antProperty.getEnvironment(); - if (environment != null) { - myPropertyHolder.addEnvironmentPropertyPrefix(environment); - } - - final String[] names = antProperty.getNames(); - if (names != null) { - for (String name : names) { - myPropertyHolder.setProperty(name, antProperty); - } - } - } - - @Override public void visitAntTarget(final AntTarget target) { - if (myVisitedTargets.contains(target)) { - return; - } - myVisitedTargets.add(target); - - final AntTarget[] dependsTargets = target.getDependsTargets(); - for (AntTarget dependsTarget : dependsTargets) { - dependsTarget.acceptAntElementVisitor(this); - } - - final String ifProperty = target.getConditionalPropertyName(AntTarget.ConditionalAttribute.IF); - if (ifProperty != null && myPropertyHolder.getProperty(ifProperty) == null) { - postponeTargetVisiting(target); - return; // skip target because 'if' property not defined - } - - final String unlessProperty = target.getConditionalPropertyName(AntTarget.ConditionalAttribute.UNLESS); - if (unlessProperty != null && myPropertyHolder.getProperty(unlessProperty) != null) { - postponeTargetVisiting(target); - return; // skip target because 'unless' property is defined - } - - visitTargetChildren(target); - } - - private void postponeTargetVisiting(final AntTarget target) { - final AntProject antProject = target.getAntProject(); - List list = myPostponedProcessing.get(antProject); - if (list == null) { - list = new ArrayList(); - myPostponedProcessing.put(antProject, list); - } - list.add(new Runnable() { - public void run() { - visitTargetChildren(target); - } - }); - } - - private void visitTargetChildren(final AntTarget target) { - for (PsiElement child : target.getChildren()) { - if (child instanceof AntElement) { - ((AntElement)child).acceptAntElementVisitor(this); - } - } - } - - @Override public void visitAntImport(final AntImport antImport) { - final AntFile antFile = antImport.getImportedFile(); - if (antFile != null) { - myDependentFiles.add(antFile); - visitAntFile(antFile); - } - } - - public static List defineProperties(AntFile file) { - final AntProject project = file.getAntProject(); - LOG.assertTrue(project != null); - - - final PropertiesBuilder builder = new PropertiesBuilder(file); - file.acceptAntElementVisitor(builder); - - /* - for (AntTarget target : builder.myVisitedTargets) { - if (target instanceof AntTargetImpl) { - definePseudoProperties((AntTargetImpl)target); - } - } - */ - return builder.myDependentFiles; - } - - /* - private static void definePseudoProperties(final AntTargetImpl target) { - final XmlTag se = target.getSourceElement(); - XmlAttribute propNameAttribute = se.getAttribute(AntFileImpl.IF_ATTR, null); - if (propNameAttribute == null) { - propNameAttribute = se.getAttribute(AntFileImpl.UNLESS_ATTR, null); - } - if (propNameAttribute != null) { - final XmlAttributeValue valueElement = propNameAttribute.getValueElement(); - if (valueElement != null) { - final String value = target.computeAttributeValue(valueElement.getValue()); - final AntFile propertyHolder = target.getAntFile(); - if (propertyHolder.getProperty(value) == null) { - target.setPropertyDefinitionElement(valueElement); - propertyHolder.setExternalProperty(value, target); - } - } - } - } - */ - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntAttributeReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntAttributeReference.java deleted file mode 100644 index 22020a7de486..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntAttributeReference.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -/** - * Ant attribute reference serves only for completion. - */ -public class AntAttributeReference extends AntGenericReference { - - public AntAttributeReference(final AntStructuredElement element, - final String str, - final TextRange textRange, - final XmlAttribute attribute) { - super(element, str, textRange, attribute); - } - - public AntStructuredElement getElement() { - return (AntStructuredElement)super.getElement(); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - return null; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - return null; - } - - public PsiElement resolve() { - return null; - } - - @NotNull - public Object[] getVariants() { - final AntTypeDefinition def = getElement().getTypeDefinition(); - return (def == null) ? EMPTY_ARRAY : def.getAttributes(); - } - - - public boolean shouldBeSkippedByAnnotator() { - return true; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementCompletionWrapper.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementCompletionWrapper.java deleted file mode 100644 index 443167e0fec1..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementCompletionWrapper.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.impl.AntElementImpl; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -public class AntElementCompletionWrapper extends AntElementImpl implements PsiNamedElement { - - private final String myName; - private final Project myProject; - private final AntElementRole myRole; - - public AntElementCompletionWrapper(final AntElement parent, final String name, @NotNull final Project project, final AntElementRole role) { - super(parent, null); - myName = name; - myProject = project; - myRole = role; - } - - public final String getText() { - return getName(); - } - - public boolean equals(final Object that) { - if (this == that) { - return true; - } - if (that instanceof AntElementCompletionWrapper) { - return myName.equals(((AntElementCompletionWrapper)that).myName); - } - return false; - } - - public int hashCode() { - return myName.hashCode(); - } - - public final String getName() { - return myName; - } - - @NotNull - public Project getProject() { - return myProject; - } - - public AntElementRole getRole() { - return myRole; - } - - public boolean isValid() { - return true; - } - - public boolean isPhysical() { - return false; - } - - public PsiElement setName(@NonNls @NotNull final String name) throws IncorrectOperationException { - throw new IncorrectOperationException("Can't rename ant completion element"); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementNameReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementNameReference.java deleted file mode 100644 index b2386f52706d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntElementNameReference.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.misc.PsiElementSetSpinAllocator; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.openapi.project.Project; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiElement; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.ArrayUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashSet; -import java.util.Set; - -public class AntElementNameReference extends AntGenericReference { - - public AntElementNameReference(final AntStructuredElement element) { - super(element); - } - - public AntElementNameReference(final AntStructuredElement element, final XmlAttribute attr) { - super(element, attr); - } - - public AntStructuredElement getElement() { - return (AntStructuredElement)super.getElement(); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntStructuredElement element = getElement(); - final AntTypeDefinition typeDef = element.getTypeDefinition(); - if (typeDef == null) return element; - - if (!(element instanceof AntTask)) { - final AntStructuredElement defElement = (AntStructuredElement)typeDef.getDefiningElement(); - if (defElement != null && (defElement instanceof AntPresetDef || ((defElement.getParent() instanceof AntMacroDef || defElement.getParent() instanceof AntScriptDef) && "element".equals(defElement.getSourceElement().getName())))) { - // renaming macrodef's or scriptdef's nested element - element.getSourceElement().setName(newElementName); - } - } - else { - AntTask task = (AntTask)element; - if (task.isMacroDefined() || task.isScriptDefined() || task.isPresetDefined() || task.isTypeDefined()) { - final XmlAttribute attr = getAttribute(); - if (attr == null) { - // renaming macrodef, presetdef or typedef/taskdef itself - task.getSourceElement().setName(newElementName); - } - else { - attr.setName(newElementName); - } - } - } - - return element; - } - - @Nullable - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - if (element instanceof AntStructuredElement) { - return handleElementRename(((AntStructuredElement)element).getName()); - } - return getElement(); - } - - public PsiElement resolveInner() { - final AntStructuredElement element = getElement(); - final AntTypeDefinition elementDef = element.getTypeDefinition(); - if (elementDef != null) { - final PsiElement definingElement = elementDef.getDefiningElement(); - if (element.isPresetDefined() || element.isTypeDefined()) { - return definingElement; - } - if (!(element instanceof AntTask)) { - return (definingElement == null) ? findClass(elementDef, element) : definingElement; - } - AntTask task = (AntTask)element; - if (task.isMacroDefined() || task.isScriptDefined()) { - final XmlAttribute attr = getAttribute(); - if (definingElement != null && attr != null) { - final String attribName = attr.getName(); - for (PsiElement child : definingElement.getChildren()) { - if (child instanceof AntStructuredElement && attribName.equals(((AntStructuredElement)child).getName())) { - return child; - } - } - } - return definingElement; - } - return findClass(elementDef, element); - } - return null; - } - - public boolean shouldBeSkippedByAnnotator() { - return true; - } - - @NotNull - public Object[] getVariants() { - if (getAttribute() != null) { - return EMPTY_ARRAY; // scriptdef or mactodef params will be handled by XML implementation - } - final AntStructuredElement parent = (AntStructuredElement)getElement().getAntParent(); - if (parent == null) { - return EMPTY_ARRAY; - } - AntTypeDefinition def = parent.getTypeDefinition(); - if (def == null) { - def = parent.getAntProject().getTypeDefinition(); - if (def == null) { - return EMPTY_ARRAY; - } - } - final AntFile antFile = parent.getAntFile(); - final Project project = antFile.getProject(); - final Set ids = PsiElementSetSpinAllocator.alloc(); - try { - for (final AntTypeId id : def.getNestedElements()) { - ids.add(new AntElementCompletionWrapper(parent, id.getName() + " ", project, AntElementRole.TASK_ROLE)); - } - if (def.isAllTaskContainer()) { - new Object() { - final Set processedFiles = new HashSet(); - final Set processedTypes = new HashSet(); - - void walkFiles(AntFile file) { - if (processedFiles.contains(file)) { - return; - } - processedFiles.add(file); - - for (final AntTypeDefinition _def : file.getBaseTypeDefinitions()) { - if (_def.isTask()) { - final AntTypeId typeId = _def.getTypeId(); - if (!processedTypes.contains(typeId)) { - processedTypes.add(typeId); - ids.add(new AntElementCompletionWrapper(parent, typeId.getName() + " ", project, AntElementRole.TASK_ROLE)); - } - } - } - - for (AntFile imported : file.getAntProject().getImportedFiles()) { - walkFiles(imported); - } - } - }.walkFiles(antFile); - } - return ArrayUtil.toObjectArray(ids); - } - finally { - PsiElementSetSpinAllocator.dispose(ids); - } - } - - @Nullable - private static PsiElement findClass(final AntTypeDefinition elementDef, final AntStructuredElement element) { - final String clazz = elementDef.getClassName(); - return JavaPsiFacade.getInstance(element.getProject()).findClass(clazz, GlobalSearchScope.allScope(element.getProject())); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEndElementNameReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEndElementNameReference.java deleted file mode 100644 index cf3d1e20b405..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEndElementNameReference.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.lookup.AutoCompletionPolicy; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupElementBuilder; -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -public class AntEndElementNameReference extends AntElementNameReference { - private final TextRange myRange; - private final boolean myIsTagClosed; - - public AntEndElementNameReference(final AntStructuredElement element, TextRange range, final boolean isClosed) { - super(element); - myRange = range; - myIsTagClosed = isClosed; - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - return getElement(); - } - - @NotNull - public LookupElement[] getVariants() { - final AntStructuredElement element = getElement(); - final XmlTag xmlTag = element.getSourceElement(); - final String completionText = myIsTagClosed ? element.getSourceElement().getName() : element.getSourceElement().getName() + ">"; - final AntElementCompletionWrapper wrapper = - new AntElementCompletionWrapper((AntElement)element.getParent(), completionText, element.getProject(), AntElementRole.TASK_ROLE) { - public PsiElement getContext() { - return xmlTag; - } - }; - return new LookupElement[] {AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy( - LookupElementBuilder.create(wrapper, completionText))}; - } - - public TextRange getRangeInElement() { - return myRange; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEntityReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEntityReference.java deleted file mode 100644 index a33acc12c9f0..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEntityReference.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; - -public class AntEntityReference implements PsiReference { - - private final AntElement myElement; - private final PsiReference myXmlRef; - - public AntEntityReference(final AntElement element, final PsiReference xmlRef) { - myElement = element; - myXmlRef = xmlRef; - } - - public PsiElement getElement() { - return myElement; - } - - public TextRange getRangeInElement() { - return myXmlRef.getRangeInElement(); - } - - @Nullable - public PsiElement resolve() { - return myXmlRef.resolve(); - } - - @NotNull - public String getCanonicalText() { - return myXmlRef.getCanonicalText(); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - return myXmlRef.handleElementRename(newElementName); - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - return myXmlRef.bindToElement(element); - } - - public boolean isReferenceTo(PsiElement element) { - return myXmlRef.isReferenceTo(element); - } - - @NotNull - public Object[] getVariants() { - return EMPTY_ARRAY; - } - - public boolean isSoft() { - return myXmlRef.isSoft(); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReference.java deleted file mode 100644 index e6311dc6ed0c..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReference.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.psi.AntImport; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileSystemItem; -import com.intellij.psi.impl.source.resolve.reference.impl.CachingReference; -import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; -import com.intellij.psi.util.PsiUtilBase; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; - -public class AntFileReference extends FileReference implements AntReference { - public AntFileReference(final AntFileReferenceSet set, final TextRange range, final int index, final String text) { - super(set, range, index, text); - } - - @Nullable - public String getText() { - final String _path = getElement().computeAttributeValue(super.getText()); - if (_path == null) { - return null; - } - final String text = FileUtil.toSystemIndependentName(_path); - return text.endsWith("/")? text.substring(0, text.length() - "/".length()) : text; - } - - public AntStructuredElement getElement() { - return (AntStructuredElement)super.getElement(); - } - - @NotNull - public AntFileReferenceSet getFileReferenceSet() { - return (AntFileReferenceSet)super.getFileReferenceSet(); - } - - public String getUnresolvedMessagePattern() { - return AntBundle.message("file.doesnt.exist", getCanonicalRepresentationText()); - } - - public boolean shouldBeSkippedByAnnotator() { - return isSoft(); - } - - public void setShouldBeSkippedByAnnotator(boolean value) { - } - - @NotNull - public IntentionAction[] getFixes() { - return IntentionAction.EMPTY_ARRAY; - } - - @Nullable - public String getCanonicalRepresentationText() { - final AntStructuredElement element = getElement(); - final String value = getCanonicalText(); - return element.computeAttributeValue(value); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntStructuredElement antElement = getElement(); - final PsiElement element = getManipulatorElement(); - CachingReference.getManipulator(element).handleContentChange(element, getRangeInElement().shiftRight( - antElement.getTextRange().getStartOffset() - element.getTextRange().getStartOffset()), newElementName); - return antElement; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - if (!(element instanceof PsiFileSystemItem)) throw new IncorrectOperationException("Cannot bind to element"); - final VirtualFile dstVFile = PsiUtilBase.getVirtualFile(element); - final AntStructuredElement se = getElement(); - final PsiFile file = se.getContainingFile(); - if (dstVFile == null) throw new IncorrectOperationException("Cannot bind to non-physical element:" + element); - VirtualFile currentFile = file.getVirtualFile(); - if (!(se instanceof AntImport)) { - final String baseDir = se.getAntProject().getBaseDir(); - if (baseDir != null && baseDir.length() > 0) { - final File f = new File(currentFile.getParent().getPath(), baseDir); - currentFile = LocalFileSystem.getInstance().findFileByPath(f.getAbsolutePath().replace(File.separatorChar, '/')); - } - } - final String newName = VfsUtil.getPath(currentFile, dstVFile, '/'); - if (newName == null) { - throw new IncorrectOperationException( - "Cannot find path between files; src = " + currentFile.getPresentableUrl() + "; dst = " + dstVFile.getPresentableUrl()); - } - final PsiElement me = getManipulatorElement(); - TextRange range = new TextRange(getFileReferenceSet().getStartInElement(), getRangeInElement().getEndOffset()); - range = range.shiftRight(se.getTextRange().getStartOffset() - me.getTextRange().getStartOffset()); - return CachingReference.getManipulator(me).handleContentChange(me, range, newName); - } - - private PsiElement getManipulatorElement() { - return getFileReferenceSet().getManipulatorElement(); - } -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReferenceSet.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReferenceSet.java deleted file mode 100644 index 3bb62d21370a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntFileReferenceSet.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2000-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.psi.*; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.newvfs.ManagingFS; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFileSystemItem; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet; -import com.intellij.psi.xml.XmlAttributeValue; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.Collections; - -public class AntFileReferenceSet extends FileReferenceSet { - - private final XmlAttributeValue myValue; - - public AntFileReferenceSet(final AntStructuredElement element, final XmlAttributeValue value, final PsiReferenceProvider provider) { - super(cutTrailingSlash(FileUtil.toSystemIndependentName(value.getValue())), element, - value.getTextRange().getStartOffset() - element.getTextRange().getStartOffset() + 1, provider, SystemInfo.isFileSystemCaseSensitive); - myValue = value; - } - - private static String cutTrailingSlash(String path) { - if (path.endsWith("/")) { - return path.substring(0, path.length() - 1); - } - return path; - } - - protected boolean isSoft() { - final AntStructuredElement element = getElement(); - if (!(element instanceof AntImport || - element instanceof AntTypeDef || - element instanceof AntProperty || - element instanceof AntAnt)) { - return true; - } - if (element instanceof AntProperty) { - return ((AntProperty)element).getFileName() != null; - } - return false; - } - - public AntFileReference createFileReference(final TextRange range, final int index, final String text) { - return new AntFileReference(this, range, index, text); - } - - public AntStructuredElement getElement() { - return (AntStructuredElement)super.getElement(); - } - - @Nullable - public String getPathString() { - return getElement().computeAttributeValue(super.getPathString()); - } - - public boolean isAbsolutePathReference() { - if (super.isAbsolutePathReference()) { - return true; - } - return FileUtil.isAbsolute(getPathString()); - } - // todo: correct context for "output" attribute file reference of the "ant" task - @NotNull - public Collection computeDefaultContexts() { - final AntStructuredElement element = getElement(); - final AntFile antFile = element.getAntFile(); - if (antFile != null) { - VirtualFile vFile = antFile.getContainingPath(); - if (isAbsolutePathReference()) { - if (SystemInfo.isWindows) { - vFile = ManagingFS.getInstance().findRoot("", LocalFileSystem.getInstance()); - } - else { - vFile = LocalFileSystem.getInstance().findFileByPath("/"); - } - } - else { - if (!(element instanceof AntImport)) { - final String basedir = element.computeAttributeValue("${basedir}"); - assert basedir != null; - vFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(basedir)); - } - } - - if (vFile != null) { - final PsiDirectory directory = antFile.getViewProvider().getManager().findDirectory(vFile); - if (directory != null) { - return Collections.singleton(directory); - } - } - } - return super.computeDefaultContexts(); - } - - XmlAttributeValue getManipulatorElement() { - return myValue; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntGenericReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntGenericReference.java deleted file mode 100644 index a4f1b6668c7a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntGenericReference.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.impl.source.resolve.reference.impl.CachingReference; -import com.intellij.psi.xml.XmlAttribute; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class AntGenericReference extends CachingReference implements AntReference { - private final AntElement myAntElement; - private final String myText; - private final TextRange myTextRange; - private final XmlAttribute myAttribute; - - protected AntGenericReference(final AntElement element, final String str, final TextRange textRange, final XmlAttribute attribute) { - myAntElement = element; - myText = str; - myTextRange = textRange; - myAttribute = attribute; - } - - protected AntGenericReference(final AntStructuredElement element, final XmlAttribute attr) { - myAntElement = element; - myText = (attr == null) ? element.getSourceElement().getName() : attr.getName(); - int startInElement = (attr == null) ? 1 : attr.getTextRange().getStartOffset() - element.getTextRange().getStartOffset(); - myTextRange = new TextRange(startInElement, myText.length() + startInElement); - myAttribute = attr; - } - - protected AntGenericReference(final AntStructuredElement element) { - this(element, null); - } - - public AntElement getElement() { - return myAntElement; - } - - public TextRange getRangeInElement() { - return myTextRange; - } - - @NotNull - public String getCanonicalText() { - return myText; - } - - public boolean shouldBeSkippedByAnnotator() { - return false; - } - - public void setShouldBeSkippedByAnnotator(boolean value) {} - - @NotNull - public IntentionAction[] getFixes() { - return IntentionAction.EMPTY_ARRAY; - } - - protected XmlAttribute getAttribute() { - return myAttribute; - } - - @Nullable - public String getCanonicalRepresentationText() { - final AntElement element = getElement(); - final String value = getCanonicalText(); - if( element instanceof AntStructuredElement) { - return ((AntStructuredElement)element).computeAttributeValue(value); - } - return element.getAntProject().computeAttributeValue(value); - } - - @Override - public PsiElement resolveInner() { - throw new UnsupportedOperationException(); - } - - public String getUnresolvedMessagePattern() { - return CodeInsightBundle.message("error.cannot.resolve.default.message"); - } -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntMacroDefParameterReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntMacroDefParameterReference.java deleted file mode 100644 index 0f6bb162433c..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntMacroDefParameterReference.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.psi.AntAllTasksContainer; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntMacroDef; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.*; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringSetSpinAllocator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Set; - -public class AntMacroDefParameterReference extends AntGenericReference { - - private final XmlElement myXmlElement; - - public AntMacroDefParameterReference(final AntElement antElement, - final String str, - final TextRange textRange, - final XmlElement xmlElement) { - super(antElement, str, textRange, null); - myXmlElement = xmlElement; - } - - @NotNull - public String getCanonicalText() { - String text = super.getCanonicalText(); - if (text.indexOf("${") >= 0) { - final AntStructuredElement se = PsiTreeUtil.getParentOfType(getElement(), AntStructuredElement.class, true); - if (se != null) { - text = se.computeAttributeValue(text); - } - } - return text; - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntElement element = getElement(); - final String oldName = getCanonicalText(); - if (oldName != null && !oldName.equals(newElementName)) { - if (myXmlElement instanceof XmlAttributeValue) { - final String text = myXmlElement.getText(); - if (text.length() > 2) { - ((XmlAttribute)myXmlElement.getParent()) - .setValue(text.substring(1, text.length() - 1).replace("@{" + oldName + '}', "@{" + newElementName + '}')); - } - } - else { - final XmlTagValue tagValue = ((XmlTag)myXmlElement).getValue(); - tagValue.setText(tagValue.getText().replace("@{" + oldName + '}', "@{" + newElementName + '}')); - } - //element.subtreeChanged(); - } - return element; - } - - @Nullable - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - return handleElementRename(((PsiNamedElement)element).getName()); - } - - public PsiElement resolveInner() { - final AntMacroDef macrodef = PsiTreeUtil.getParentOfType(getElement(), AntMacroDef.class, true); - if (macrodef != null) { - final String name = getCanonicalText(); - if (name != null) { - for (final PsiElement child : macrodef.getChildren()) { - if (child instanceof AntStructuredElement && !(child instanceof AntAllTasksContainer)) { - if (name.equals(((AntStructuredElement)child).getName())) { - return child; - } - } - } - } - } - return null; - } - - @NotNull - @SuppressWarnings({"HardCodedStringLiteral"}) - public Object[] getVariants() { - final Set variants = StringSetSpinAllocator.alloc(); - try { - AntMacroDef macrodef = PsiTreeUtil.getParentOfType(getElement(), AntMacroDef.class, true); - if (macrodef != null) { - for (PsiElement child : macrodef.getChildren()) { - if (child instanceof AntStructuredElement) { - AntStructuredElement element = (AntStructuredElement)child; - if (element.getSourceElement().getName().equals("attribute")) { - variants.add(element.getName()); - } - } - } - } - final int count = variants.size(); - return (count == 0) ? EMPTY_ARRAY : variants.toArray(new String[count]); - } - finally { - StringSetSpinAllocator.dispose(variants); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntPropertyReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntPropertyReference.java deleted file mode 100644 index 66cefec931a1..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntPropertyReference.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.AntElementRole; -import com.intellij.lang.ant.misc.PsiElementSetSpinAllocator; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntProperty; -import com.intellij.lang.ant.quickfix.AntChangeContextFix; -import com.intellij.lang.ant.quickfix.AntCreatePropertyFix; -import com.intellij.lang.properties.IProperty; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.StringSetSpinAllocator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -public class AntPropertyReference extends AntGenericReference { - public AntPropertyReference(final AntElement antElement, final String str, final TextRange textRange, final XmlAttribute attribute) { - super(antElement, str, textRange, attribute); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntElement element = getElement(); - final String oldName = getCanonicalText(); - final XmlAttribute attr = getAttribute(); - final XmlAttributeValue attrValue = attr.getValueElement(); - if (attrValue != null) { - final int valueStartOffset = attrValue.getTextRange().getStartOffset() - element.getTextRange().getStartOffset() + 1; - final String value = attr.getValue(); - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - final AntFile antFile = element.getAntFile(); - final AntProperty resolved = antFile != null? antFile.getProperty(oldName) : null; - final String prefix = resolved != null? resolved.getPrefix() : null; - final int startOffset = getRangeInElement().getStartOffset(); - final int endOffset = getRangeInElement().getEndOffset(); - if (valueStartOffset < startOffset) { - builder.append(value.substring(0, startOffset - valueStartOffset)); - } - if (prefix != null) { - builder.append(prefix).append("."); - } - builder.append(newElementName); - if (endOffset < valueStartOffset + value.length()) { - builder.append(value.substring(endOffset - valueStartOffset)); - } - attr.setValue(builder.toString()); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - return element; - } - - @Nullable - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - return handleElementRename(((PsiNamedElement)element).getName()); - } - - public PsiElement resolveInner() { - final AntElement elem = getElement(); - final AntFile contextFile = null/*AntConfigurationBase.getInstance(elem.getProject()).getEffectiveContextFile(elem.getAntFile())*/; - if (contextFile == null) { - return null; - } - final String text = getCanonicalText(); - AntProperty resolved = contextFile.getProperty(text); - - if (resolved != null) { - final String propName = cutPrefix(text, resolved.getPrefix()); - final PropertiesFile propFile = resolved.getPropertiesFile(); - if (propFile != null) { - IProperty property = propFile.findPropertyByKey(propName); - return property == null ? null : property.getPsiElement(); - } - return resolved.getFormatElement(propName); - } - return null; - } - - private static String cutPrefix(final String text, final String prefix) { - if (prefix != null && text.startsWith(prefix) && prefix.length() < text.length() && text.charAt(prefix.length()) == '.') { - return text.substring(prefix.length() + 1); - } - return text; - } - - public String getUnresolvedMessagePattern() { - return AntBundle.message("unknown.property", getCanonicalText()); - } - - @NotNull - public Object[] getVariants() { - final AntElement currentElement = getElement(); - final Set variants = PsiElementSetSpinAllocator.alloc(); - try { - final AntFile antFile = currentElement.getAntFile(); - final Project project = currentElement.getProject(); - for (final AntProperty property : antFile.getProperties()) { - if (currentElement == property) { - continue; - } - final String[] names = property.getNames(); - if (names != null) { - for (final String name : names) { - variants.add(new AntElementCompletionWrapper((AntElement)property.getParent(), name, project, AntElementRole.PROPERTY_ROLE)); - } - } - } - return ArrayUtil.toObjectArray(variants); - } - finally { - PsiElementSetSpinAllocator.dispose(variants); - } - } - - @NotNull - public IntentionAction[] getFixes() { - final String name = getCanonicalRepresentationText(); - if (name == null || name.length() == 0) return IntentionAction.EMPTY_ARRAY; - - final List result = new ArrayList(); - final AntProject project = getElement().getAntProject(); - result.add(new AntCreatePropertyFix(this)); - final Set files = StringSetSpinAllocator.alloc(); - try { - for (final PsiElement child : project.getChildren()) { - if (child instanceof AntProperty) { - final PropertiesFile propFile = ((AntProperty)child).getPropertiesFile(); - if (propFile != null) { - final String fileName = propFile.getName(); - if (!files.contains(fileName)) { - files.add(fileName); - result.add(new AntCreatePropertyFix(this, propFile)); - } - } - } - } - } - finally { - StringSetSpinAllocator.dispose(files); - } - result.add(new AntChangeContextFix()); - return result.toArray(new IntentionAction[result.size()]); - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntRefIdReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntRefIdReference.java deleted file mode 100644 index 95a5305d4cf2..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntRefIdReference.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.PsiElementSetSpinAllocator; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Set; - -public class AntRefIdReference extends AntGenericReference { - - public AntRefIdReference(final AntElement antElement, final String str, final TextRange textRange, final XmlAttribute attribute) { - super(antElement, str, textRange, attribute); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntElement element = getElement(); - if (element instanceof AntStructuredElement) { - getAttribute().setValue(newElementName); - } - return element; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - if (element instanceof AntStructuredElement) { - final PsiNamedElement psiNamedElement = (PsiNamedElement)element; - return handleElementRename(psiNamedElement.getName()); - } - throw new IncorrectOperationException("Can bind only to ant structured elements."); - } - - - public AntStructuredElement getElement() { - return (AntStructuredElement)super.getElement(); - } - - public String getUnresolvedMessagePattern() { - return AntBundle.message("cannot.resolve.refid", getCanonicalRepresentationText()); - } - - public PsiElement resolveInner() { - final String id = getCanonicalRepresentationText(); - final Set elementsDepthStack = PsiElementSetSpinAllocator.alloc(); - try { - final AntStructuredElement elem = getElement(); - final AntFile contextFile = null/*AntConfigurationBase.getInstance(elem.getProject()).getEffectiveContextFile(elem.getAntFile())*/; - return resolve(id, contextFile.getAntProject(), elementsDepthStack); - } - finally { - PsiElementSetSpinAllocator.dispose(elementsDepthStack); - } - } - - @NotNull - public Object[] getVariants() { - final Set variants = PsiElementSetSpinAllocator.alloc(); - try { - final Set elementsDepthStack = PsiElementSetSpinAllocator.alloc(); - try { - getVariants(getElement().getAntProject(), variants, elementsDepthStack); - return ArrayUtil.toObjectArray(variants); - } - finally { - PsiElementSetSpinAllocator.dispose(elementsDepthStack); - } - } - finally { - PsiElementSetSpinAllocator.dispose(variants); - } - } - - @Nullable - private static AntElement resolve(final String id, final AntProject project, final Set elementsDepthStack) { - if (elementsDepthStack.contains(project)) return null; - elementsDepthStack.add(project); - try { - AntElement refId = project.getElementByRefId(id); - if (refId == null) { - for (final AntFile file : project.getImportedFiles()) { - refId = resolve(id, file.getAntProject(), elementsDepthStack); - if (refId != null) break; - } - } - return refId; - } - finally { - elementsDepthStack.remove(project); - } - } - - private static void getVariants(final AntProject project, final Set variants, final Set elementsDepthStack) { - if (elementsDepthStack.contains(project)) return; - elementsDepthStack.add(project); - try { - for (final String id : project.getRefIds()) { - final AntElement refElement = project.getElementByRefId(id); - if (refElement != null) { - variants.add(refElement); - } - } - for (final AntFile file : project.getImportedFiles()) { - getVariants(file.getAntProject(), variants, elementsDepthStack); - } - } - finally { - elementsDepthStack.remove(project); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReference.java deleted file mode 100644 index e45d4d61cbe3..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReference.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.intention.IntentionAction; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntReference { - - boolean shouldBeSkippedByAnnotator(); - - void setShouldBeSkippedByAnnotator(boolean value); - - String getUnresolvedMessagePattern(); - - @NotNull - IntentionAction[] getFixes(); - - @Nullable - String getCanonicalRepresentationText(); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReferenceProvidersRegistry.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReferenceProvidersRegistry.java deleted file mode 100644 index 191970c0431d..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntReferenceProvidersRegistry.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.impl.*; -import com.intellij.lang.ant.psi.impl.reference.providers.*; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.util.containers.HashMap; - -import java.util.Map; - -public class AntReferenceProvidersRegistry { - private static final Map ourProviders; - - static { - ourProviders = new HashMap(); - - final AntAttributeReferenceProvider attrProvider = new AntAttributeReferenceProvider(); - final AntElementNameReferenceProvider nameProvider = new AntElementNameReferenceProvider(); - final AntPropertyReferenceProvider propProvider = new AntPropertyReferenceProvider(); - final AntFileReferenceProvider fileProvider = new AntFileReferenceProvider(); - final AntRefIdReferenceProvider refIdProvider = new AntRefIdReferenceProvider(); - final AntMacroDefParameterReferenceProvider macroParamsProvider = new AntMacroDefParameterReferenceProvider(); - final AntSingleTargetReferenceProvider targetProvider = new AntSingleTargetReferenceProvider(); - - ourProviders.put(AntProjectImpl.class, new PsiReferenceProvider[]{targetProvider, nameProvider, attrProvider}); - ourProviders.put(AntTargetImpl.class, new PsiReferenceProvider[]{new AntTargetListReferenceProvider(), propProvider, refIdProvider, - nameProvider, attrProvider}); - ourProviders.put(AntStructuredElementImpl.class, new PsiReferenceProvider[]{fileProvider, propProvider, refIdProvider, nameProvider, - attrProvider, macroParamsProvider}); - ourProviders.put(AntTimestampFormatImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntTaskImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntPropertyImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntMacroDefImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntPresetDefImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntTypeDefImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntImportImpl.class, new PsiReferenceProvider[]{fileProvider, propProvider, nameProvider, attrProvider}); - ourProviders.put(AntAntImpl.class, new PsiReferenceProvider[]{fileProvider, propProvider, nameProvider, attrProvider, - targetProvider, macroParamsProvider}); - ourProviders.put(AntBuildNumberImpl.class, - new PsiReferenceProvider[]{fileProvider, propProvider, nameProvider, attrProvider, macroParamsProvider}); - ourProviders.put(AntCallImpl.class, new PsiReferenceProvider[]{targetProvider, propProvider, refIdProvider, nameProvider, - attrProvider, macroParamsProvider}); - - ourProviders.put(AntDirSetImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntFileListImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntFileSetImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - ourProviders.put(AntPathImpl.class, ourProviders.get(AntStructuredElementImpl.class)); - } - - private AntReferenceProvidersRegistry() { - } - - public static PsiReferenceProvider[] getProvidersByElement(final AntElement element) { - PsiReferenceProvider[] result = ourProviders.get(element.getClass()); - return (result != null) ? result : PsiReferenceProvider.EMPTY_ARRAY; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntTargetReference.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntTargetReference.java deleted file mode 100644 index db948225b48f..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntTargetReference.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference; - -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.AntSupport; -import com.intellij.lang.ant.config.AntConfigurationBase; -import com.intellij.lang.ant.psi.*; -import com.intellij.lang.ant.psi.impl.AntAntImpl; -import com.intellij.lang.ant.quickfix.AntChangeContextFix; -import com.intellij.lang.ant.quickfix.AntCreateTargetFix; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLock; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class AntTargetReference extends AntGenericReference { - private boolean myShouldBeSkippedByAnnotator; - - public AntTargetReference(final AntElement antElement, final String str, final TextRange textRange, final XmlAttribute attribute) { - super(antElement, str, textRange, attribute); - setShouldBeSkippedByAnnotator(false); - } - - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - final AntElement element = getElement(); - if (element instanceof AntProject || element instanceof AntCall || element instanceof AntAnt) { - getAttribute().setValue(newElementName); - } - else if (element instanceof AntTarget) { - int start = getElementStartOffset() + getReferenceStartOffset() - getAttributeValueStartOffset(); - final String value = getAttribute().getValue(); - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - if (start > 0) { - builder.append(value.substring(0, start)); - } - builder.append(newElementName); - if (value.length() > start + getRangeInElement().getLength()) { - builder.append(value.substring(start + getRangeInElement().getLength())); - } - getAttribute().setValue(builder.toString()); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - return element; - } - - @Nullable - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { - if (element instanceof AntTarget) { - final PsiNamedElement psiNamedElement = (PsiNamedElement)element; - return handleElementRename(psiNamedElement.getName()); - } - throw new IncorrectOperationException("Can bind only to ant targets."); - } - - - public PsiElement resolveInner() { - final String name = getCanonicalRepresentationText(); - if (name == null) return null; - - final AntElement element = getElement(); - final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(element.getProject()); - AntTarget result = null; - - if (element instanceof AntAntImpl) { - final PsiFile psiFile = ((AntAntImpl)element).getCalledAntFile(); - if (psiFile != null) { - AntFile antFile = AntSupport.getAntFile(psiFile); - if (antFile != null) { - final AntFile context = null/*antConfig.getEffectiveContextFile(antFile)*/; - - assert context != null; - - final AntProject project = context.getAntProject(); - if (project != null) { - result = resolveTargetImpl(name, project); - } - } - } - } - - if (result == null) { - final AntFile context = null/*antConfig.getEffectiveContextFile(element.getAntFile())*/; - - assert context != null; - - result = resolveTargetImpl(name, context.getAntProject()); - } - - return result; - } - - private static AntTarget resolveTargetImpl(final String name, final AntProject project) { - final AntTarget result = project.getTarget(name); - if (result != null) { - return result; - } - for (final AntTarget target : project.getImportedTargets()) { - if (name.equals(target.getName())) { - return target; - } - } - for (final AntTarget target : project.getImportedTargets()) { - if (name.equals(target.getQualifiedName())) { - return target; - } - } - return null; - } - - public String getUnresolvedMessagePattern() { - return AntBundle.message("cannot.resolve.target", getCanonicalRepresentationText()); - } - - public boolean shouldBeSkippedByAnnotator() { - synchronized (PsiLock.LOCK) { - return myShouldBeSkippedByAnnotator; - } - } - - public void setShouldBeSkippedByAnnotator(boolean value) { - synchronized (PsiLock.LOCK) { - myShouldBeSkippedByAnnotator = value; - } - } - - @NotNull - public Object[] getVariants() { - final AntElement element = getElement(); - if (element instanceof AntAntImpl) { - final PsiFile psiFile = ((AntAntImpl)element).getCalledAntFile(); - if (psiFile != null) { - AntFile antFile; - if (psiFile instanceof AntFile) { - antFile = (AntFile)psiFile; - } - else { - antFile = AntSupport.getAntFile(psiFile); - } - final AntProject project = (antFile == null) ? null : antFile.getAntProject(); - if (project != null) { - return project.getTargets(); - } - } - } - - List result = new ArrayList(); - - final AntProject project = element.getAntProject(); - final AntTarget[] targets = project.getTargets(); - for (final AntTarget target : targets) { - if (target != element) { - result.add(target); - } - } - - ContainerUtil.addAll(result, project.getImportedTargets()); - - return result.toArray(); - } - - @NotNull - public IntentionAction[] getFixes() { - final String name = getCanonicalRepresentationText(); - if (name == null || name.length() == 0) return IntentionAction.EMPTY_ARRAY; - - final AntProject project = getElement().getAntProject(); - final AntFile[] importedFiles = project.getImportedFiles(); - final List result = new ArrayList(importedFiles.length + 1); - result.add(new AntCreateTargetFix(this)); - for (final AntFile file : importedFiles) { - if (file.isPhysical()) { - result.add(new AntCreateTargetFix(this, file)); - } - } - result.add(new AntChangeContextFix()); - return result.toArray(new IntentionAction[result.size()]); - } - - private int getElementStartOffset() { - return getElement().getTextRange().getStartOffset(); - } - - private int getReferenceStartOffset() { - return getRangeInElement().getStartOffset(); - } - - private int getAttributeValueStartOffset() { - final XmlAttribute attr = getAttribute(); - final XmlAttributeValue valueElement = attr.getValueElement(); - return (valueElement == null) ? attr.getTextRange().getEndOffset() + 1 : valueElement.getTextRange().getStartOffset() + 1; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntAttributeReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntAttributeReferenceProvider.java deleted file mode 100644 index fc7d5a81c2b6..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntAttributeReferenceProvider.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntAttributeReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiWhiteSpace; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlToken; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class AntAttributeReferenceProvider extends PsiReferenceProvider { - - @SuppressWarnings({"HardCodedStringLiteral"}) - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - if (!(element instanceof AntStructuredElement)) { - return PsiReference.EMPTY_ARRAY; - } - final AntStructuredElement se = (AntStructuredElement)element; - final int elementStartOffset = se.getTextRange().getStartOffset(); - final List list = PsiReferenceListSpinAllocator.alloc(); - try { - for (PsiElement child : se.getSourceElement().getChildren()) { - if (child instanceof XmlToken) { - XmlToken token = (XmlToken)child; - // TODO: move XmlTokenType to openAPI - if (token.getTokenType().toString().equals("XML_TAG_END")) { - break; - } - } - else if (child instanceof PsiWhiteSpace) { - final int off = child.getTextRange().getStartOffset() - elementStartOffset + 1; - list.add(new AntAttributeReference(se, " ", new TextRange(off, off), null)); - } - else if (child instanceof XmlAttribute) { - final PsiElement nameElement = child.getFirstChild(); - if (nameElement != null) { - final int off = nameElement.getTextRange().getStartOffset() - elementStartOffset; - final String text = nameElement.getText(); - list.add(new AntAttributeReference(se, text, new TextRange(off, off + text.length()), null)); - } - } - } - final int count = list.size(); - return (count == 0) ? PsiReference.EMPTY_ARRAY : list.toArray(new PsiReference[count]); - } - finally { - PsiReferenceListSpinAllocator.dispose(list); - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntElementNameReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntElementNameReferenceProvider.java deleted file mode 100644 index fa97ddba85dc..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntElementNameReferenceProvider.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.AntTask; -import com.intellij.lang.ant.psi.impl.reference.AntElementNameReference; -import com.intellij.lang.ant.psi.impl.reference.AntEndElementNameReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlTag; -import com.intellij.psi.xml.XmlToken; -import com.intellij.psi.xml.XmlTokenType; -import com.intellij.util.ProcessingContext; -import com.intellij.xml.util.XmlTagUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class AntElementNameReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - if (!(element instanceof AntStructuredElement)) { - return PsiReference.EMPTY_ARRAY; - } - final AntStructuredElement se = (AntStructuredElement)element; - final List result = PsiReferenceListSpinAllocator.alloc(); - try { - result.add(new AntElementNameReference(se)); - if (element instanceof AntTask) { - final AntTask task = (AntTask)element; - if (task.isMacroDefined() || task.isScriptDefined()) { - final XmlAttribute[] attrs = task.getSourceElement().getAttributes(); - if (attrs.length != 0) { - for (XmlAttribute attr : attrs) { - result.add(new AntElementNameReference(task, attr)); - } - } - } - } - final AntElementNameReference endReference = findEndElementNameReference(se); - if (endReference != null) { - result.add(endReference); - } - return result.toArray(new PsiReference[result.size()]); - } - finally { - PsiReferenceListSpinAllocator.dispose(result); - } - } - - @Nullable - private static AntEndElementNameReference findEndElementNameReference(final AntStructuredElement element) { - final XmlTag tag = element.getSourceElement(); - final PsiElement endTagElement = XmlTagUtil.getEndTagNameElement(tag); - if (endTagElement == null) { - return null; - } - final TextRange elementRange = element.getTextRange(); - final TextRange endTagRange = endTagElement.getTextRange(); - final TextRange refRange = new TextRange( - endTagRange.getStartOffset() - elementRange.getStartOffset(), - endTagRange.getEndOffset() - elementRange.getStartOffset() - ); - return new AntEndElementNameReference(element, refRange, isClosed(endTagElement)); - } - - private static boolean isClosed(PsiElement current) { - for (PsiElement e = current; e != null; e = e.getNextSibling()) { - if (e instanceof XmlToken) { - final IElementType tokenType = ((XmlToken)e).getTokenType(); - if (tokenType == XmlTokenType.XML_TAG_END || tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END) { - return true; - } - } - } - return false; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntFileReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntFileReferenceProvider.java deleted file mode 100644 index 1f8ce65df9f4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntFileReferenceProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntFileReferenceSet; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.ProcessingContext; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -public class AntFileReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - AntStructuredElement antElement = (AntStructuredElement)element; - final List referenceAttributes = antElement.getFileReferenceAttributes(); - if (referenceAttributes.isEmpty()) { - return PsiReference.EMPTY_ARRAY; - } - final List refList = new ArrayList(); - for (String attrib : referenceAttributes) { - final XmlAttribute attr = antElement.getSourceElement().getAttribute(attrib, null); - if (attr == null) { - continue; - } - final XmlAttributeValue xmlAttributeValue = attr.getValueElement(); - if (xmlAttributeValue == null) { - continue; - } - final String attrValue = attr.getValue(); - if (attrValue == null || attrValue.length() == 0 || isSingleSlash(attrValue) || attrValue.indexOf("@{") >= 0) { - continue; - } - final AntFileReferenceSet refSet = new AntFileReferenceSet(antElement, xmlAttributeValue, this); - ContainerUtil.addAll(refList, refSet.getAllReferences()); - } - return refList.toArray(new PsiReference[refList.size()]); - } - - private static boolean isSingleSlash(final String attrValue) { - return "/".equals(attrValue) || "\\".equals(attrValue); - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntMacroDefParameterReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntMacroDefParameterReferenceProvider.java deleted file mode 100644 index 5663a5cd668f..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntMacroDefParameterReferenceProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntAllTasksContainer; -import com.intellij.lang.ant.psi.AntMacroDef; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntMacroDefParameterReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.ElementManipulators; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlElement; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class AntMacroDefParameterReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - if (!(element instanceof AntStructuredElement)) { - return PsiReference.EMPTY_ARRAY; - } - final AntStructuredElement antElement = (AntStructuredElement)element; - final AntAllTasksContainer sequential = PsiTreeUtil.getParentOfType(antElement, AntAllTasksContainer.class, true); - if (sequential == null) { - return PsiReference.EMPTY_ARRAY; - } - final AntMacroDef macrodef = PsiTreeUtil.getParentOfType(sequential, AntMacroDef.class, true); - if (macrodef == null) { - return PsiReference.EMPTY_ARRAY; - } - final List refs = PsiReferenceListSpinAllocator.alloc(); - try { - for (XmlAttribute attr : antElement.getSourceElement().getAttributes()) { - getXmlElementReferences(attr.getValueElement(), refs, antElement); - } - getXmlElementReferences(antElement.getSourceElement(), refs, antElement); - return (refs.size() > 0) ? refs.toArray(new PsiReference[refs.size()]) : PsiReference.EMPTY_ARRAY; - } - finally { - PsiReferenceListSpinAllocator.dispose(refs); - } - } - - private static void getXmlElementReferences(final XmlElement element, final List refs, final AntStructuredElement antElement) { - if (element == null) return; - final String text = ElementManipulators.getValueText(element); - final int offsetInPosition = ElementManipulators.getValueTextRange(element).getStartOffset() + element.getTextRange().getStartOffset() - antElement.getTextRange().getStartOffset(); - int startIndex; - int endIndex = -1; - while ((startIndex = text.indexOf("@{", endIndex + 1)) > endIndex) { - startIndex += 2; - endIndex = startIndex; - int nestedBrackets = 0; - while (text.length() > endIndex) { - final char ch = text.charAt(endIndex); - if (ch == '}') { - if (nestedBrackets == 0) { - break; - } - --nestedBrackets; - } - else if (ch == '{') { - ++nestedBrackets; - } - ++endIndex; - } - if(nestedBrackets > 0 || endIndex == text.length()) return; - if (endIndex >= startIndex) { - final String name = text.substring(startIndex, endIndex); - refs.add(new AntMacroDefParameterReference(antElement, name, - new TextRange(offsetInPosition + startIndex, offsetInPosition + endIndex), element)); - } - endIndex = startIndex; - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java deleted file mode 100644 index dff6aab18333..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.lang.ant.psi.impl.reference.AntPropertyReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class AntPropertyReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - final AntStructuredElement antElement = (AntStructuredElement)element; - final XmlTag sourceElement = antElement.getSourceElement(); - final XmlAttribute[] attributes = sourceElement.getAttributes(); - if (attributes.length > 0) { - final List refs = PsiReferenceListSpinAllocator.alloc(); - try { - //final boolean isTarget = antElement instanceof AntTarget; - final boolean isSet = "isset".equals(sourceElement.getName()); - for (final XmlAttribute attr : attributes) { - @NonNls final String attName = attr.getName(); - if (/*isTarget && */(AntFileImpl.IF_ATTR.equals(attName) || AntFileImpl.UNLESS_ATTR.equals(attName))) { - getAttributeReference(antElement, attr, refs); - } - else if (isSet && AntFileImpl.PROPERTY.equals(attName)) { - getAttributeReference(antElement, attr, refs); - } - else { - getAttributeReferences(antElement, attr, refs); - } - } - if (refs.size() > 0) { - return refs.toArray(new PsiReference[refs.size()]); - } - } - finally { - PsiReferenceListSpinAllocator.dispose(refs); - } - } - return PsiReference.EMPTY_ARRAY; - } - - /** - * Gets all references to the ${} properties. - * - * @param element - * @param attr - * @param refs - */ - private static void getAttributeReferences(final AntElement element, final XmlAttribute attr, final List refs) { - final AntFile antFile = element.getAntFile(); - final String value = attr.getValue(); - final XmlAttributeValue xmlAttributeValue = attr.getValueElement(); - if (xmlAttributeValue != null && value.indexOf("@{") < 0) { - final int offsetInPosition = xmlAttributeValue.getTextRange().getStartOffset() - element.getTextRange().getStartOffset() + 1; - int startIndex; - int endIndex = -1; - while ((startIndex = value.indexOf("${", endIndex + 1)) > endIndex) { - if (startIndex > 0 && value.charAt(startIndex - 1) == '$') { - // the '$' is escaped - endIndex = startIndex + 1; - continue; - } - startIndex += 2; - endIndex = startIndex; - int nestedBrackets = 0; - while (value.length() > endIndex) { - final char ch = value.charAt(endIndex); - if (ch == '}') { - if (nestedBrackets == 0) { - break; - } - --nestedBrackets; - } - else if (ch == '{') { - ++nestedBrackets; - } - ++endIndex; - } - if (nestedBrackets > 0 || endIndex > value.length()) return; - if (endIndex >= startIndex) { - final String propName = value.substring(startIndex, endIndex); - if (antFile.isEnvironmentProperty(propName) && antFile.getProperty(propName) == null) { - continue; - } - refs.add(new AntPropertyReference(element, propName, - new TextRange(offsetInPosition + startIndex, offsetInPosition + endIndex), attr)); - } - endIndex = startIndex; - } - } - } - - /** - * Gets single reference on a property named as the attribute's and if the property is resolved. - * - * @param element - * @param attr - * @param refs - */ - private static void getAttributeReference(final AntElement element, final XmlAttribute attr, final List refs) { - final AntFile antFile = element.getAntFile(); - final String value = attr.getValue(); - if (value == null) { - return; - } - if (antFile.isEnvironmentProperty(value) && antFile.getProperty(value) == null) { - return; - } - final XmlAttributeValue xmlAttributeValue = attr.getValueElement(); - if (xmlAttributeValue != null) { - final int offsetInPosition = xmlAttributeValue.getTextRange().getStartOffset() - element.getTextRange().getStartOffset() + 1; - refs.add(new AntPropertyReference(element, value, new TextRange(offsetInPosition, offsetInPosition + value.length()), attr) { - public boolean shouldBeSkippedByAnnotator() { - return getCanonicalText().length() > 0; - } - - public String getUnresolvedMessagePattern() { - return AntBundle.message("please.specify.a.property"); - } - }); - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntRefIdReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntRefIdReferenceProvider.java deleted file mode 100644 index 80896280c907..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntRefIdReferenceProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.reference.AntRefIdReference; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.NonNls; - -import java.util.ArrayList; -import java.util.List; - -public class AntRefIdReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - if (!(element instanceof AntStructuredElement)) { - return PsiReference.EMPTY_ARRAY; - } - final AntStructuredElement se = (AntStructuredElement)element; - final List refs = new ArrayList(); - for (XmlAttribute attr : se.getSourceElement().getAttributes()) { - if (!isRefAttribute(se, attr.getName())) { - continue; - } - final XmlAttributeValue valueElement = attr.getValueElement(); - if (valueElement == null) { - continue; - } - final int offsetInPosition = valueElement.getTextRange().getStartOffset() - se.getTextRange().getStartOffset() + 1; - final String attrValue = attr.getValue(); - if (attrValue == null || attrValue.indexOf("@{") >= 0) { - continue; - } - refs.add(new AntRefIdReference(se, attrValue, new TextRange(offsetInPosition, offsetInPosition + attrValue.length()), attr)); - } - return refs.toArray(new PsiReference[refs.size()]); - } - - private static boolean isRefAttribute(AntStructuredElement element, @NonNls final String attribName) { - if ("refid".equals(attribName)) { - return true; - } - final AntTypeDefinition typeDef = element.getTypeDefinition(); - return typeDef != null && AntAttributeType.ID_REFERENCE == typeDef.getAttributeType(attribName); - } - -} \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntSingleTargetReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntSingleTargetReferenceProvider.java deleted file mode 100644 index 43757b85e2b5..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntSingleTargetReferenceProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.impl.AntAntImpl; -import com.intellij.lang.ant.psi.impl.AntCallImpl; -import com.intellij.lang.ant.psi.impl.AntProjectImpl; -import com.intellij.lang.ant.psi.impl.reference.AntTargetReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.containers.HashMap; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public class AntSingleTargetReferenceProvider extends PsiReferenceProvider { - - @NonNls private static final Map ourTypesToAttributeNames; - - static { - ourTypesToAttributeNames = new HashMap(); - ourTypesToAttributeNames.put(AntProjectImpl.class, "default"); - ourTypesToAttributeNames.put(AntCallImpl.class, "target"); - ourTypesToAttributeNames.put(AntAntImpl.class, "target"); - } - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - String attributeName = ourTypesToAttributeNames.get(element.getClass()); - if( attributeName == null) { - return PsiReference.EMPTY_ARRAY; - } - AntElement antElement = (AntElement)element; - final XmlAttribute attr = ((XmlTag)antElement.getSourceElement()).getAttribute(attributeName, null); - if (attr == null) { - return PsiReference.EMPTY_ARRAY; - } - final XmlAttributeValue valueElement = attr.getValueElement(); - if( valueElement == null ) { - return PsiReference.EMPTY_ARRAY; - } - final int offsetInPosition = valueElement.getTextRange().getStartOffset() - antElement.getTextRange().getStartOffset() + 1; - final String attrValue = valueElement.getValue(); - return new PsiReference[]{ - new AntTargetReference(antElement, attrValue, new TextRange(offsetInPosition, offsetInPosition + attrValue.length()), attr)}; - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntTargetListReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntTargetListReferenceProvider.java deleted file mode 100644 index 79b0a453e048..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntTargetListReferenceProvider.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl.reference.providers; - -import com.intellij.lang.ant.misc.PsiReferenceListSpinAllocator; -import com.intellij.lang.ant.psi.AntTarget; -import com.intellij.lang.ant.psi.impl.reference.AntTargetReference; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class AntTargetListReferenceProvider extends PsiReferenceProvider { - - @NotNull - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { - final AntTarget target = (AntTarget)element; - final XmlAttribute attr = target.getSourceElement().getAttribute("depends", null); - if (attr == null) { - return PsiReference.EMPTY_ARRAY; - } - final XmlAttributeValue xmlAttributeValue = attr.getValueElement(); - if (xmlAttributeValue == null) { - return PsiReference.EMPTY_ARRAY; - } - int offsetInPosition = xmlAttributeValue.getTextRange().getStartOffset() - target.getTextRange().getStartOffset() + 1; - final String value = attr.getValue(); - final List result = PsiReferenceListSpinAllocator.alloc(); - try { - final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - int i = 0; - int rightBound; - final int valueLen = value.length(); - do { - rightBound = (i < valueLen) ? value.indexOf(',', i) : valueLen; - if (rightBound < 0) rightBound = valueLen; - builder.setLength(0); - int j = i; - for (; j < rightBound; ++j) { - builder.append(value.charAt(j)); - } - j = 0; - final int len = builder.length(); - for (; j < len; ++j) { - if (!Character.isWhitespace(builder.charAt(j))) break; - } - final String targetName = (len == 0 || j == len) ? "" : builder.substring(j); - result.add(new AntTargetReference(target, targetName, - new TextRange(offsetInPosition + i + j, offsetInPosition + i + j + targetName.length()), attr)); - i = rightBound + 1; - } - while (rightBound < valueLen); - return (result.size() > 0) ? result.toArray(new PsiReference[result.size()]) : PsiReference.EMPTY_ARRAY; - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - finally { - PsiReferenceListSpinAllocator.dispose(result); - } - } - -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntAttributeType.java b/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntAttributeType.java deleted file mode 100644 index 8bf1b9b275c7..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntAttributeType.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.introspection; - -import org.apache.tools.ant.types.Reference; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -public enum AntAttributeType { - INTEGER, - BOOLEAN, - STRING, - FILE, - ID_REFERENCE; - - - private static final Map, AntAttributeType> ourClassesMap = new HashMap, AntAttributeType>(); - static { - ourClassesMap.put(int.class, INTEGER); - ourClassesMap.put(boolean.class, BOOLEAN); - ourClassesMap.put(File.class, FILE); - } - - public static AntAttributeType create(Class antDeclaredClass) { - final AntAttributeType type = ourClassesMap.get(antDeclaredClass); - if (type != null) { - return type; - } - if (isAssignableFrom(Reference.class, antDeclaredClass)) { - return ID_REFERENCE; - } - return STRING; // default attribute type - } - - private static boolean isAssignableFrom(Class interfaceClass, Class antDeclaredClass) { - final ClassLoader loader = antDeclaredClass.getClassLoader(); - try { - final Class ifaceClass = loader != null? loader.loadClass(interfaceClass.getName()) : interfaceClass; - return ifaceClass.isAssignableFrom(antDeclaredClass); - } - catch (ClassNotFoundException ignored) { - } - return false; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeDefinition.java b/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeDefinition.java deleted file mode 100644 index b065c3c2b219..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.introspection; - -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface AntTypeDefinition { - - AntTypeDefinition[] EMPTY_ARRAY = new AntTypeDefinition[0]; - - AntTypeId getTypeId(); - - void setTypeId(final AntTypeId id); - - String getClassName(); - - boolean isTask(); - - boolean isAllTaskContainer(); - - boolean isProperty(); - - @NotNull - String[] getAttributes(); - - @Nullable - AntAttributeType getAttributeType(final String attr); - - AntTypeId[] getNestedElements(); - - @Nullable - String getNestedClassName(final AntTypeId id); - - boolean isExtensionPointType(ClassLoader aClass, final String className); - - void registerNestedType(final AntTypeId typeId, final String className); - - void unregisterNestedType(final AntTypeId typeId); - - PsiElement getDefiningElement(); - - boolean isOutdated(); - - void setOutdated(boolean isOutdated); -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeId.java b/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeId.java deleted file mode 100644 index 80889b704b2a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/AntTypeId.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.introspection; - -import com.intellij.lang.ant.misc.AntStringInterner; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -public class AntTypeId { - private String myName; - private String myNsPrefix; - - public AntTypeId(@NonNls final String name, @Nullable final String nsPrefix) { - init(name, nsPrefix); - } - - public AntTypeId(@NonNls final String name) { - final int nsSeparator = name.indexOf(':'); - if (nsSeparator < 0) { - init(name, null); - } - else { - init(name.substring(nsSeparator + 1), name.substring(0, nsSeparator)); - } - } - - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final AntTypeId antTypeId = (AntTypeId)o; - - if (!myName.equals(antTypeId.myName)) return false; - if (myNsPrefix != null && antTypeId.myNsPrefix != null && !myNsPrefix.equals(antTypeId.myNsPrefix)) return false; - - return true; - } - - public int hashCode() { - return 31 * myName.hashCode() + (myNsPrefix != null ? myNsPrefix.hashCode() : 0); - } - - @NonNls - public String getName() { - return myName; - } - - @Nullable - public String getNamespacePrefix() { - return myNsPrefix; - } - - private void init(@NonNls final String name, @Nullable final String nsPrefix) { - myName = AntStringInterner.intern(name); - myNsPrefix = (nsPrefix != null && nsPrefix.length() > 0) ? AntStringInterner.intern(nsPrefix) : null; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/impl/AntTypeDefinitionImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/introspection/impl/AntTypeDefinitionImpl.java deleted file mode 100644 index 6094d62b3807..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/introspection/impl/AntTypeDefinitionImpl.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.introspection.impl; - -import com.intellij.lang.ant.misc.AntStringInterner; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.lang.ant.psi.introspection.AntAttributeType; -import com.intellij.lang.ant.psi.introspection.AntTypeDefinition; -import com.intellij.lang.ant.psi.introspection.AntTypeId; -import com.intellij.psi.CommonClassNames; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiLock; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public class AntTypeDefinitionImpl implements AntTypeDefinition { - - private static final AntTypeId ourJavadocId = new AntTypeId(AntFileImpl.JAVADOC_TAG); - private static final AntTypeId ourUnzipId = new AntTypeId(AntFileImpl.UNZIP_TAG); - - private AntTypeId myTypeId; - private final Set myExtensionPoints; - private String myClassName; - private boolean myIsTask; - private boolean myIsAllTaskContainer; - private boolean myIsProperty; - private PsiElement myDefiningElement; - private boolean myIsOutdated = false; - /** - * Attribute names to their types. - */ - private final Map myAttributes; - private String[] myAttributesArray; - /** - * Task ids to their class names. - */ - private final Map myNestedClassNames; - private AntTypeId[] myNestedElementsArray; - - public AntTypeDefinitionImpl(final AntTypeDefinitionImpl base) { - this(base.getTypeId(), base.getClassName(), base.isTask(), base.isAllTaskContainer(), new HashMap(base.myAttributes), - new HashMap(base.myNestedClassNames)); - } - - public AntTypeDefinitionImpl(final AntTypeId id, final String className, final boolean isTask, final boolean isAllTaskContainer) { - this(id, className, isTask, isAllTaskContainer, new HashMap(), new HashMap()); - } - - public AntTypeDefinitionImpl(final AntTypeId id, - final String className, - final boolean isTask, final boolean isAllTaskContainer, @NonNls @NotNull final Map attributes, - final Map nestedElements) { - this(id, className, isTask, isAllTaskContainer, attributes, nestedElements, null); - } - - public AntTypeDefinitionImpl(final AntTypeId id, - final String className, - final boolean isTask, final boolean allTaskContainer, @NonNls @NotNull final Map attributes, - final Map nestedElements, - final PsiElement definingElement) { - this(id, className, isTask, allTaskContainer, attributes, nestedElements, Collections.emptySet(), definingElement); - } - - public AntTypeDefinitionImpl(final AntTypeId id, - final String className, - final boolean isTask, final boolean isAllTaskContainer, @NonNls @NotNull final Map attributes, - final Map nestedElements, - final Set extensionPoints, - final PsiElement definingElement) { - myTypeId = id; - myExtensionPoints = extensionPoints; - setClassName(className); - myIsTask = isTask; - myIsAllTaskContainer = isAllTaskContainer; - attributes.put(AntFileImpl.ID_ATTR, AntAttributeType.STRING); - myAttributes = attributes; - myNestedClassNames = nestedElements; - myDefiningElement = definingElement; - } - - public boolean isOutdated() { - return myIsOutdated; - } - - public void setOutdated(final boolean isOutdated) { - myIsOutdated = isOutdated; - } - - public final AntTypeId getTypeId() { - return myTypeId; - } - - public final void setTypeId(final AntTypeId id) { - myTypeId = id; - } - - public final String getClassName() { - return myClassName; - } - - public final boolean isTask() { - return myIsTask; - } - - public boolean isAllTaskContainer() { - return myIsAllTaskContainer; - } - - public boolean isProperty() { - return myIsProperty; - } - - @NotNull - public final String[] getAttributes() { - synchronized (PsiLock.LOCK) { - if (myAttributesArray == null || myAttributesArray.length != myAttributes.size()) { - myAttributesArray = myAttributes.keySet().toArray(new String[myAttributes.size()]); - } - return myAttributesArray; - } - } - - public final AntAttributeType getAttributeType(final String attr) { - for (int i = 0; i < attr.length(); ++i) { - if (!Character.isLowerCase(attr.charAt(i))) { - return myAttributes.get(attr.toLowerCase(Locale.US)); - } - } - return myAttributes.get(attr); - } - - public final Map getAttributesMap() { - return myAttributes; - } - - @SuppressWarnings({"unchecked"}) - public final AntTypeId[] getNestedElements() { - synchronized (PsiLock.LOCK) { - if (myNestedElementsArray == null || myNestedElementsArray.length != myNestedClassNames.size()) { - myNestedElementsArray = myNestedClassNames.keySet().toArray(new AntTypeId[myNestedClassNames.size()]); - } - return myNestedElementsArray; - } - } - - public final Map getNestedElementsMap() { - return myNestedClassNames; - } - - public boolean isExtensionPointType(final ClassLoader loader, final String className) { - if (CommonClassNames.JAVA_LANG_OBJECT.equals(className)) { - return false; - } - if (myExtensionPoints.contains(className)) { - return true; - } - try { - return isExtensionPointType(loader.loadClass(className)); - } - catch (ClassNotFoundException e) { - return false; - } - } - - private boolean isExtensionPointType(final Class aClass) { - if (aClass == null || CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getName())) { - return false; - } - if (myExtensionPoints.contains(aClass.getName())) { - return true; - } - final Class[] interfaces = aClass.getInterfaces(); - for (Class iface : interfaces) { - if (isExtensionPointType(iface)) { - return true; - } - } - return isExtensionPointType(aClass.getSuperclass()); - } - - - @Nullable - public final String getNestedClassName(final AntTypeId id) { - final String nsPrefix = id.getNamespacePrefix(); - if (nsPrefix == null) { - final String name = id.getName(); - /** - * Hardcode for task (IDEADEV-6731). - */ - if (name.equals(AntFileImpl.JAVADOC2_TAG)) { - return myNestedClassNames.get(ourJavadocId); - } - /** - * Hardcode for and tasks (IDEADEV-6830). - */ - if (name.equals(AntFileImpl.UNWAR_TAG) || name.equals(AntFileImpl.UNJAR_TAG)) { - return myNestedClassNames.get(ourUnzipId); - } - } - return myNestedClassNames.get(id); - } - - public final void registerNestedType(final AntTypeId id, String taskClassName) { - myNestedClassNames.put(id, taskClassName); - } - - public final void unregisterNestedType(final AntTypeId typeId) { - myNestedClassNames.remove(typeId); - } - - public final PsiElement getDefiningElement() { - return myDefiningElement; - } - - public final void setDefiningElement(final PsiElement element) { - myDefiningElement = element; - } - - public final void setIsTask(final boolean isTask) { - myIsTask = isTask; - } - - public final void setIsProperty(final boolean isProperty) { - myIsProperty = isProperty; - } - - public final void setClassName(final String className) { - myClassName = AntStringInterner.intern(className); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/usages/AntUsagesProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/usages/AntUsagesProvider.java deleted file mode 100644 index a5912c62f55e..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/psi/usages/AntUsagesProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.usages; - -import com.intellij.lang.ant.HelpID; -import com.intellij.lang.ant.PsiAntElement; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.cacheBuilder.WordsScanner; -import com.intellij.lang.findUsages.FindUsagesProvider; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.xml.XmlElement; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class AntUsagesProvider implements FindUsagesProvider { - - @Nullable - public WordsScanner getWordsScanner() { - return null; - } - - public boolean canFindUsagesFor(@NotNull PsiElement element) { - if (!(element instanceof AntStructuredElement)) return false; - AntStructuredElement se = (AntStructuredElement)element; - return se.hasNameElement() || se.hasIdElement(); - } - - @Nullable - public String getHelpId(@NotNull PsiElement element) { - return HelpID.FIND_OTHER_USAGES; - } - - @NotNull - public String getType(@NotNull PsiElement element) { - return ((PsiAntElement) element).getRole().getName(); - } - - @NotNull - public String getDescriptiveName(@NotNull PsiElement element) { - if( element instanceof PsiNamedElement) { - final String name = ((PsiNamedElement)element).getName(); - if (name != null) { - return name; - } - } - final XmlElement sourceElement = ((AntElement)element).getSourceElement(); - if (sourceElement instanceof XmlTag) { - return ((XmlTag)sourceElement).getName(); - } - return sourceElement.getText(); - } - - @NotNull - public String getNodeText(@NotNull PsiElement element, boolean useFullName) { - return getDescriptiveName(element); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextFix.java index 93fc48ac15fc..21945f4943d8 100644 --- a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextFix.java +++ b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextFix.java @@ -18,17 +18,12 @@ package com.intellij.lang.ant.quickfix; import com.intellij.codeInsight.daemon.impl.HectorComponent; import com.intellij.codeInsight.intention.impl.BaseIntentionAction; import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.validation.AntHectorConfigurable; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; /** * @author Eugene Zhuravlev @@ -45,33 +40,44 @@ public class AntChangeContextFix extends BaseIntentionAction { } public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) { + //if (!(file instanceof XmlFile)) { + // return false; + //} + //final XmlTag xmlTag = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), XmlTag.class); + //if (xmlTag == null) { + // return false; + //} + //final AntDomElement antDomElement = AntSupport.getAntDomElement(xmlTag); + //if (antDomElement == null) { + // return false; + //} return true; } public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final HectorComponent component = new HectorComponent(file); - final JComponent focusComponent = findComponentToFocus(component); + //final JComponent focusComponent = findComponentToFocus(component); component.showComponent(JBPopupFactory.getInstance().guessBestPopupLocation(editor)); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - (focusComponent != null? focusComponent : component).requestFocus(); - } - }); + //SwingUtilities.invokeLater(new Runnable() { + // public void run() { + // (focusComponent != null? focusComponent : component).requestFocus(); + // } + //}); } - @Nullable - private static JComponent findComponentToFocus(final JComponent component) { - if (component.getClientProperty(AntHectorConfigurable.CONTEXTS_COMBO_KEY) != null) { - return component; - } - for (Component child : component.getComponents()) { - if (child instanceof JComponent) { - final JComponent found = findComponentToFocus((JComponent)child); - if (found != null) { - return found; - } - } - } - return null; - } + //@Nullable + //private static JComponent findComponentToFocus(final JComponent component) { + // if (component.getClientProperty(AntHectorConfigurable.CONTEXTS_COMBO_KEY) != null) { + // return component; + // } + // for (Component child : component.getComponents()) { + // if (child instanceof JComponent) { + // final JComponent found = findComponentToFocus((JComponent)child); + // if (found != null) { + // return found; + // } + // } + // } + // return null; + //} } diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextLocalFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextLocalFix.java new file mode 100644 index 000000000000..ae4c85b4d495 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntChangeContextLocalFix.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.quickfix; + +import com.intellij.codeInsight.daemon.impl.HectorComponent; +import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.lang.ant.AntBundle; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author Eugene Zhuravlev + * Date: May 12, 2008 + */ +public class AntChangeContextLocalFix implements LocalQuickFix { + + @NotNull public String getName() { + return AntBundle.message("intention.configure.highlighting.text"); + } + + @NotNull + public final String getFamilyName() { + return AntBundle.message("intention.configure.highlighting.family.name"); + } + + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + final PsiElement psiElement = descriptor.getPsiElement(); + final PsiFile containingFile = psiElement.getContainingFile(); + if (containingFile == null) { + return; + } + final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); + if (editor == null) { + return; + } + final HectorComponent component = new HectorComponent(containingFile.getOriginalFile()); + component.showComponent(JBPopupFactory.getInstance().guessBestPopupLocation(editor)); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateMacroDefFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateMacroDefFix.java deleted file mode 100644 index 8d87309d4b81..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateMacroDefFix.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.quickfix; - -import com.intellij.codeInsight.intention.impl.BaseIntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.AntPsiUtil; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.pom.Navigatable; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NotNull; - -public class AntCreateMacroDefFix extends BaseIntentionAction { - - private final AntStructuredElement myUndefinedElement; - private final AntFile myFile; - - public AntCreateMacroDefFix(final AntStructuredElement undefinedElement) { - this(undefinedElement, null); - } - - public AntCreateMacroDefFix(final AntStructuredElement undefinedElement, final AntFile file) { - myUndefinedElement = undefinedElement; - myFile = file; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - @NotNull - public String getFamilyName() { - final String i18nName = AntBundle.message("intention.create.macrodef.family.name"); - return (i18nName == null) ? "Create macrodef" : i18nName; - } - - @NotNull - public String getText() { - StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(getFamilyName()); - builder.append(" '"); - builder.append(myUndefinedElement.getSourceElement().getName()); - builder.append('\''); - if (myFile != null) { - builder.append(' '); - builder.append(AntBundle.message("text.in.the.file", myFile.getName())); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return true; - } - - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final AntStructuredElement element = myUndefinedElement; - final AntProject antProject = (myFile == null) ? element.getAntProject() : myFile.getAntProject(); - final AntElement anchor = - (myFile == null) ? AntPsiUtil.getSubProjectElement(element) : PsiTreeUtil.getChildOfType(antProject, AntStructuredElement.class); - final XmlTag se = element.getSourceElement(); - final XmlTag projectTag = antProject.getSourceElement(); - - // create macrodef tag - XmlTag macrodefTag = projectTag.createChildTag("macrodef", projectTag.getNamespace(), null, false); - macrodefTag.setAttribute(AntFileImpl.NAME_ATTR, se.getName()); - - // create attribute definitons - for (XmlAttribute attr : se.getAttributes()) { - XmlTag attrTag = macrodefTag.createChildTag("attribute", macrodefTag.getNamespace(), null, false); - attrTag.setAttribute(AntFileImpl.NAME_ATTR, attr.getName()); - macrodefTag.add(attrTag); - } - - // create definitons of nested elements - for (XmlTag subtag : se.getSubTags()) { - XmlTag elementTag = macrodefTag.createChildTag("element", macrodefTag.getNamespace(), null, false); - elementTag.setAttribute(AntFileImpl.NAME_ATTR, subtag.getName()); - macrodefTag.add(elementTag); - } - - // insert macrodef in file and navigate to it - macrodefTag = (XmlTag)((anchor == null) ? projectTag.add(macrodefTag) : projectTag.addBefore(macrodefTag, anchor.getSourceElement())); - ((Navigatable)macrodefTag).navigate(true); - - // if macrodef is inserted into an imported file, clear caches in order to re-annotate current element - if (myFile != null) { - element.getAntFile().clearCaches(); - } - } -} - diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePresetDefFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePresetDefFix.java deleted file mode 100644 index 8250adfc67cd..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePresetDefFix.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.quickfix; - -import com.intellij.codeInsight.intention.impl.BaseIntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.AntPsiUtil; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.pom.Navigatable; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NotNull; - -public class AntCreatePresetDefFix extends BaseIntentionAction { - - private final AntStructuredElement myUndefinedElement; - private final AntFile myFile; - - public AntCreatePresetDefFix(final AntStructuredElement undefinedElement) { - this(undefinedElement, null); - } - - public AntCreatePresetDefFix(final AntStructuredElement undefinedElement, final AntFile file) { - myUndefinedElement = undefinedElement; - myFile = file; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - @NotNull - public String getFamilyName() { - final String i18nName = AntBundle.message("intention.create.presetdef.family.name"); - return (i18nName == null) ? "Create presetdef" : i18nName; - } - - @NotNull - public String getText() { - StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(getFamilyName()); - builder.append(" '"); - builder.append(myUndefinedElement.getSourceElement().getName()); - builder.append('\''); - if (myFile != null) { - builder.append(' '); - builder.append(AntBundle.message("text.in.the.file", myFile.getName())); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return true; - } - - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final AntStructuredElement element = myUndefinedElement; - final AntProject antProject = (myFile == null) ? element.getAntProject() : myFile.getAntProject(); - final AntElement anchor = - (myFile == null) ? AntPsiUtil.getSubProjectElement(element) : PsiTreeUtil.getChildOfType(antProject, AntStructuredElement.class); - final XmlTag se = element.getSourceElement(); - final XmlTag projectTag = antProject.getSourceElement(); - - // create presetdef tag - XmlTag presetDef = projectTag.createChildTag("presetdef", projectTag.getNamespace(), null, false); - presetDef.setAttribute(AntFileImpl.NAME_ATTR, se.getName()); - - // insert presetdef in file and navigate to it - presetDef = (XmlTag)((anchor == null) ? projectTag.add(presetDef) : projectTag.addBefore(presetDef, anchor.getSourceElement())); - ((Navigatable)presetDef).navigate(true); - - // if presetdef is inserted into an imported file, clear caches in order to re-annotate current element - if (myFile != null) { - element.getAntFile().clearCaches(); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePropertyFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePropertyFix.java deleted file mode 100644 index fafb011f73d1..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreatePropertyFix.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.quickfix; - -import com.intellij.codeInsight.CodeInsightUtilBase; -import com.intellij.codeInsight.intention.impl.BaseIntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.AntPsiUtil; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.lang.ant.psi.impl.reference.AntPropertyReference; -import com.intellij.lang.properties.psi.PropertiesFile; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.pom.Navigatable; -import com.intellij.psi.PsiFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NotNull; - -public class AntCreatePropertyFix extends BaseIntentionAction { - - private final AntPropertyReference myRef; - private final PropertiesFile myPropFile; - - public AntCreatePropertyFix(final AntPropertyReference ref) { - this(ref, null); - } - - public AntCreatePropertyFix(final AntPropertyReference ref, final PropertiesFile propFile) { - myRef = ref; - myPropFile = propFile; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - @NotNull - public String getFamilyName() { - final String i18nName = AntBundle.message("intention.create.property.family.name"); - return (i18nName == null) ? "Create property" : i18nName; - } - - @NotNull - public String getText() { - StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(getFamilyName()); - builder.append(" '"); - builder.append(myRef.getCanonicalRepresentationText()); - builder.append('\''); - if (myPropFile != null) { - builder.append(' '); - builder.append(AntBundle.message("text.in.the.file", myPropFile.getName())); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return true; - } - - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final String name = myRef.getCanonicalRepresentationText(); - if( name == null) return; - - Navigatable result = null; - if (myPropFile != null) { - result = myPropFile.addProperty(name, ""); - } - else { - final AntElement element = myRef.getElement(); - final AntElement anchor = AntPsiUtil.getSubProjectElement(element); - final XmlTag projectTag = element.getAntProject().getSourceElement(); - XmlTag propTag = projectTag.createChildTag(AntFileImpl.PROPERTY, projectTag.getNamespace(), null, false); - propTag.setAttribute(AntFileImpl.NAME_ATTR, name); - if (CodeInsightUtilBase.preparePsiElementForWrite(projectTag)) { - result = (Navigatable)((anchor == null) ? projectTag.add(propTag) : projectTag.addBefore(propTag, anchor.getSourceElement())); - } - } - if (result != null) { - result.navigate(true); - } - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateTargetFix.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateTargetFix.java deleted file mode 100644 index 7e848276d0a4..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntCreateTargetFix.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.quickfix; - -import com.intellij.codeInsight.intention.impl.BaseIntentionAction; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.misc.AntPsiUtil; -import com.intellij.lang.ant.psi.AntElement; -import com.intellij.lang.ant.psi.AntFile; -import com.intellij.lang.ant.psi.AntProject; -import com.intellij.lang.ant.psi.AntStructuredElement; -import com.intellij.lang.ant.psi.impl.AntFileImpl; -import com.intellij.lang.ant.psi.impl.reference.AntTargetReference; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.pom.Navigatable; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; -import org.jetbrains.annotations.NotNull; - -public class AntCreateTargetFix extends BaseIntentionAction { - - private final AntTargetReference myRef; - private final AntFile myFile; - - public AntCreateTargetFix(final AntTargetReference ref) { - this(ref, null); - } - - public AntCreateTargetFix(final AntTargetReference ref, final AntFile file) { - myRef = ref; - myFile = file; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - @NotNull - public String getFamilyName() { - final String i18nName = AntBundle.message("intention.create.target.family.name"); - return (i18nName == null) ? "Create target" : i18nName; - } - - @NotNull - public String getText() { - StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append(getFamilyName()); - builder.append(" '"); - builder.append(myRef.getCanonicalRepresentationText()); - builder.append('\''); - if (myFile != null) { - builder.append(' '); - builder.append(AntBundle.message("text.in.the.file", myFile.getName())); - } - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return true; - } - - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final AntElement element = myRef.getElement(); - final AntProject antProject = (myFile == null) ? element.getAntProject() : myFile.getAntProject(); - final AntElement anchor = - (myFile == null) ? AntPsiUtil.getSubProjectElement(element) : PsiTreeUtil.getChildOfType(antProject, AntStructuredElement.class); - final XmlTag projectTag = antProject.getSourceElement(); - XmlTag targetTag = projectTag.createChildTag(AntFileImpl.TARGET_TAG, projectTag.getNamespace(), null, false); - targetTag.setAttribute(AntFileImpl.NAME_ATTR, myRef.getCanonicalRepresentationText()); - targetTag = (XmlTag)((anchor == null) ? projectTag.add(targetTag) : projectTag.addBefore(targetTag, anchor.getSourceElement())); - ((Navigatable)targetTag).navigate(true); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/quickfix/AntUnresolvedRefsFixProvider.java b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntUnresolvedRefsFixProvider.java new file mode 100644 index 000000000000..5df91b5c9fcf --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/quickfix/AntUnresolvedRefsFixProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.quickfix; + +import com.intellij.codeInsight.daemon.QuickFixActionRegistrar; +import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider; +import com.intellij.lang.ant.dom.AntDomReference; +import com.intellij.psi.PsiReference; +import com.intellij.psi.impl.source.xml.TagNameReference; +import org.jetbrains.annotations.NotNull; + +/** + * @author Eugene Zhuravlev + * Date: 6/23/12 + */ +public class AntUnresolvedRefsFixProvider extends UnresolvedReferenceQuickFixProvider { + + public void registerFixes(PsiReference ref, QuickFixActionRegistrar registrar) { + if (ref instanceof TagNameReference || ref instanceof AntDomReference) { + registrar.register(new AntChangeContextFix()); + } + } + + @NotNull + public Class getReferenceClass() { + return PsiReference.class; + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/refactoring/AntTargetRenameListenerProvider.java b/plugins/ant/src/com/intellij/lang/ant/refactoring/AntTargetRenameListenerProvider.java deleted file mode 100644 index c1a290f43902..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/refactoring/AntTargetRenameListenerProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.refactoring; - -import com.intellij.execution.BeforeRunTaskProvider; -import com.intellij.lang.ant.config.AntConfiguration; -import com.intellij.lang.ant.config.impl.AntBeforeRunTask; -import com.intellij.lang.ant.config.impl.AntBeforeRunTaskProvider; -import com.intellij.lang.ant.config.impl.AntConfigurationImpl; -import com.intellij.lang.ant.psi.AntTarget; -import com.intellij.openapi.util.Comparing; -import com.intellij.psi.PsiElement; -import com.intellij.refactoring.listeners.RefactoringElementListener; -import com.intellij.refactoring.listeners.RefactoringElementListenerProvider; -import org.jetbrains.annotations.NotNull; - -/** - * @author Eugene Zhuravlev - * Date: May 14, 2009 - */ -public class AntTargetRenameListenerProvider implements RefactoringElementListenerProvider { - public RefactoringElementListener getListener(PsiElement element) { - if (element instanceof AntTarget) { - final String oldName = ((AntTarget)element).getName(); - return new RefactoringElementListener() { - public void elementMoved(@NotNull PsiElement newElement) { - } - - public void elementRenamed(@NotNull PsiElement newElement) { - final String newName = ((AntTarget)newElement).getName(); - if (!Comparing.equal(oldName, newName)) { - final AntConfiguration configuration = AntConfiguration.getInstance(newElement.getProject()); - ((AntConfigurationImpl)configuration).handleTargetRename(oldName, newName); - - BeforeRunTaskProvider provider = - BeforeRunTaskProvider.getProvider(newElement.getProject(), AntBeforeRunTaskProvider.ID); - if (provider instanceof AntBeforeRunTaskProvider) { - ((AntBeforeRunTaskProvider)provider).handleTargetRename(oldName, newName); - } - } - } - }; - } - return null; - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/refactoring/AntVetoRenameCondition.java b/plugins/ant/src/com/intellij/lang/ant/refactoring/AntVetoRenameCondition.java deleted file mode 100644 index fa9cd43cd44a..000000000000 --- a/plugins/ant/src/com/intellij/lang/ant/refactoring/AntVetoRenameCondition.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.refactoring; - -import com.intellij.openapi.util.Condition; -import com.intellij.psi.PsiElement; -import com.intellij.lang.ant.PsiAntElement; - -public class AntVetoRenameCondition implements Condition { - public boolean value(final PsiElement element) { - return element instanceof PsiAntElement && !((PsiAntElement)element).canRename(); - } -} diff --git a/plugins/ant/src/com/intellij/lang/ant/validation/AntHectorConfigurable.java b/plugins/ant/src/com/intellij/lang/ant/validation/AntHectorConfigurable.java index 7f9f84539d7a..0ca897b36644 100644 --- a/plugins/ant/src/com/intellij/lang/ant/validation/AntHectorConfigurable.java +++ b/plugins/ant/src/com/intellij/lang/ant/validation/AntHectorConfigurable.java @@ -15,9 +15,9 @@ */ package com.intellij.lang.ant.validation; +import com.intellij.lang.ant.AntImportsIndex; import com.intellij.lang.ant.config.AntConfigurationBase; import com.intellij.lang.ant.dom.AntDomFileDescription; -import com.intellij.lang.ant.psi.impl.AntImportsIndex; import com.intellij.openapi.editor.HectorComponentPanel; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/psi/impl/PatternsTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/psi/impl/PatternsTest.java deleted file mode 100644 index 0942f6264198..000000000000 --- a/plugins/ant/tests/src/com/intellij/lang/ant/psi/impl/PatternsTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.lang.ant.psi.impl; - -import junit.framework.TestCase; - -/** - * @author Eugene Zhuravlev - * Date: May 19, 2007 - */ -public class PatternsTest extends TestCase { - public void testIncludesRecursively() { - final AntPattern antPattern = new AntPattern(true); - antPattern.addIncludePattern("**/source/**/*.java"); - - assertTrue(antPattern.acceptPath("source/foo.java")); - assertTrue(antPattern.acceptPath("source/ppp/foo.java")); - assertTrue(antPattern.acceptPath("source/ppp/qqq/foo.java")); - assertFalse(antPattern.acceptPath("src/ppp/qqq/foo.java")); - - assertTrue(antPattern.couldBeIncluded("ccc/fff/source/kkk")); - assertTrue(antPattern.couldBeIncluded("ccc/fff/src/kkk")); - } - - public void testIncludes() { - final AntPattern antPattern = new AntPattern(true); - antPattern.addIncludePattern("source/**/*.java"); - - assertTrue(antPattern.acceptPath("source/foo.java")); - assertTrue(antPattern.acceptPath("source/ppp/foo.java")); - assertTrue(antPattern.acceptPath("source/ppp/qqq/foo.java")); - assertFalse(antPattern.acceptPath("aa/source/ppp/qqq/foo.java")); - assertFalse(antPattern.acceptPath("src/ppp/qqq/foo.java")); - - assertTrue(antPattern.couldBeIncluded("source")); - assertTrue(antPattern.couldBeIncluded("source/aaa")); - assertTrue(antPattern.couldBeIncluded("source/aaa/bbb")); - assertTrue(antPattern.couldBeIncluded("source/fff/source/kkk")); - assertFalse(antPattern.couldBeIncluded("bbb/source")); - assertFalse(antPattern.couldBeIncluded("bbb/source/aaa")); - assertFalse(antPattern.couldBeIncluded("ccc/fff/source/kkk")); - assertFalse(antPattern.couldBeIncluded("ccc/fff/src/kkk")); - } - - public void testIncludesAll() { - final AntPattern antPattern = new AntPattern(true); - - assertTrue(antPattern.acceptPath("source1/foo.java")); - assertTrue(antPattern.acceptPath("source/ppp/foo.class")); - assertTrue(antPattern.acceptPath("source/ppp/qqq/bar.properties")); - assertTrue(antPattern.acceptPath("src55/ppp/qqq/foo.bar")); - - assertTrue(antPattern.couldBeIncluded("ccc/fff/source/kkk")); - assertTrue(antPattern.couldBeIncluded("ccc/fff/src/kkk")); - assertTrue(antPattern.couldBeIncluded("ccc")); - } - - public void testCouldBeExcluded() { - final AntPattern antPattern = new AntPattern(true); - antPattern.addIncludePattern("aaa/bbb/**"); - - assertTrue(antPattern.couldBeIncluded("aaa")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb/source")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb/source/com")); - assertFalse(antPattern.couldBeIncluded("aaa/bb/source/com")); - } - - public void testCouldBeExcludedWithTrailingSlash() { - final AntPattern antPattern = new AntPattern(true); - antPattern.addIncludePattern("aaa/bbb/"); - - assertFalse(antPattern.acceptPath("aaa/foo.java")); - assertTrue(antPattern.acceptPath("aaa/bbb/bar.properties")); - assertTrue(antPattern.acceptPath("aaa/bbb/source/a.xml")); - assertTrue(antPattern.acceptPath("aaa/bbb/source/com/f.ttt")); - assertFalse(antPattern.acceptPath("aaa/bb/source/com/m.bbb")); - - - assertTrue(antPattern.couldBeIncluded("aaa")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb/source")); - assertTrue(antPattern.couldBeIncluded("aaa/bbb/source/com")); - assertFalse(antPattern.couldBeIncluded("aaa/bb/source/com")); - } - -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java index 841933c8dd44..ed6cc9b9f95a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntBuilderMethod.java @@ -1,7 +1,7 @@ package org.jetbrains.plugins.groovy.gant; +import com.intellij.lang.ant.AntIntrospector; import com.intellij.lang.ant.dom.AntDomExtender; -import com.intellij.lang.ant.psi.impl.AntIntrospector; import com.intellij.openapi.util.Computable; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightMethodBuilder; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntTasksProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntTasksProvider.java index eac9b6cb22b5..8ef3340cc160 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntTasksProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/AntTasksProvider.java @@ -15,7 +15,7 @@ */ package org.jetbrains.plugins.groovy.gant; -import com.intellij.lang.ant.psi.impl.ReflectedProject; +import com.intellij.lang.ant.ReflectedProject; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; @@ -67,7 +67,7 @@ public class AntTasksProvider { static { boolean ant = false; try { - Class.forName("com.intellij.lang.ant.psi.impl.ReflectedProject"); + Class.forName("com.intellij.lang.ant.ReflectedProject"); ant = true; } catch (ClassNotFoundException ignored) {