From 5410dc520900acccf2c3c314de7d5cb68af8d6b9 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Fri, 9 Jul 2010 12:32:41 +0400 Subject: [PATCH 1/6] EA-20885 - assert: FormatProcessor.adjustIndent Check for read-only white space is applied only to backward alignment processing now --- .../src/com/intellij/formatting/FormatProcessor.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java index dc155a59b4c6..bc8d78d106d9 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java @@ -44,7 +44,7 @@ class FormatProcessor { private final CodeStyleSettings mySettings; /** - * Remembers mappings between backward-shifted aligned block and blocks that cause that shift in order to detected + * Remembers mappings between backward-shifted aligned block and blocks that cause that shift in order to detect * infinite cycles that may occur when, for example following alignment is specified: *

*

@@ -527,6 +527,13 @@ class FormatProcessor {
       return true;
     }
 
+    // Note that we can't just put this check at the method start because at least adjustSpacingByIndentOffset() may perform
+    // block states modification (e.g. define new value for 'allow to use first child indent as block indent' flag).
+    if (offsetResponsibleBlock.getWhiteSpace().isIsReadOnly()) {
+      // We're unable to perform backward shift because white space for the target element is read-only.
+      return true;
+    }
+
     // There is a possible case that alignment options are defined incorrectly. Consider the following example:
     //     int i1;
     //     int i2, i3;
@@ -538,9 +545,10 @@ class FormatProcessor {
     Set blocksCausedRealignment = myBackwardShiftedAlignedBlocks.get(offsetResponsibleBlock);
     if (blocksCausedRealignment != null && blocksCausedRealignment.contains(myCurrentBlock)) {
       LOG.error(String.format("Formatting error - code block %s is set to be shifted right because of its alignment with "
-                              + "block %s more than once. I.e. moving the former block because of alignment algo causes "
+                              + "block %s more than once. I.e. moving the former block because of alignment algorithm causes "
                               + "subsequent block to be shifted right as well - cyclic dependency",
                               offsetResponsibleBlock.getTextRange(), myCurrentBlock.getTextRange()));
+      blocksCausedRealignment.add(myCurrentBlock);
       return true;
     }
     myBackwardShiftedAlignedBlocks.clear();

From 506fcb1e0a32e2cacdcf8090c95961117c9624c4 Mon Sep 17 00:00:00 2001
From: anna 
Date: Thu, 8 Jul 2010 20:42:04 +0400
Subject: [PATCH 2/6] show progress (IDEA-56322)

---
 .../refactoring/BaseRefactoringProcessor.java        | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java
index a1dd93f35073..cacf6cf002bb 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java
@@ -308,7 +308,17 @@ public abstract class BaseRefactoringProcessor {
 
     final PsiElement[] initialElements = viewDescriptor.getElements();
     final UsageTarget[] targets = PsiElement2UsageTargetAdapter.convert(initialElements);
-    final Usage[] usages = UsageInfo2UsageAdapter.convert(usageInfos);
+    final Ref convertUsagesRef = new Ref();
+    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
+      @Override
+      public void run() {
+        convertUsagesRef.set(UsageInfo2UsageAdapter.convert(usageInfos));
+      }
+    }, "Preprocess usages", true, myProject)) return;
+
+    if (convertUsagesRef.isNull()) return;
+
+    final Usage[] usages = convertUsagesRef.get();
 
     final UsageViewPresentation presentation = createPresentation(viewDescriptor, usages);
 

From 6e6149ce79c72219bb106815f6b2d04c2695c011 Mon Sep 17 00:00:00 2001
From: anna 
Date: Thu, 8 Jul 2010 20:52:08 +0400
Subject: [PATCH 3/6] eclipse: typo - store tests output even if actual file
 doesn't exist (IDEA-56379 )

---
 .../jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
index c98af4013422..92df4d758d77 100644
--- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
+++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
@@ -176,7 +176,7 @@ public class IdeaSpecificSettings {
 
     final CompilerModuleExtension compilerModuleExtension = model.getModuleExtension(CompilerModuleExtension.class);
 
-    if (compilerModuleExtension.getCompilerOutputPathForTests() != null) {
+    if (compilerModuleExtension.getCompilerOutputUrlForTests() != null) {
       final Element pathElement = new Element(IdeaXml.OUTPUT_TEST_TAG);
       pathElement.setAttribute(IdeaXml.URL_ATTR, compilerModuleExtension.getCompilerOutputUrlForTests());
       root.addContent(pathElement);

From 60d45d96151e1a137f6dd7bed8da0d946e4e2987 Mon Sep 17 00:00:00 2001
From: anna 
Date: Fri, 9 Jul 2010 13:00:16 +0400
Subject: [PATCH 4/6] eclipse: write the first javadoc root to .classpath,
 others to .eml (IDEA-56380)

---
 .../idea/eclipse/conversion/EJavadocUtil.java |   4 ++--
 .../conversion/IdeaSpecificSettings.java      |  12 ++++++++++++
 .../expected/.classpath                       |   9 +++++++++
 .../expected/ws-internals.eml                 |   8 ++++++++
 .../srcvariableidea1/test.jar                 | Bin 0 -> 840 bytes
 .../test/.classpath                           |   5 +++++
 .../test/.project                             |  17 +++++++++++++++++
 .../variableidea/test.jar                     | Bin 0 -> 840 bytes
 .../EclipseLibrariesModificationsTest.java    |  18 ++++++++++++++++--
 9 files changed, 69 insertions(+), 4 deletions(-)
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/.classpath
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/ws-internals.eml
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/srcvariableidea1/test.jar
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.classpath
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.project
 create mode 100644 plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/variableidea/test.jar

diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/EJavadocUtil.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/EJavadocUtil.java
index b48d3c843f7c..9c9e94bb7607 100644
--- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/EJavadocUtil.java
+++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/EJavadocUtil.java
@@ -197,8 +197,8 @@ public class EJavadocUtil {
   static void setupJavadocAttributes(Element orderEntry, LibraryOrderEntry libraryOrderEntry, final ModuleRootModel model) {
     final List eclipseUrls = new ArrayList();
     final String[] docUrls = libraryOrderEntry.getRootUrls(JavadocOrderRootType.getInstance());
-    for (String docUrl : docUrls) {
-      eclipseUrls.add(toEclipseJavadocPath(model, docUrl));
+    if (docUrls.length > 0) {
+      eclipseUrls.add(toEclipseJavadocPath(model, docUrls[0]));
     }
 
     final List children = new ArrayList(orderEntry.getChildren(ATTRIBUTES_TAG));
diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
index 92df4d758d77..995ecb8ff26e 100644
--- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
+++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java
@@ -64,6 +64,7 @@ public class IdeaSpecificSettings {
 
   @NonNls private static final String SRCROOT_ATTR = "srcroot";
   private static final Logger LOG = Logger.getInstance("#" + IdeaSpecificSettings.class.getName());
+  @NonNls private static final String JAVADOCROOT_ATTR = "javadocroot_attr";
 
   private IdeaSpecificSettings() {
   }
@@ -106,6 +107,10 @@ public class IdeaSpecificSettings {
         appendLibraryScope(model, libElement, libraryByName);
         final Library.ModifiableModel modifiableModel = libraryByName.getModifiableModel();
         replaceCollapsedByEclipseSourceRoots(libElement, modifiableModel);
+        for (Object r : libElement.getChildren(JAVADOCROOT_ATTR)) {
+          final String url = ((Element)r).getAttributeValue("url");
+          modifiableModel.addRoot(url, JavadocOrderRootType.getInstance());
+        }
         replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, RELATIVE_MODULE_SRC);
         replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, RELATIVE_MODULE_CLS);
         replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, JavadocOrderRootType.getInstance(), RELATIVE_MODULE_JAVADOC);
@@ -248,6 +253,13 @@ public class IdeaSpecificSettings {
           element.addContent(srcElement);
         }
 
+        final String[] javadocUrls = libraryEntry.getRootUrls(JavadocOrderRootType.getInstance());
+        for (int i = 1; i < javadocUrls.length;  i++) {
+          Element javadocElement = new Element(JAVADOCROOT_ATTR);
+          javadocElement.setAttribute("url", javadocUrls[i]);
+          element.addContent(javadocElement);
+        }
+
         for (String srcUrl : libraryEntry.getRootUrls(OrderRootType.SOURCES)) {
           appendModuleRelatedRoot(element, srcUrl, RELATIVE_MODULE_SRC, model);
         }
diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/.classpath b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/.classpath
new file mode 100644
index 000000000000..4b571b36ea65
--- /dev/null
+++ b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/.classpath
@@ -0,0 +1,9 @@
+
+
+  
+    
+      
+    
+  
+  
+
diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/ws-internals.eml b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/ws-internals.eml
new file mode 100644
index 000000000000..7dfadd07d41e
--- /dev/null
+++ b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/expected/ws-internals.eml
@@ -0,0 +1,8 @@
+
+
+  
+  
+  
+    
+  
+
\ No newline at end of file
diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/srcvariableidea1/test.jar b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/srcvariableidea1/test.jar
new file mode 100644
index 0000000000000000000000000000000000000000..69d35ecffe38daa9f5223585d031f42787e479ea
GIT binary patch
literal 840
zcmWIWW@h1H0D*&D*;Zf%l;C7wVeoYgan$wnbJPEKih&^js+5D_08pvpv?#qOpwcuT
z76D?oQeQ_uPdC@#5ItYF&%S3)`*`c>UF7xF)jD_P{N^BoE5;9=7M*bxD%A1tIp-0|
z(8Z{F_A5{2&Nakr?==Sg2p
zDtA`wgu8`-VKbVuxq)s;P0qCj$a%FO#%hK-c`}?QrKSM!hEq7^&@0(dSlq0?$e0+Da{fl;IC-WIy
zOFsln?A;q6t|c8WEMtHESyYOZ&`YOn7nDu%LzaEfU07EnCCFnh@7W~1!snZ~{zjcP
zCBM{})76!FT^4%n%aW>E^sJ@XL2c!%v#AS`^v{U9D#=S!E>H~?wfD3=>FyI2zG}-Z
z>AS8!gQRu0aPF<2%rW<@S#yP!u&=@Nr$X-G7H+-!85Lv>IW%Waj^tI7*GiVueOD3F
znf>?;@0TdgZ4$FXH}lTE_)qY_!7|Yo>&`wGJs!XK^J$Olwxj^j
c2(tPCsz&sL5#Y_r22#udg#UrGF%yUf0C~Xuh5!Hn

literal 0
HcmV?d00001

diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.classpath b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.classpath
new file mode 100644
index 000000000000..f62ed8d1c84a
--- /dev/null
+++ b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.classpath
@@ -0,0 +1,5 @@
+
+
+  
+  
+
\ No newline at end of file
diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.project b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.project
new file mode 100644
index 000000000000..3c7030a86519
--- /dev/null
+++ b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/test/.project
@@ -0,0 +1,17 @@
+
+
+	ws-internals
+	
+	
+	
+	
+		
+			org.eclipse.jdt.core.javabuilder
+			
+			
+		
+	
+	
+		org.eclipse.jdt.core.javanature
+	
+
diff --git a/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/variableidea/test.jar b/plugins/eclipse/testData/modification/replacedExistingWithMultipleJavadocs/variableidea/test.jar
new file mode 100644
index 0000000000000000000000000000000000000000..69d35ecffe38daa9f5223585d031f42787e479ea
GIT binary patch
literal 840
zcmWIWW@h1H0D*&D*;Zf%l;C7wVeoYgan$wnbJPEKih&^js+5D_08pvpv?#qOpwcuT
z76D?oQeQ_uPdC@#5ItYF&%S3)`*`c>UF7xF)jD_P{N^BoE5;9=7M*bxD%A1tIp-0|
z(8Z{F_A5{2&Nakr?==Sg2p
zDtA`wgu8`-VKbVuxq)s;P0qCj$a%FO#%hK-c`}?QrKSM!hEq7^&@0(dSlq0?$e0+Da{fl;IC-WIy
zOFsln?A;q6t|c8WEMtHESyYOZ&`YOn7nDu%LzaEfU07EnCCFnh@7W~1!snZ~{zjcP
zCBM{})76!FT^4%n%aW>E^sJ@XL2c!%v#AS`^v{U9D#=S!E>H~?wfD3=>FyI2zG}-Z
z>AS8!gQRu0aPF<2%rW<@S#yP!u&=@Nr$X-G7H+-!85Lv>IW%Waj^tI7*GiVueOD3F
znf>?;@0TdgZ4$FXH}lTE_)qY_!7|Yo>&`wGJs!XK^J$Olwxj^j
c2(tPCsz&sL5#Y_r22#udg#UrGF%yUf0C~Xuh5!Hn

literal 0
HcmV?d00001

diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseLibrariesModificationsTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseLibrariesModificationsTest.java
index 15a431bc6764..a18977e3d81d 100644
--- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseLibrariesModificationsTest.java
+++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseLibrariesModificationsTest.java
@@ -22,6 +22,7 @@ package org.jetbrains.idea.eclipse;
 
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.JavadocOrderRootType;
 import com.intellij.openapi.roots.ModifiableRootModel;
 import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.roots.OrderRootType;
@@ -74,10 +75,15 @@ public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
   }
 
   public void testReplacedExistingWithVariablesCantReplaceSrc() throws Exception {
-    doTestExisting(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea1/test.jar!/"});
+    doTestExisting(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea1/test.jar!/"}, new String[0]);
   }
 
-  private void doTestExisting(String[] classRoots, String[] sourceRoots) throws Exception {
+   public void testReplacedExistingWithMultipleJavadocs() throws Exception {
+    doTestExisting(new String[]{"/variableidea/test.jar!/"}, new String[]{},
+                   new String[]{"/srcvariableidea1/test.jar!/", "/srcvariableidea11/test.jar!/"});
+  }
+
+  private void doTestExisting(String[] classRoots, String[] sourceRoots, String[] javadocs) throws Exception {
     final Project project = getProject();
     final String path = project.getBaseDir().getPath() + "/test";
     final Module module = EclipseClasspathTest.setUpModule(path, project);
@@ -94,11 +100,19 @@ public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
     for (String oldSrcRoot : oldSrcRoots) {
       libModifiableModel.removeRoot(oldSrcRoot, OrderRootType.SOURCES);
     }
+
+    final String[] oldJdcRoots = libModifiableModel.getUrls(JavadocOrderRootType.getInstance());
+    for (String oldJavadocRoot : oldJdcRoots) {
+      libModifiableModel.removeRoot(oldJavadocRoot, JavadocOrderRootType.getInstance());
+    }
     for (String classRoot : classRoots) {
       libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
     }
     for (String sourceRoot : sourceRoots) {
       libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
+    }
+     for (String javadocRoot : javadocs) {
+      libModifiableModel.addRoot(parentUrl + javadocRoot, JavadocOrderRootType.getInstance());
     }
     libModifiableModel.commit();
     model.commit();

From c84ca7dc14cabb743a9ad097caf4d17af2e57446 Mon Sep 17 00:00:00 2001
From: Eugene Zhuravlev 
Date: Thu, 8 Jul 2010 22:21:57 +0400
Subject: [PATCH 5/6] namespaces used correctly

---
 .../intellij/lang/ant/dom/AntDomAntlib.java   |  42 ++++++
 .../lang/ant/dom/AntDomCustomElement.java     |   2 +-
 .../intellij/lang/ant/dom/AntDomExtender.java |  11 +-
 .../intellij/lang/ant/dom/AntDomMacroDef.java |  23 +++
 .../lang/ant/dom/AntDomPresetDef.java         |  23 +++
 .../lang/ant/dom/AntDomRecursiveVisitor.java  |  16 ++
 .../lang/ant/dom/AntDomScriptDef.java         |  23 +++
 .../intellij/lang/ant/dom/AntDomTaskdef.java  |  23 +++
 .../ant/dom/CustomAntElementsRegistry.java    | 142 ++++++++++--------
 .../dom/AbstractDomChildrenDescriptor.java    |   8 +
 10 files changed, 243 insertions(+), 70 deletions(-)
 create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomAntlib.java
 create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomMacroDef.java
 create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomPresetDef.java
 create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomScriptDef.java
 create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomTaskdef.java

diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAntlib.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAntlib.java
new file mode 100644
index 000000000000..60d59c70ab64
--- /dev/null
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAntlib.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2000-2010 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.dom;
+
+import com.intellij.util.xml.SubTagList;
+
+import java.util.List;
+
+/**
+ * @author Eugene Zhuravlev
+ *         Date: Jul 8, 2010
+ */
+public abstract class AntDomAntlib extends AntDomElement{
+
+  @SubTagList("typedef")
+  public abstract List getTypedefs();
+
+  @SubTagList("taskdef")
+  public abstract List getTaskdefs();
+
+  @SubTagList("macrodef")
+  public abstract List getMacrodefs();
+
+  @SubTagList("presetdef")
+  public abstract List getPresetdefs();
+
+  @SubTagList("scriptdef")
+  public abstract List getScriptdefs();
+}
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomCustomElement.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomCustomElement.java
index f852c9e02284..d0c23b7d8751 100644
--- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomCustomElement.java
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomCustomElement.java
@@ -27,7 +27,7 @@ public abstract class AntDomCustomElement extends AntDomElement{
   @Nullable
   public final Class getDefinitionClass() {
     final String name = getXmlElementName();
-    final String nsKey = getXmlElementNamespaceKey();
+    final String nsKey = getXmlElementNamespace();
     return CustomAntElementsRegistry.getInstance(getAntProject()).lookupClass(new XmlName(name, nsKey));
   }
 }
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 869cfc14fad1..26888f508b99 100644
--- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java
@@ -45,7 +45,11 @@ public class AntDomExtender extends DomExtender{
     TAG_MAPPING.put("path", AntDomPath.class);
     TAG_MAPPING.put("classpath", AntDomPath.class);
     TAG_MAPPING.put("typedef", AntDomTypeDef.class);
-    TAG_MAPPING.put("taskdef", AntDomTypeDef.class);
+    TAG_MAPPING.put("taskdef", AntDomTaskdef.class);
+    TAG_MAPPING.put("presetdef", AntDomPresetDef.class);
+    TAG_MAPPING.put("macrodef", AntDomMacroDef.class);
+    TAG_MAPPING.put("scriptdef", AntDomScriptDef.class);
+    TAG_MAPPING.put("antlib", AntDomAntlib.class);
   }
 
   public void registerExtensions(@NotNull AntDomElement antDomElement, @NotNull DomExtensionsRegistrar registrar) {
@@ -217,7 +221,8 @@ public class AntDomExtender extends DomExtender{
       final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(element.getAntProject());
       final Set result = new HashSet();
       for (XmlName variant : registry.getCompletionVariants(element)) {
-        result.add(new DummyEvaluatedXmlName(variant, null));
+        final String ns = variant.getNamespaceKey();
+        result.add(new DummyEvaluatedXmlName(variant, ns != null? ns : ""));
       }
       return result;
     }
@@ -230,7 +235,7 @@ public class AntDomExtender extends DomExtender{
 
     @Nullable
     public PomTarget findDeclaration(@NotNull DomElement child) {
-      XmlName name = new XmlName(child.getXmlElementName(), child.getXmlElementNamespaceKey());
+      XmlName name = new XmlName(child.getXmlElementName(), child.getXmlElementNamespace());
       return doFindDeclaration(child.getParent(), name);
     }
 
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomMacroDef.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomMacroDef.java
new file mode 100644
index 000000000000..d3d7847e0711
--- /dev/null
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomMacroDef.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2010 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.dom;
+
+/**
+ * @author Eugene Zhuravlev
+ *         Date: Jul 8, 2010
+ */
+public abstract class AntDomMacroDef extends AntDomNamedElement{
+}
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPresetDef.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPresetDef.java
new file mode 100644
index 000000000000..837554569d29
--- /dev/null
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomPresetDef.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2010 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.dom;
+
+/**
+ * @author Eugene Zhuravlev
+ *         Date: Jul 8, 2010
+ */
+public abstract class AntDomPresetDef extends AntDomNamedElement{
+}
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomRecursiveVisitor.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomRecursiveVisitor.java
index f92c6ec73089..d11992356fb3 100644
--- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomRecursiveVisitor.java
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomRecursiveVisitor.java
@@ -36,6 +36,22 @@ public class AntDomRecursiveVisitor implements DomElementVisitor{
     visitAntDomElement(typedef);
   }
 
+  public void visitTaskDef(AntDomTaskdef typedef) {
+    visitTypeDef(typedef);
+  }
+
+  public void visitMacroDef(AntDomMacroDef macrodef) {
+    visitAntDomElement(macrodef);
+  }
+
+  public void visitPresetDef(AntDomPresetDef presetdef) {
+    visitAntDomElement(presetdef);
+  }
+
+  public void visitScriptDef(AntDomScriptDef scriptdef) {
+    visitAntDomElement(scriptdef);
+  }
+
   public void visitTarget(AntDomTarget target) {
     visitAntDomElement(target);
   }
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomScriptDef.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomScriptDef.java
new file mode 100644
index 000000000000..adf423331bac
--- /dev/null
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomScriptDef.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2010 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.dom;
+
+/**
+ * @author Eugene Zhuravlev
+ *         Date: Jul 8, 2010
+ */
+public abstract class AntDomScriptDef extends AntDomNamedElement{
+}
diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomTaskdef.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomTaskdef.java
new file mode 100644
index 000000000000..53dd264a8cbc
--- /dev/null
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomTaskdef.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2010 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.dom;
+
+/**
+ * @author Eugene Zhuravlev
+ *         Date: Jul 8, 2010
+ */
+public abstract class AntDomTaskdef extends AntDomTypeDef{
+}
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 1f7d59d2b03d..dcdfe8a7e1e6 100644
--- a/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java
+++ b/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java
@@ -26,6 +26,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiFileFactory;
@@ -59,10 +60,13 @@ public class CustomAntElementsRegistry {
   private final Map myCustomElements = new HashMap();
   private final Map myErrors = new HashMap();
   private final Map myDeclarations = new HashMap();
+  private final Map myNamedLoaders = new HashMap();
 
   private CustomAntElementsRegistry(final AntDomProject antProject) {
     antProject.accept(new BaseVisitor() {
       public void visitTypeDef(AntDomTypeDef typedef) {
+        // if loaderRef attribute is specified, make sure the loader is built and stored
+        rememberNamedClassLoader(typedef, antProject);
         defineCustomElements(typedef, antProject);
       }
     });
@@ -126,12 +130,11 @@ public class CustomAntElementsRegistry {
 
   private void defineCustomElements(AntDomTypeDef typedef, final AntDomProject antProject) {
     final String uri = typedef.getUri().getStringValue();
-    final String nsPrefix = (uri == null) ? null : typedef.getXmlTag().getPrefixByNamespace(uri);
 
     final String customTagName = typedef.getName().getStringValue();
     final String classname = typedef.getClassName().getStringValue();
     if (classname != null && customTagName != null) {
-      registerElement(typedef, customTagName, nsPrefix, classname, getClassLoader(collectUrls(typedef), antProject));
+      registerElement(typedef, customTagName, uri, classname, getClassLoader(typedef, antProject));
     }
     else {
       final XmlElement xmlElement = antProject.getXmlElement();
@@ -139,11 +142,11 @@ public class CustomAntElementsRegistry {
       if (project != null) {
         final String resource = typedef.getResource().getStringValue();
         if (resource != null) {
-          final ClassLoader loader = getClassLoader(collectUrls(typedef), antProject);
+          final ClassLoader loader = getClassLoader(typedef, antProject);
           if (loader != null) {
             final InputStream stream = loader.getResourceAsStream(resource);
             if (stream != null) {
-              loadFromStream(typedef, nsPrefix, resource, loader, stream, project);
+              loadFromStream(typedef, uri, resource, loader, stream, project);
             }
           }
         }
@@ -155,7 +158,7 @@ public class CustomAntElementsRegistry {
               try {
                 final InputStream stream = vf.getInputStream();
                 if (stream != null) {
-                  loadFromStream(typedef, nsPrefix, file.getName(), getClassLoader(collectUrls(typedef), antProject), stream, project);
+                  loadFromStream(typedef, uri, file.getName(), getClassLoader(typedef, antProject), stream, project);
                 }
               }
               catch (IOException e) {
@@ -168,6 +171,24 @@ public class CustomAntElementsRegistry {
     }
   }
 
+  private void rememberNamedClassLoader(AntDomTypeDef typedef, AntDomProject antProject) {
+    final String loaderRef = typedef.getLoaderRef().getStringValue();
+    if (loaderRef != null) {
+      if (!myNamedLoaders.containsKey(loaderRef)) {
+        myNamedLoaders.put(loaderRef, createClassLoader(collectUrls(typedef), antProject));
+      }
+    }
+  }
+
+  @Nullable
+  private ClassLoader getClassLoader(AntDomTypeDef typedef, AntDomProject antProject) {
+    final String loaderRef = typedef.getLoaderRef().getStringValue();
+    if (loaderRef != null && myNamedLoaders.containsKey(loaderRef)) {
+      return myNamedLoaders.get(loaderRef);
+    }
+    return createClassLoader(collectUrls(typedef), antProject);
+  }
+
   private void loadFromStream(AntDomTypeDef typedef, String nsPrefix, String resource, ClassLoader loader, InputStream stream, final Project project) {
     if (isXmlFormat(typedef, resource)) {
       // todo
@@ -199,56 +220,53 @@ public class CustomAntElementsRegistry {
     }
   }
 
-  //static void loadAntlibStream(@NotNull final InputStream antlibStream, final String nsPrefix, Project project) {
-  //  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, project);
-  //    final XmlDocument document = xmlFile.getDocument();
-  //    if (document != null) {
-  //      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);
-  //  }
-  //}
+  /*
+  static void loadAntlibStream(@NotNull final InputStream antlibStream, final String nsPrefix, Project project) {
+    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, project);
+      final XmlDocument document = xmlFile.getDocument();
+      if (document != null) {
+        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);
+              }
+            }
+          }
+        }
+      }
+    }
+    catch (IOException e) {
+      LOG.info(e);
+    }
+    finally {
+      StringBuilderSpinAllocator.dispose(builder);
+    }
+  }
+  */
 
 
-  private void registerElement(AntDomTypeDef typedef, String customTagName, String nsPrefix, String classname, ClassLoader loader) {
+  private void registerElement(AntDomTypeDef typedef, String customTagName, String nsUri, String classname, ClassLoader loader) {
     Class clazz = null;
     String error = "";
     try {
@@ -266,7 +284,7 @@ public class CustomAntElementsRegistry {
       error = e.getMessage();
       clazz = null;
     }
-    final XmlName xmlName = (nsPrefix == null) ? new XmlName(customTagName) : new XmlName(customTagName, nsPrefix);
+    final XmlName xmlName = new XmlName(customTagName, nsUri == null? "" : nsUri);
     if (clazz != null) {
       myCustomElements.put(xmlName, clazz);
       myDeclarations.put(xmlName, typedef);
@@ -283,26 +301,18 @@ public class CustomAntElementsRegistry {
   private static boolean isXmlFormat(AntDomTypeDef typedef, @NotNull final String resourceOrFileName) {
     final String format = typedef.getFormat().getStringValue();
     if (format != null) {
-      return format.equals("xml");
+      return "xml".equalsIgnoreCase(format);
     }
-    return resourceOrFileName.endsWith(".xml");
+    return StringUtil.endsWithIgnoreCase(resourceOrFileName, ".xml");
   }
 
   @Nullable
-  private static ClassLoader getClassLoader(final List urls, final AntDomProject antProject) {
+  private static ClassLoader createClassLoader(final List urls, final AntDomProject antProject) {
     final ClassLoader parentLoader = antProject.getClassLoader();
     if (urls.size() == 0) {
       return parentLoader;
     }
-
-    //final ClassLoader cached = LOADERS_CACHE.getClassLoader(urls);
-    //if (cached != null && parentLoader == cached.getParent()) {
-    //  return cached;
-    //}
-
-    final ClassLoader loader = new AntResourcesClassLoader(urls, parentLoader, false, false);
-    //LOADERS_CACHE.setClassLoader(urls, loader);
-    return loader;
+    return new AntResourcesClassLoader(urls, parentLoader, false, false);
   }
 
   private static List collectUrls(AntDomTypeDef typedef) {
diff --git a/xml/dom-impl/src/com/intellij/xml/impl/dom/AbstractDomChildrenDescriptor.java b/xml/dom-impl/src/com/intellij/xml/impl/dom/AbstractDomChildrenDescriptor.java
index 38f6f51d89b9..a5c8b06681d4 100644
--- a/xml/dom-impl/src/com/intellij/xml/impl/dom/AbstractDomChildrenDescriptor.java
+++ b/xml/dom-impl/src/com/intellij/xml/impl/dom/AbstractDomChildrenDescriptor.java
@@ -48,10 +48,18 @@ public abstract class AbstractDomChildrenDescriptor implements XmlElementDescrip
 
     final CustomDomChildrenDescription customDescription = domElement.getGenericInfo().getCustomNameChildrenDescription();
     if (customDescription != null) {
+      final XmlTag xmlTag = domElement.getXmlTag();
       for (final EvaluatedXmlName name : customDescription.getTagNameDescriptor().getCompletionVariants(domElement)) {
         xmlElementDescriptors.add(new AbstractDomChildrenDescriptor(myManager) {
           @Override
           public String getDefaultName() {
+            final String ns = xmlTag != null? name.getNamespace(xmlTag, (XmlFile)xmlTag.getContainingFile()) : null;
+            if (ns != null) {
+              final String prefix = xmlTag.getPrefixByNamespace(ns);
+              if (prefix != null) {
+                return prefix + ":" + name.getXmlName().getLocalName();
+              }
+            }
             return name.getXmlName().getLocalName();
           }
 

From cf6189ab1729f46dd778da33d2d8dbcb88976ae2 Mon Sep 17 00:00:00 2001
From: Alexey Kudravtsev 
Date: Wed, 7 Jul 2010 16:47:06 +0400
Subject: [PATCH 6/6] OOME guard

---
 .../intellij/util/containers/WeaksTestCase.java | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java b/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java
index 9d88ab2989ab..6f426d0e7a16 100644
--- a/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java
+++ b/platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java
@@ -45,13 +45,18 @@ public abstract class WeaksTestCase extends TestCase {
 
   protected static void gc() {
     System.gc();
-    List list = new ArrayList();
-    while (Runtime.getRuntime().freeMemory() > 10000) {
-      list.add(new byte[1000]);
-    }
+    try {
+      List list = new ArrayList();
+      while (Runtime.getRuntime().freeMemory() > 10000) {
+        list.add(new byte[1000]);
+      }
 
-    System.gc();
-    list = null;
+      System.gc();
+      list = null;
+    }
+    catch (OutOfMemoryError e) {
+      // ignore
+    }
     System.gc();
 
     WeakReference weakReference = new WeakReference(new Object());