mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
add jdom to source code to modify and strip to our needs
GitOrigin-RevId: 3e16d0d954aa7bc45c4eadb91164b44e4b2e75d3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
24c055ad07
commit
a8f6a48409
15
.idea/libraries/JDOM.xml
generated
15
.idea/libraries/JDOM.xml
generated
@@ -1,15 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="JDOM" type="repository">
|
||||
<properties maven-id="org.jetbrains.intellij.deps:jdom:2.0.6" />
|
||||
<ANNOTATIONS>
|
||||
<root url="file://$PROJECT_DIR$/lib/annotations/jdom" />
|
||||
</ANNOTATIONS>
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/jdom/2.0.6/jdom-2.0.6.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/jdom/2.0.6/jdom-2.0.6-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -859,6 +859,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util-ex/intellij.platform.util.ex.iml" filepath="$PROJECT_DIR$/platform/util-ex/intellij.platform.util.ex.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/immutable-key-value-store/intellij.platform.util.immutableKeyValueStore.iml" filepath="$PROJECT_DIR$/platform/util/immutable-key-value-store/intellij.platform.util.immutableKeyValueStore.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/immutable-key-value-store/benchmark/intellij.platform.util.immutableKeyValueStore.benchmark.iml" filepath="$PROJECT_DIR$/platform/util/immutable-key-value-store/benchmark/intellij.platform.util.immutableKeyValueStore.benchmark.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/jdom/intellij.platform.util.jdom.iml" filepath="$PROJECT_DIR$/platform/util/jdom/intellij.platform.util.jdom.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util-rt/intellij.platform.util.rt.iml" filepath="$PROJECT_DIR$/platform/util-rt/intellij.platform.util.rt.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/rt-java8/intellij.platform.util.rt.java8.iml" filepath="$PROJECT_DIR$/platform/util/rt-java8/intellij.platform.util.rt.java8.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/testSrc/intellij.platform.util.tests.iml" filepath="$PROJECT_DIR$/platform/util/testSrc/intellij.platform.util.tests.iml" />
|
||||
|
||||
@@ -33,6 +33,7 @@ final class CommunityStandaloneJpsBuilder {
|
||||
module("intellij.platform.util.text.matching")
|
||||
module("intellij.platform.util.base")
|
||||
module("intellij.platform.util.xmlDom")
|
||||
module("intellij.platform.util.jdom")
|
||||
module("intellij.platform.tracing.rt")
|
||||
module("intellij.platform.util.diff")
|
||||
module("intellij.platform.util.rt.java8")
|
||||
@@ -87,7 +88,7 @@ final class CommunityStandaloneJpsBuilder {
|
||||
jar("space-java-jps.jar") { module("intellij.space.java.jps") }
|
||||
|
||||
for (String name in List.of(
|
||||
"JDOM", "jna", "OroMatcher", "Trove4j", "ASM", "NanoXML", "protobuf", "cli-parser", "Log4J", "jgoodies-forms", "Eclipse",
|
||||
"jna", "OroMatcher", "Trove4j", "ASM", "NanoXML", "protobuf", "cli-parser", "Log4J", "jgoodies-forms", "Eclipse",
|
||||
"netty-codec-http", "lz4-java", "commons-codec", "commons-logging", "http-client", "Slf4j", "Guava", "plexus-utils",
|
||||
"jetbrains-annotations-java5", "gson", "jps-javac-extension", "fastutil-min", "kotlin-stdlib-jdk8",
|
||||
"commons-lang3", "maven-resolver-provider", "netty-buffer", "aalto-xml"
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -8,7 +8,7 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.java.guiForms.rt" />
|
||||
<orderEntry type="library" name="ASM" level="project" />
|
||||
<orderEntry type="library" name="jgoodies-forms" level="project" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler" exported="" />
|
||||
<orderEntry type="library" name="OroMatcher" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="module" module-name="intellij.java" />
|
||||
<orderEntry type="module" module-name="intellij.java.rt" />
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.jps" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module relativePaths="false" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.java" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
@@ -58,8 +58,8 @@ public abstract class PackagingElementsTestCase extends ArtifactsTestCase {
|
||||
return VfsTestUtil.createDir(getOrCreateProjectBaseDir(), path);
|
||||
}
|
||||
|
||||
protected static VirtualFile getJDomJar() {
|
||||
return IntelliJProjectConfiguration.getJarFromSingleJarProjectLibrary("JDOM");
|
||||
protected static VirtualFile getFastUtilJar() {
|
||||
return IntelliJProjectConfiguration.getJarFromSingleJarProjectLibrary("fastutil-min");
|
||||
}
|
||||
|
||||
protected static String getLocalJarPath(VirtualFile jarEntry) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compiler.artifacts.ui;
|
||||
|
||||
import com.intellij.compiler.artifacts.ArtifactsTestUtil;
|
||||
@@ -28,7 +29,7 @@ public class ExtractArtifactActionTest extends ArtifactEditorActionTestCase {
|
||||
}
|
||||
|
||||
public void testDisabledForJarFromLib() {
|
||||
final VirtualFile jar = getJDomJar();
|
||||
final VirtualFile jar = getFastUtilJar();
|
||||
createEditor(addArtifact(root().lib(addProjectLibrary(null, "dom", jar))), true);
|
||||
|
||||
selectNode(jar.getName());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compiler.artifacts.ui;
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
@@ -68,17 +68,17 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
|
||||
public void testModuleWithLibraryJar() {
|
||||
final Module module = addModuleWithSourceRoot("a");
|
||||
addProjectLibrary(module, "jdom", getJDomJar());
|
||||
addProjectLibrary(module, "jdom", getFastUtilJar());
|
||||
createFromTemplate(module, null, null, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a\n" +
|
||||
" extracted:" + getLocalJarPath(getJDomJar()) + "!/");
|
||||
" extracted:" + getLocalJarPath(getFastUtilJar()) + "!/");
|
||||
}
|
||||
|
||||
public void testModuleWithLibraryJarWithManifest() {
|
||||
final VirtualFile file = createFile("src/A.java");
|
||||
final Module module = addModule("a", file.getParent());
|
||||
VirtualFile jDomJar = getJDomJar();
|
||||
VirtualFile jDomJar = getFastUtilJar();
|
||||
addProjectLibrary(module, "jdom", jDomJar);
|
||||
createFromTemplate(module, null, file.getParent().getPath(), false);
|
||||
assertLayout("<root>\n" +
|
||||
@@ -90,7 +90,7 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
|
||||
public void testSkipTestLibrary() {
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getJDomJar());
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a");
|
||||
@@ -98,7 +98,7 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
|
||||
public void testSkipProvidedLibrary() {
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
addProjectLibrary(a, "jdom", DependencyScope.PROVIDED, getJDomJar());
|
||||
addProjectLibrary(a, "jdom", DependencyScope.PROVIDED, getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a");
|
||||
@@ -107,21 +107,21 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
public void testIncludeTests() {
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
PsiTestUtil.addSourceRoot(a, createDir("testSrc-a"), true);
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getJDomJar());
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a\n" +
|
||||
" module-tests:a\n" +
|
||||
" extracted:" + getLocalJarPath(getJDomJar()) + "!/");
|
||||
" extracted:" + getLocalJarPath(getFastUtilJar()) + "!/");
|
||||
}
|
||||
|
||||
public void testDoNotIncludeTestsForModuleWithoutTestSources() {
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getJDomJar());
|
||||
addProjectLibrary(a, "jdom", DependencyScope.TEST, getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a\n" +
|
||||
" extracted:" + getLocalJarPath(getJDomJar()) + "!/");
|
||||
" extracted:" + getLocalJarPath(getFastUtilJar()) + "!/");
|
||||
}
|
||||
|
||||
public void testTwoIndependentModules() {
|
||||
@@ -155,12 +155,12 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
final Module b = addModuleWithSourceRoot("b");
|
||||
addModuleDependency(a, b);
|
||||
addProjectLibrary(b, "jdom", getJDomJar());
|
||||
addProjectLibrary(b, "jdom", getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a\n" +
|
||||
" module:b\n" +
|
||||
" extracted:" + getLocalJarPath(getJDomJar()) + "!/");
|
||||
" extracted:" + getLocalJarPath(getFastUtilJar()) + "!/");
|
||||
}
|
||||
|
||||
public void testExtractedLibraryWithDirectories() {
|
||||
@@ -190,18 +190,18 @@ public class JarFromModulesTemplateTest extends PackagingElementsTestCase {
|
||||
public void testExtractedLibraryWithJarsAndDirs() {
|
||||
final VirtualFile dir = createDir("lib");
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
addProjectLibrary(a, "dir", dir, getJDomJar());
|
||||
addProjectLibrary(a, "dir", dir, getFastUtilJar());
|
||||
createFromTemplate(a, null, null, true);
|
||||
assertLayout("a.jar\n" +
|
||||
" module:a\n" +
|
||||
" dir:" + dir.getPath() + "\n" +
|
||||
" extracted:" + getLocalJarPath(getJDomJar()) + "!/");
|
||||
" extracted:" + getLocalJarPath(getFastUtilJar()) + "!/");
|
||||
}
|
||||
|
||||
public void testCopiedLibraryWithJarsAndDirs() {
|
||||
final VirtualFile dir = createDir("lib");
|
||||
final Module a = addModuleWithSourceRoot("a");
|
||||
VirtualFile jDomJar = getJDomJar();
|
||||
VirtualFile jDomJar = getFastUtilJar();
|
||||
addProjectLibrary(a, "dir", dir, jDomJar);
|
||||
final String basePath = myProject.getBasePath();
|
||||
createFromTemplate(a, null, basePath, false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compiler.artifacts.ui;
|
||||
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
@@ -42,7 +43,7 @@ public class RemoveActionTest extends ArtifactEditorTestCase {
|
||||
}
|
||||
|
||||
public void testJarFileInLibrary() {
|
||||
VirtualFile jDomJar = getJDomJar();
|
||||
VirtualFile jDomJar = getFastUtilJar();
|
||||
final Library library = addProjectLibrary(null, "jdom", jDomJar);
|
||||
createEditor(addArtifact(root().lib(library)), true);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
|
||||
<orderEntry type="library" name="gson" level="project" />
|
||||
<orderEntry type="library" name="ASM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<orderEntry type="module" module-name="intellij.jsp" />
|
||||
<orderEntry type="module" module-name="intellij.java.psi" />
|
||||
<orderEntry type="module" module-name="intellij.java.resources.en" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang" />
|
||||
<orderEntry type="module" module-name="intellij.platform.debugger" exported="" />
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.util.classLoader" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -34,5 +34,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="library" name="gson" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.feedback" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
@@ -30,6 +16,7 @@ import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -41,13 +28,11 @@ import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.util.ArrayUtil.contains;
|
||||
|
||||
public class CreateModuleLibraryChooser implements ClasspathElementChooser<Library> {
|
||||
private final JComponent myParentComponent;
|
||||
private final Module myModule;
|
||||
private final LibraryTable.ModifiableModel myModuleLibrariesModel;
|
||||
@Nullable private final Function<? super LibraryType, ? extends LibraryProperties> myDefaultPropertiesFactory;
|
||||
private final @Nullable Function<? super LibraryType, ? extends LibraryProperties> myDefaultPropertiesFactory;
|
||||
private final HashMap<LibraryRootsComponentDescriptor,LibraryType> myLibraryTypes;
|
||||
private final DefaultLibraryRootsComponentDescriptor myDefaultDescriptor;
|
||||
|
||||
@@ -59,7 +44,7 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
public CreateModuleLibraryChooser(List<? extends LibraryType> libraryTypes, JComponent parentComponent,
|
||||
Module module,
|
||||
final LibraryTable.ModifiableModel moduleLibrariesModel,
|
||||
@Nullable final Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
final @Nullable Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
myParentComponent = parentComponent;
|
||||
myModule = module;
|
||||
myModuleLibrariesModel = moduleLibrariesModel;
|
||||
@@ -81,13 +66,13 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
}
|
||||
}
|
||||
|
||||
private static Library createLibraryFromRoots(@NotNull List<? extends OrderRoot> roots,
|
||||
@Nullable final LibraryType libraryType,
|
||||
@NotNull LibraryTable.ModifiableModel moduleLibrariesModel,
|
||||
@Nullable Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
|
||||
final Library library = moduleLibrariesModel.createLibrary(null, kind);
|
||||
final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
|
||||
private static @NotNull Library createLibraryFromRoots(@NotNull List<OrderRoot> roots,
|
||||
@Nullable LibraryType libraryType,
|
||||
@NotNull LibraryTable.ModifiableModel moduleLibrariesModel,
|
||||
@Nullable Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
|
||||
Library library = moduleLibrariesModel.createLibrary(null, kind);
|
||||
LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
|
||||
if (defaultPropertiesFactory != null) {
|
||||
libModel.setProperties(defaultPropertiesFactory.fun(libraryType));
|
||||
}
|
||||
@@ -103,26 +88,28 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
return library;
|
||||
}
|
||||
|
||||
private static List<OrderRoot> filterAlreadyAdded(final List<? extends OrderRoot> roots, LibraryTable.ModifiableModel moduleLibrariesModel) {
|
||||
@SuppressWarnings("SSBasedInspection")
|
||||
private static @NotNull List<OrderRoot> filterAlreadyAdded(List<OrderRoot> roots, LibraryTable.ModifiableModel moduleLibrariesModel) {
|
||||
if (roots == null || roots.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<OrderRoot> result = new ArrayList<>();
|
||||
final Library[] libraries = moduleLibrariesModel.getLibraries();
|
||||
for (OrderRoot root : roots) {
|
||||
if (!ContainerUtil.exists(libraries, library -> contains(root.getFile(), library.getFiles(root.getType())))) {
|
||||
result.add(root);
|
||||
}
|
||||
Library[] libraries = moduleLibrariesModel.getLibraries();
|
||||
if (libraries.length == 0) {
|
||||
return roots;
|
||||
}
|
||||
return result;
|
||||
|
||||
return roots.stream()
|
||||
.filter(root -> {
|
||||
return Arrays.stream(libraries).noneMatch(library -> ArrayUtil.contains(root.getFile(), library.getFiles(root.getType())));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Library> chooseElements() {
|
||||
final FileChooserDescriptor chooserDescriptor;
|
||||
final List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>();
|
||||
public @NotNull List<Library> chooseElements() {
|
||||
FileChooserDescriptor chooserDescriptor;
|
||||
List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>();
|
||||
for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) {
|
||||
descriptors.add(Pair.create(componentDescriptor, componentDescriptor.createAttachFilesChooserDescriptor(null)));
|
||||
}
|
||||
@@ -154,9 +141,11 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
}
|
||||
chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule);
|
||||
|
||||
final Project project = myModule.getProject();
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir());
|
||||
if (files.length == 0) return Collections.emptyList();
|
||||
Project project = myModule.getProject();
|
||||
VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir());
|
||||
if (files.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<>();
|
||||
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
|
||||
@@ -180,33 +169,32 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@NotNull
|
||||
public static List<Library> createLibrariesFromRoots(List<? extends OrderRoot> chosenRoots, LibraryTable.ModifiableModel moduleLibrariesModel) {
|
||||
public static @NotNull List<Library> createLibrariesFromRoots(List<OrderRoot> chosenRoots, LibraryTable.ModifiableModel moduleLibrariesModel) {
|
||||
return createLibrariesFromRoots(chosenRoots, null, moduleLibrariesModel, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Library> createLibrariesFromRoots(@NotNull List<? extends OrderRoot> chosenRoots,
|
||||
@Nullable LibraryType libraryType,
|
||||
@NotNull LibraryTable.ModifiableModel moduleLibrariesModel,
|
||||
@Nullable Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
final List<OrderRoot> roots = filterAlreadyAdded(chosenRoots, moduleLibrariesModel);
|
||||
private static @NotNull List<Library> createLibrariesFromRoots(@NotNull List<OrderRoot> chosenRoots,
|
||||
@Nullable LibraryType libraryType,
|
||||
@NotNull LibraryTable.ModifiableModel moduleLibrariesModel,
|
||||
@Nullable Function<? super LibraryType, ? extends LibraryProperties> defaultPropertiesFactory) {
|
||||
List<OrderRoot> roots = filterAlreadyAdded(chosenRoots, moduleLibrariesModel);
|
||||
if (roots.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<Library> addedLibraries = new ArrayList<>();
|
||||
Map<VirtualFile, List<OrderRoot>> byFile = roots.stream().collect(Collectors.groupingBy(OrderRoot::getFile, LinkedHashMap::new, Collectors.toList()));
|
||||
Predicate<List<OrderRoot>> containsClasses = it -> it.stream().anyMatch(root -> root.getType().equals(OrderRootType.CLASSES));
|
||||
//noinspection SSBasedInspection
|
||||
if (byFile.values().stream().allMatch(containsClasses)) {
|
||||
List<Library> addedLibraries = new ArrayList<>();
|
||||
for (List<OrderRoot> rootsForFile : byFile.values()) {
|
||||
addedLibraries.add(createLibraryFromRoots(rootsForFile, libraryType, moduleLibrariesModel, defaultPropertiesFactory));
|
||||
}
|
||||
return addedLibraries;
|
||||
}
|
||||
else {
|
||||
addedLibraries.add(createLibraryFromRoots(roots, libraryType, moduleLibrariesModel, defaultPropertiesFactory));
|
||||
return List.of(createLibraryFromRoots(roots, libraryType, moduleLibrariesModel, defaultPropertiesFactory));
|
||||
}
|
||||
return addedLibraries;
|
||||
}
|
||||
|
||||
private static boolean acceptAll(FileChooserDescriptor descriptor, VirtualFile[] files) {
|
||||
|
||||
@@ -29,5 +29,6 @@
|
||||
<orderEntry type="library" name="Trove4j" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
|
||||
<orderEntry type="library" name="icu4j" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.compiler" />
|
||||
<orderEntry type="library" name="ASM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl.refactorings" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.diff.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -62,6 +62,7 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.copyright" />
|
||||
<orderEntry type="library" name="StreamEx" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.statistics" />
|
||||
|
||||
@@ -86,5 +86,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.lang" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit5Suites" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl.refactorings" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
@@ -24,7 +23,6 @@ import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.project.IntelliJProjectConfiguration;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.JavaModuleTestCase;
|
||||
@@ -33,7 +31,6 @@ import com.intellij.util.PathsList;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.util.JpsPathUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -94,11 +91,7 @@ public abstract class ModuleRootManagerTestCase extends JavaModuleTestCase {
|
||||
}
|
||||
|
||||
protected VirtualFile getJDomSources() {
|
||||
//todo[nik] download sources of JDOM library and locate the JAR via IntelliJProjectConfiguration instead
|
||||
String url = JpsPathUtil.getLibraryRootUrl(PathManagerEx.findFileUnderCommunityHome("lib/src/jdom.zip"));
|
||||
VirtualFile jar = VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
|
||||
assertNotNull(jar);
|
||||
return jar;
|
||||
return IntelliJProjectConfiguration.getSourceJarFromSingleJarProjectLibrary("fastutil-min");
|
||||
}
|
||||
|
||||
protected VirtualFile addSourceRoot(Module module, boolean testSource) throws IOException {
|
||||
|
||||
@@ -56,11 +56,11 @@ public class LibraryTest extends ModuleRootManagerTestCase {
|
||||
assertThat(serializeLibraries(myProject)).isEqualTo(
|
||||
"<library name=\"junit\">\n" +
|
||||
" <CLASSES>\n" +
|
||||
" <root url=\"file://$PROJECT_DIR$/jdom-2.0.6.jar\" />\n" +
|
||||
" <root url=\"file://$PROJECT_DIR$/intellij-deps-fastutil-8.5.8-11.jar\" />\n" +
|
||||
" </CLASSES>\n" +
|
||||
" <JAVADOC />\n" +
|
||||
" <SOURCES>\n" +
|
||||
" <root url=\"file://$PROJECT_DIR$/jdom.zip\" />\n" +
|
||||
" <root url=\"file://$PROJECT_DIR$/intellij-deps-fastutil-8.5.8-11-sources.jar\" />\n" +
|
||||
" </SOURCES>\n" +
|
||||
"</library>"
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" exported="" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.java.guiForms.rt" scope="PROVIDED" />
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.icons" />
|
||||
|
||||
@@ -18,5 +18,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -10,7 +10,7 @@
|
||||
<orderEntry type="module" module-name="intellij.java" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" exported="" />
|
||||
<orderEntry type="library" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler.impl" />
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<orderEntry type="module" module-name="intellij.java.compiler.instrumentationUtil.java8" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="intellij.java.aetherDependencyResolver" />
|
||||
<orderEntry type="library" name="ASM" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="NanoXML" level="project" />
|
||||
<orderEntry type="library" name="jgoodies-forms" level="project" />
|
||||
<orderEntry type="library" name="protobuf" level="project" />
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.jps.model;
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
@@ -34,7 +20,6 @@ import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jps.model.java.JpsJavaExtensionService.dependencies;
|
||||
|
||||
|
||||
public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
private JpsModule myModule;
|
||||
|
||||
@@ -58,20 +43,19 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
public void testLibrary() {
|
||||
JpsModuleRootModificationUtil.addDependency(myModule, createJDomLibrary());
|
||||
|
||||
assertClassRoots(dependencies(myModule), getRtJarJdk17(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().productionOnly().runtimeOnly(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule), getRtJarJdk17(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().productionOnly().runtimeOnly(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutLibraries(), getRtJarJdk17());
|
||||
assertSourceRoots(dependencies(myModule), getJDomSources());
|
||||
assertSourceRoots(dependencies(myModule), getFastUtilSources());
|
||||
}
|
||||
|
||||
private static String getJDomSources() {
|
||||
//todo[nik] download sources of JDOM library and locate the JAR via IntelliJProjectConfiguration instead
|
||||
return JpsPathUtil.getLibraryRootUrl(PathManagerEx.findFileUnderCommunityHome("lib/src/jdom.zip"));
|
||||
private static String getFastUtilSources() {
|
||||
return IntelliJProjectConfiguration.getProjectLibrary("fastutil-min").getSourcesUrls().get(0);
|
||||
}
|
||||
|
||||
private static String getJDomJar() {
|
||||
return getJarUrlFromProjectLib("JDOM");
|
||||
private static String getFastUtilJar() {
|
||||
return getJarUrlFromProjectLib("fastutil-min");
|
||||
}
|
||||
|
||||
private static String getAsmJar() {
|
||||
@@ -96,8 +80,8 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
|
||||
private JpsLibrary createJDomLibrary() {
|
||||
JpsLibrary library = addLibrary("jdom");
|
||||
library.addRoot(getJDomJar(), JpsOrderRootType.COMPILED);
|
||||
library.addRoot(getJDomSources(), JpsOrderRootType.SOURCES);
|
||||
library.addRoot(getFastUtilJar(), JpsOrderRootType.COMPILED);
|
||||
library.addRoot(getFastUtilSources(), JpsOrderRootType.SOURCES);
|
||||
return library;
|
||||
}
|
||||
|
||||
@@ -127,7 +111,7 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
getJavaService().getOrCreateDependencyExtension(dependency).setScope(JpsJavaDependencyScope.RUNTIME);
|
||||
JpsModuleRootModificationUtil.addDependency(myModule, createJDomLibrary(), JpsJavaDependencyScope.RUNTIME, false);
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().exportedOnly());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().compileOnly());
|
||||
}
|
||||
@@ -147,24 +131,24 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
final String testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), testOutput, output, depTestOutput, depOutput);
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), testOutput, output, depTestOutput, depOutput, getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), testOutput, output, depTestOutput, depOutput, getFastUtilJar());
|
||||
assertSourceRoots(dependencies(myModule), srcRoot, testRoot, depSrcRoot, depTestRoot);
|
||||
assertSourceRoots(dependencies(myModule).recursively(), srcRoot, testRoot, depSrcRoot, depTestRoot, getJDomSources());
|
||||
assertSourceRoots(dependencies(myModule).recursively(), srcRoot, testRoot, depSrcRoot, depTestRoot, getFastUtilSources());
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively(), getJDomJar());
|
||||
assertSourceRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively(), getJDomSources());
|
||||
assertEnumeratorRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively().classes(), getJDomJar());
|
||||
assertEnumeratorRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively().sources(), getJDomSources());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively(), getFastUtilJar());
|
||||
assertSourceRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively(), getFastUtilSources());
|
||||
assertEnumeratorRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively().classes(), getFastUtilJar());
|
||||
assertEnumeratorRoots(dependencies(myModule).withoutSdk().withoutModuleSourceEntries().recursively().sources(), getFastUtilSources());
|
||||
|
||||
assertEnumeratorRoots(dependencies(myModule).withoutSdk().recursively().classes().withoutSelfModuleOutput(),
|
||||
output, depTestOutput, depOutput, getJDomJar());
|
||||
output, depTestOutput, depOutput, getFastUtilJar());
|
||||
assertEnumeratorRoots(dependencies(myModule).productionOnly().withoutSdk().recursively().classes().withoutSelfModuleOutput(),
|
||||
depOutput, getJDomJar());
|
||||
depOutput, getFastUtilJar());
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().withoutDepModules().withoutModuleSourceEntries().recursively(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().withoutDepModules().withoutModuleSourceEntries().recursively(), getFastUtilJar());
|
||||
assertEnumeratorRoots(
|
||||
dependencies(myModule).productionOnly().withoutSdk().withoutDepModules().withoutModuleSourceEntries().recursively().classes(),
|
||||
getJDomJar());
|
||||
getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().withoutDepModules().withoutModuleSourceEntries());
|
||||
assertEnumeratorRoots(dependencies(myModule).productionOnly().withoutModuleSourceEntries().withoutSdk().withoutDepModules().classes());
|
||||
}
|
||||
@@ -175,12 +159,12 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
JpsModuleRootModificationUtil.addDependency(myModule, dep, JpsJavaDependencyScope.TEST, true);
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().exportedOnly().recursively(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().exportedOnly().recursively(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().productionOnly().recursively());
|
||||
|
||||
assertClassRoots(dependencies(myProject).withoutSdk(), getJDomJar());
|
||||
assertClassRoots(dependencies(myProject).withoutSdk().productionOnly(), getJDomJar());
|
||||
assertClassRoots(dependencies(myProject).withoutSdk(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myProject).withoutSdk().productionOnly(), getFastUtilJar());
|
||||
}
|
||||
|
||||
public void testNotExportedLibrary() {
|
||||
@@ -190,7 +174,7 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
JpsModuleRootModificationUtil.addDependency(myModule, dep, JpsJavaDependencyScope.COMPILE, false);
|
||||
|
||||
assertClassRoots(dependencies(myModule).withoutSdk(), getAsmJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), getAsmJar(), getJDomJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursively(), getAsmJar(), getFastUtilJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().recursivelyExportedOnly(), getAsmJar());
|
||||
assertClassRoots(dependencies(myModule).withoutSdk().exportedOnly().recursively());
|
||||
}
|
||||
@@ -228,8 +212,8 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
final String output = setModuleOutput(myModule, false);
|
||||
final String testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
assertClassRoots(dependencies(myProject).withoutSdk(), testOutput, output, getJDomJar());
|
||||
assertSourceRoots(dependencies(myProject).withoutSdk(), srcRoot, testRoot, getJDomSources());
|
||||
assertClassRoots(dependencies(myProject).withoutSdk(), testOutput, output, getFastUtilJar());
|
||||
assertSourceRoots(dependencies(myProject).withoutSdk(), srcRoot, testRoot, getFastUtilSources());
|
||||
}
|
||||
|
||||
public void testModules() {
|
||||
@@ -241,9 +225,9 @@ public class JpsDependenciesEnumeratorTest extends JpsJavaModelTestCase {
|
||||
final String testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
assertClassRoots(getJavaService().enumerateDependencies(Collections.singletonList(myModule)).withoutSdk(),
|
||||
testOutput, output, getJDomJar());
|
||||
testOutput, output, getFastUtilJar());
|
||||
assertSourceRoots(getJavaService().enumerateDependencies(Collections.singletonList(myModule)).withoutSdk(),
|
||||
srcRoot, testRoot, getJDomSources());
|
||||
srcRoot, testRoot, getFastUtilSources());
|
||||
}
|
||||
|
||||
private String setModuleOutput(JpsModule module, boolean tests) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.model" />
|
||||
<orderEntry type="library" exported="" name="JDOM" level="project" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -10,5 +10,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.model.serialization" />
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.model.tests" exported="" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testExtensions" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -17,5 +17,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl.refactorings" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
lib/src/jdom.zip
BIN
lib/src/jdom.zip
Binary file not shown.
@@ -9,7 +9,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.codeStyle" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="library" name="StreamEx" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -418,9 +418,6 @@ final class CommunityLibraryLicenses {
|
||||
url: "https://www.jcip.net", licenseUrl: "https://creativecommons.org/licenses/by/2.5"),
|
||||
new LibraryLicense(name: "JCodings", libraryName: "joni", transitiveDependency: true, version: "1.0.55",
|
||||
url: "https://github.com/jruby/jcodings", licenseUrl: "https://github.com/jruby/jcodings/blob/master/pom.xml").mit(),
|
||||
new LibraryLicense(name: "JDOM (JetBrains's fork)", libraryName: "JDOM", license: "modified Apache",
|
||||
url: "https://github.com/JetBrains/intellij-deps-jdom",
|
||||
licenseUrl: "https://github.com/JetBrains/intellij-deps-jdom/blob/master/LICENSE.txt"),
|
||||
new LibraryLicense(name: "JediTerm", libraryName: "jediterm-pty", license: "LGPL 3",
|
||||
url: "https://github.com/JetBrains/jediterm",
|
||||
licenseUrl: "https://github.com/JetBrains/jediterm/blob/master/LICENSE-LGPLv3.txt"),
|
||||
|
||||
@@ -215,6 +215,7 @@ final class PlatformModules {
|
||||
"intellij.platform.util.base",
|
||||
"intellij.platform.util.diff",
|
||||
"intellij.platform.util.xmlDom",
|
||||
"intellij.platform.util.jdom",
|
||||
"intellij.platform.extensions",
|
||||
"intellij.platform.tracing.rt",
|
||||
"intellij.platform.boot",
|
||||
@@ -293,10 +294,7 @@ final class PlatformModules {
|
||||
}
|
||||
}
|
||||
|
||||
layout.projectLibrariesToUnpack.putValues(UTIL_JAR, List.of(
|
||||
"JDOM",
|
||||
"Trove4j",
|
||||
))
|
||||
layout.projectLibrariesToUnpack.putValues(UTIL_JAR, List.of("Trove4j"))
|
||||
|
||||
for (ProjectLibraryData item in additionalProjectLevelLibraries) {
|
||||
String name = item.libraryName
|
||||
|
||||
@@ -263,7 +263,7 @@ final class WindowsDistributionBuilder extends OsSpecificDistributionBuilder {
|
||||
arg(value: outputPath.toString())
|
||||
classpath {
|
||||
pathelement(location: "$communityHome/build/lib/launcher-generator.jar")
|
||||
["Guava", "JDOM", "commons-imaging"].each {
|
||||
["Guava", "commons-imaging"].each {
|
||||
buildContext.project.libraryCollection.findLibrary(it).getFiles(JpsOrderRootType.COMPILED).each {
|
||||
pathelement(location: it.absolutePath)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -27,5 +27,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="library" name="aalto-xml" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.xmlDom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -18,6 +18,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.statistics" scope="TEST" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="library" name="Trove4j" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
<component name="TestModuleProperties" production-module="intellij.platform.configurationStore.impl" />
|
||||
</module>
|
||||
@@ -18,7 +18,7 @@ import com.intellij.testFramework.*
|
||||
import com.intellij.testFramework.rules.InMemoryFsRule
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.io.*
|
||||
import com.intellij.util.toByteArray
|
||||
import com.intellij.util.toBufferExposingByteArray
|
||||
import com.intellij.util.xmlb.annotations.Tag
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
@@ -144,7 +144,7 @@ internal class SchemeManagerTest {
|
||||
}
|
||||
|
||||
fun TestScheme.save(file: Path) {
|
||||
file.write(serialize(this)!!.toByteArray())
|
||||
file.write(serialize(this)!!.toBufferExposingByteArray().toByteArray())
|
||||
}
|
||||
|
||||
@Test fun `different extensions - old, new`() {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" exported="" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.xmlDom" />
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core" exported="" />
|
||||
<orderEntry type="library" exported="" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.classLoader" />
|
||||
<orderEntry type="library" name="aalto-xml" level="project" />
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="library" name="bouncy-castle-provider" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testExtensions" scope="TEST" />
|
||||
<orderEntry type="library" name="snakeyaml" level="project" />
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" exported="" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -13,7 +13,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="module" module-name="intellij.platform.indexing" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="jetbrains-annotations" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
|
||||
@@ -17,5 +17,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -25,6 +25,7 @@
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" name="jediterm-typeahead" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.wsl.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -13,7 +13,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.lang" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem.rt" exported="" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.objectSerializer" />
|
||||
<orderEntry type="module" module-name="intellij.platform.objectSerializer.annotations" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
|
||||
@@ -27,5 +27,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
|
||||
<orderEntry type="library" name="Velocity" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -28,5 +28,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem.testFramework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis.impl" />
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ex" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="kotlinx-serialization-core" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-serialization-json" level="project" />
|
||||
</component>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
</component>
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
|
||||
<orderEntry type="library" name="StreamEx" level="project" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.vcs.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" exported="" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" scope="TEST" name="jmock" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
|
||||
|
||||
@@ -120,13 +120,14 @@ class InlayHintsSettings : PersistentStateComponent<InlayHintsSettings.State> {
|
||||
val element = myState.settingsMapElement.clone()
|
||||
element.removeChild(fullId)
|
||||
val serialized = serialize(value)
|
||||
if (serialized != null) {
|
||||
if (serialized == null) {
|
||||
myState.settingsMapElement = element
|
||||
}
|
||||
else {
|
||||
val storeElement = Element(fullId)
|
||||
val wrappedSettingsElement = storeElement.addContent(serialized)
|
||||
myState.settingsMapElement = element.addContent(wrappedSettingsElement)
|
||||
element.sortAttributes(compareBy { it.name })
|
||||
} else {
|
||||
myState.settingsMapElement = element
|
||||
}
|
||||
}
|
||||
listener.settingsChanged()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.execution" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.classLoader" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="module" module-name="intellij.platform.codeStyle" />
|
||||
|
||||
@@ -56,5 +56,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.bootstrap" />
|
||||
<orderEntry type="module" module-name="intellij.platform.tracing.rt" />
|
||||
<orderEntry type="module" module-name="intellij.platform.rd.community" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -42,5 +42,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.jps" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,25 +1,11 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
*/
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.roots.libraries.ui;
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class OrderRoot {
|
||||
public final class OrderRoot {
|
||||
private final VirtualFile myFile;
|
||||
private final OrderRootType myType;
|
||||
private final boolean myJarDirectory;
|
||||
@@ -34,13 +20,11 @@ public class OrderRoot {
|
||||
myJarDirectory = jarDirectory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile getFile() {
|
||||
public @NotNull VirtualFile getFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OrderRootType getType() {
|
||||
public @NotNull OrderRootType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,5 +18,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -13,7 +13,7 @@
|
||||
<orderEntry type="library" name="ion" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ex" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<orderEntry type="library" name="jna" level="project" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ex" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
|
||||
@@ -142,5 +142,6 @@
|
||||
<orderEntry type="library" name="kotlinx-serialization-json" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-serialization-core" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -67,5 +67,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.util.zip" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.rt.java8" />
|
||||
<orderEntry type="module" module-name="intellij.platform.wsl.impl" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.model" exported="" />
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="library" name="Kryo" level="project" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
@file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet")
|
||||
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
@@ -9,12 +11,10 @@ import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.PathUtilRt
|
||||
import com.intellij.util.isEmpty
|
||||
import com.intellij.util.text.UniqueNameGenerator
|
||||
import com.intellij.util.toByteArray
|
||||
import com.intellij.util.toBufferExposingByteArray
|
||||
import org.jdom.Element
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.collections.LinkedHashMap
|
||||
import kotlin.concurrent.read
|
||||
import kotlin.concurrent.write
|
||||
|
||||
@@ -92,7 +92,7 @@ class SchemeManagerIprProvider(private val subStateTagName: String, private val
|
||||
continue
|
||||
}
|
||||
|
||||
nameToData.put(nameGenerator.generateUniqueName("${FileUtil.sanitizeFileName(name, false)}.xml"), child.toByteArray())
|
||||
nameToData.put(nameGenerator.generateUniqueName("${FileUtil.sanitizeFileName(name, false)}.xml"), child.toBufferExposingByteArray().toByteArray())
|
||||
}
|
||||
|
||||
lock.write {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.extensions" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<orderEntry type="library" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ex" exported="" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit5" level="project" />
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.remoteServers.agent.rt" exported="" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.execution" />
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -18,5 +18,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.smRunner" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.junit" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java.tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.netty" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -13,7 +13,7 @@
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="gson" level="project" />
|
||||
<orderEntry type="library" name="jetbrains-annotations" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.statistics.uploader" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.concurrency" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.xml.impl" />
|
||||
<orderEntry type="library" name="org.codehaus.groovy:groovy" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide" />
|
||||
|
||||
@@ -14,5 +14,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.structuralSearch" />
|
||||
<orderEntry type="module" module-name="intellij.java.i18n" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -10,6 +10,6 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide" />
|
||||
<orderEntry type="module" module-name="intellij.platform.vcs" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -20,5 +20,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.debugger" />
|
||||
<orderEntry type="module" module-name="intellij.platform.vcs.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,7 @@
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" exported="" name="memoryfilesystem" level="project" />
|
||||
<orderEntry type="library" exported="" name="assertJ" level="project" />
|
||||
<orderEntry type="library" name="snakeyaml" level="project" />
|
||||
|
||||
@@ -38,5 +38,6 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="JUnit5Launcher" level="project" />
|
||||
<orderEntry type="library" exported="" scope="PROVIDED" name="JUnit5" level="project" />
|
||||
<orderEntry type="library" exported="" scope="PROVIDED" name="JUnit5Params" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,13 +1,12 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.project
|
||||
|
||||
import com.intellij.application.options.PathMacrosImpl
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.SystemProperties
|
||||
import com.intellij.util.io.systemIndependentPath
|
||||
import org.jetbrains.jps.model.JpsProject
|
||||
@@ -17,31 +16,35 @@ import org.jetbrains.jps.model.library.JpsLibraryCollection
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationManager
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
/**
|
||||
* Provides access to IntelliJ project configuration so the tests from IntelliJ project sources may locate project and module libraries without
|
||||
* hardcoding paths to their JARs.
|
||||
* Provides access to IntelliJ project configuration so the tests from IntelliJ project sources may locate project and module libraries
|
||||
* without hard-coding paths to their JARs.
|
||||
*/
|
||||
class IntelliJProjectConfiguration {
|
||||
private val projectHome = PathManager.getHomePath()
|
||||
private val projectLibraries: Map<String, LibraryRoots>
|
||||
private val moduleLibraries: Map<String, Map<String, LibraryRoots>>
|
||||
|
||||
private val remoteRepositoryDescriptions : List<JpsRemoteRepositoryDescription>
|
||||
private val remoteRepositoryDescriptions: List<JpsRemoteRepositoryDescription>
|
||||
|
||||
init {
|
||||
val project = loadIntelliJProject(projectHome)
|
||||
fun extractLibrariesRoots(collection: JpsLibraryCollection) = collection.libraries.associateBy({ it.name }, {
|
||||
LibraryRoots(SmartList(it.getFiles(JpsOrderRootType.COMPILED)), SmartList(it.getFiles(JpsOrderRootType.SOURCES)))
|
||||
})
|
||||
fun extractLibrariesRoots(collection: JpsLibraryCollection): Map<@NlsSafe String, LibraryRoots> {
|
||||
return collection.libraries.associateBy(keySelector = { it.name }, valueTransform = {
|
||||
LibraryRoots(
|
||||
classes = java.util.List.copyOf(it.getFiles(JpsOrderRootType.COMPILED)),
|
||||
sources = java.util.List.copyOf(it.getFiles(JpsOrderRootType.SOURCES)),
|
||||
)
|
||||
})
|
||||
}
|
||||
projectLibraries = extractLibrariesRoots(project.libraryCollection)
|
||||
moduleLibraries = project.modules.associateBy({it.name}, {
|
||||
val libraries = extractLibrariesRoots(it.libraryCollection)
|
||||
if (libraries.isNotEmpty()) libraries else emptyMap()
|
||||
libraries.ifEmpty { emptyMap() }
|
||||
})
|
||||
|
||||
remoteRepositoryDescriptions = JpsRemoteRepositoryService.getInstance().getRemoteRepositoriesConfiguration(project)!!.repositories
|
||||
@@ -81,10 +84,19 @@ class IntelliJProjectConfiguration {
|
||||
|
||||
@JvmStatic
|
||||
fun getJarFromSingleJarProjectLibrary(projectLibraryName: String): VirtualFile {
|
||||
val jarUrl = UsefulTestCase.assertOneElement(getProjectLibraryClassesRootUrls(projectLibraryName))
|
||||
val jarRoot = VirtualFileManager.getInstance().refreshAndFindFileByUrl(jarUrl)
|
||||
Assert.assertNotNull(jarRoot)
|
||||
return jarRoot!!
|
||||
return getVirtualFile(getProjectLibrary(projectLibraryName))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getVirtualFile(lib: LibraryRoots): VirtualFile {
|
||||
val url = lib.classesUrls.single()
|
||||
return VirtualFileManager.getInstance().refreshAndFindFileByUrl(url)
|
||||
?: throw IllegalStateException("Cannot find virtual file by $url (nio file exists: ${lib.classes.single().exists()})")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getJarPathFromSingleJarProjectLibrary(libName: String): Path {
|
||||
return getProjectLibrary(libName).classes.single().toPath()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -17,5 +17,6 @@
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -10,7 +10,7 @@
|
||||
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="library" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="jcip" level="project" />
|
||||
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
|
||||
<orderEntry type="library" name="fastutil-min" level="project" />
|
||||
|
||||
@@ -83,7 +83,7 @@ private val cachedSpecialSaxBuilder = ThreadLocal<SoftReference<SAXBuilder>>()
|
||||
|
||||
private fun getSpecialSaxBuilder(): SAXBuilder {
|
||||
val reference = cachedSpecialSaxBuilder.get()
|
||||
var saxBuilder = SoftReference.dereference<SAXBuilder>(reference)
|
||||
var saxBuilder = SoftReference.dereference(reference)
|
||||
if (saxBuilder == null) {
|
||||
saxBuilder = object : SAXBuilder() {
|
||||
override fun configureParser(parser: XMLReader, contentHandler: SAXHandler?) {
|
||||
@@ -95,7 +95,7 @@ private fun getSpecialSaxBuilder(): SAXBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
saxBuilder.entityResolver = EntityResolver { _, _ -> InputSource(CharArrayReader(ArrayUtilRt.EMPTY_CHAR_ARRAY)) }
|
||||
saxBuilder.setEntityResolver(EntityResolver { _, _ -> InputSource(CharArrayReader(ArrayUtilRt.EMPTY_CHAR_ARRAY)) })
|
||||
cachedSpecialSaxBuilder.set(SoftReference(saxBuilder))
|
||||
}
|
||||
return saxBuilder
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="library" name="Log4J" level="project" />
|
||||
<orderEntry type="library" name="Trove4j" level="project" />
|
||||
<orderEntry type="library" exported="" name="jetbrains-annotations" level="project" />
|
||||
|
||||
12
platform/util/jdom/intellij.platform.util.jdom.iml
Normal file
12
platform/util/jdom/intellij.platform.util.jdom.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Jaxen" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
694
platform/util/jdom/src/org/jdom/Attribute.java
Normal file
694
platform/util/jdom/src/org/jdom/Attribute.java
Normal file
@@ -0,0 +1,694 @@
|
||||
/*--
|
||||
|
||||
Copyright (C) 2000-2012 Jason Hunter & Brett McLaughlin.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer that follows
|
||||
these conditions in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. The name "JDOM" must not be used to endorse or promote products
|
||||
derived from this software without prior written permission. For
|
||||
written permission, please contact <request_AT_jdom_DOT_org>.
|
||||
|
||||
4. Products derived from this software may not be called "JDOM", nor
|
||||
may "JDOM" appear in their name, without prior written permission
|
||||
from the JDOM Project Management <request_AT_jdom_DOT_org>.
|
||||
|
||||
In addition, we request (but do not require) that you include in the
|
||||
end-user documentation provided with the redistribution and/or in the
|
||||
software itself an acknowledgement equivalent to the following:
|
||||
"This product includes software developed by the
|
||||
JDOM Project (http://www.jdom.org/)."
|
||||
Alternatively, the acknowledgment may be graphical using the logos
|
||||
available at http://www.jdom.org/images/logos.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the JDOM Project and was originally
|
||||
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
|
||||
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
|
||||
on the JDOM Project, please see <http://www.jdom.org/>.
|
||||
|
||||
*/
|
||||
|
||||
package org.jdom;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* An XML attribute. Methods allow the user to obtain the value of the attribute
|
||||
* as well as namespace and type information.
|
||||
* <p>
|
||||
* <strong>JDOM 1.x Compatibility Note:</strong><br>
|
||||
* The Attribute class in JDOM 1.x had a number of int Constants declared to
|
||||
* represent different Attribute Types. JDOM2 has introduced an AttributeType
|
||||
* enumeration instead. To facilitate compatibility and to simplify JDOM 1.x
|
||||
* migrations, the replacement AttributeType enums are referenced still using
|
||||
* the JDOM 1.x constant names. In JDOM 1.x these names referenced constant
|
||||
* int values. In JDOM2 these names reference Enum constants.
|
||||
*
|
||||
* @author Brett McLaughlin
|
||||
* @author Jason Hunter
|
||||
* @author Elliotte Rusty Harold
|
||||
* @author Wesley Biggs
|
||||
* @author Victor Toni
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
public class Attribute extends CloneBase implements NamespaceAware, Serializable, Cloneable {
|
||||
/**
|
||||
* JDOM 2.0.0 Serialization version. Attribute is simple
|
||||
*/
|
||||
private static final long serialVersionUID = 200L;
|
||||
|
||||
/**
|
||||
* The local name of the <code>Attribute</code>
|
||||
*/
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* The <code>{@link Namespace}</code> of the <code>Attribute</code>
|
||||
*/
|
||||
protected Namespace namespace;
|
||||
|
||||
/**
|
||||
* The value of the <code>Attribute</code>
|
||||
*/
|
||||
protected String value;
|
||||
|
||||
/**
|
||||
* The type of the <code>Attribute</code>
|
||||
*/
|
||||
protected AttributeType type = AttributeType.UNDECLARED;
|
||||
|
||||
/**
|
||||
* Specified attributes are part of the XML,
|
||||
* unspecified attributes are 'defaulted' from a DTD.
|
||||
*/
|
||||
protected boolean specified = true;
|
||||
|
||||
/**
|
||||
* The parent to which this Attribute belongs. Change it with
|
||||
* {@link #setParent(Element)}
|
||||
*/
|
||||
protected transient Element parent;
|
||||
|
||||
/**
|
||||
* Default, no-args constructor for implementations to use if needed.
|
||||
*/
|
||||
protected Attribute() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a new <code>Attribute</code> with the
|
||||
* specified (local) name and value, and in the provided
|
||||
* <code>{@link Namespace}</code>.
|
||||
*
|
||||
* @param name <code>String</code> name of <code>Attribute</code>.
|
||||
* @param value <code>String</code> value for new attribute.
|
||||
* @param namespace <code>Namespace</code> namespace for new attribute.
|
||||
* @throws IllegalNameException if the given name is illegal as an
|
||||
* attribute name or if is the new namespace is the default
|
||||
* namespace. Attributes cannot be in a default namespace.
|
||||
* @throws IllegalDataException if the given attribute value is
|
||||
* illegal character data (as determined by
|
||||
* {@link Verifier#checkCharacterData}).
|
||||
*/
|
||||
public Attribute(final String name, final String value, final Namespace namespace) {
|
||||
this(name, value, AttributeType.UNDECLARED, namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a new <code>Attribute</code> with the
|
||||
* specified (local) name, value, and type, and in the provided
|
||||
* <code>{@link Namespace}</code>.
|
||||
*
|
||||
* @param name <code>String</code> name of <code>Attribute</code>.
|
||||
* @param value <code>String</code> value for new attribute.
|
||||
* @param type <code>AttributeType</code> for new attribute.
|
||||
* @param namespace <code>Namespace</code> namespace for new attribute.
|
||||
* @throws IllegalNameException if the given name is illegal as an
|
||||
* attribute name or if is the new namespace is the default
|
||||
* namespace. Attributes cannot be in a default namespace.
|
||||
* @throws IllegalDataException if the given attribute value is
|
||||
* illegal character data (as determined by
|
||||
* {@link Verifier#checkCharacterData}) or
|
||||
* if the given attribute type is not one of the
|
||||
* supported types.
|
||||
*/
|
||||
public Attribute(final String name, final String value, final AttributeType type, final Namespace namespace) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
setAttributeType(type);
|
||||
setNamespace(namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a new <code>Attribute</code> with the
|
||||
* specified (local) name and value, and does not place
|
||||
* the attribute in a <code>{@link Namespace}</code>.
|
||||
* <p>
|
||||
* <b>Note</b>: This actually explicitly puts the
|
||||
* <code>Attribute</code> in the "empty" <code>Namespace</code>
|
||||
* (<code>{@link Namespace#NO_NAMESPACE}</code>).
|
||||
*
|
||||
* @param name <code>String</code> name of <code>Attribute</code>.
|
||||
* @param value <code>String</code> value for new attribute.
|
||||
* @throws IllegalNameException if the given name is illegal as an
|
||||
* attribute name.
|
||||
* @throws IllegalDataException if the given attribute value is
|
||||
* illegal character data (as determined by
|
||||
* {@link Verifier#checkCharacterData}).
|
||||
*/
|
||||
public Attribute(final String name, final String value) {
|
||||
this(name, value, AttributeType.UNDECLARED, Namespace.NO_NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a new <code>Attribute</code> with the
|
||||
* specified (local) name, value and type, and does not place
|
||||
* the attribute in a <code>{@link Namespace}</code>.
|
||||
* <p>
|
||||
* <b>Note</b>: This actually explicitly puts the
|
||||
* <code>Attribute</code> in the "empty" <code>Namespace</code>
|
||||
* (<code>{@link Namespace#NO_NAMESPACE}</code>).
|
||||
*
|
||||
* @param name <code>String</code> name of <code>Attribute</code>.
|
||||
* @param value <code>String</code> value for new attribute.
|
||||
* @param type <code>AttributeType</code> for new attribute.
|
||||
* @throws IllegalNameException if the given name is illegal as an
|
||||
* attribute name.
|
||||
* @throws IllegalDataException if the given attribute value is
|
||||
* illegal character data (as determined by
|
||||
* {@link Verifier#checkCharacterData}) or
|
||||
* if the given attribute type is not one of the
|
||||
* supported types.
|
||||
*/
|
||||
public Attribute(final String name, final String value, final AttributeType type) {
|
||||
this(name, value, type, Namespace.NO_NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return the parent of this <code>Attribute</code>.
|
||||
* If there is no parent, then this returns <code>null</code>.
|
||||
* Use return-type covariance to override Content's getParent() method
|
||||
* to return an Element, not just a Parent
|
||||
*
|
||||
* @return parent of this <code>Attribute</code>
|
||||
*/
|
||||
public Element getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this Attribute's Document.
|
||||
*
|
||||
* @return The document to which this Attribute is associated, may be null.
|
||||
*/
|
||||
public Document getDocument() {
|
||||
return parent == null ? null : parent.getDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* This will retrieve the local name of the
|
||||
* <code>Attribute</code>. For any XML attribute
|
||||
* which appears as
|
||||
* <code>[namespacePrefix]:[attributeName]</code>,
|
||||
* the local name of the attribute would be
|
||||
* <code>[attributeName]</code>. When the attribute
|
||||
* has no namespace, the local name is simply the attribute
|
||||
* name.
|
||||
* <p>
|
||||
* To obtain the namespace prefix for this
|
||||
* attribute, the
|
||||
* <code>{@link #getNamespacePrefix()}</code>
|
||||
* method should be used.
|
||||
*
|
||||
* @return <code>String</code> - name of this attribute,
|
||||
* without any namespace prefix.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets the local name of the <code>Attribute</code>.
|
||||
*
|
||||
* @param name the new local name to set
|
||||
* @return <code>Attribute</code> - the attribute modified.
|
||||
* @throws IllegalNameException if the given name is illegal as an
|
||||
* attribute name.
|
||||
*/
|
||||
public Attribute setName(final String name) {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"Can not set a null name for an Attribute.");
|
||||
}
|
||||
final String reason = Verifier.checkAttributeName(name);
|
||||
if (reason != null) {
|
||||
throw new IllegalNameException(name, "attribute", reason);
|
||||
}
|
||||
this.name = name;
|
||||
specified = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will retrieve the qualified name of the <code>Attribute</code>.
|
||||
* For any XML attribute whose name is
|
||||
* <code>[namespacePrefix]:[elementName]</code>,
|
||||
* the qualified name of the attribute would be
|
||||
* everything (both namespace prefix and
|
||||
* element name). When the attribute has no
|
||||
* namespace, the qualified name is simply the attribute's
|
||||
* local name.
|
||||
* <p>
|
||||
* To obtain the local name of the attribute, the
|
||||
* <code>{@link #getName()}</code> method should be used.
|
||||
* <p>
|
||||
* To obtain the namespace prefix for this attribute,
|
||||
* the <code>{@link #getNamespacePrefix()}</code>
|
||||
* method should be used.
|
||||
*
|
||||
* @return <code>String</code> - full name for this element.
|
||||
*/
|
||||
public String getQualifiedName() {
|
||||
// Note: Any changes here should be reflected in
|
||||
// XMLOutputter.printQualifiedName()
|
||||
final String prefix = namespace.getPrefix();
|
||||
|
||||
// no prefix found
|
||||
if ("".equals(prefix)) {
|
||||
return getName();
|
||||
}
|
||||
return prefix +
|
||||
':' +
|
||||
getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* This will retrieve the namespace prefix of the
|
||||
* <code>Attribute</code>. For any XML attribute
|
||||
* which appears as
|
||||
* <code>[namespacePrefix]:[attributeName]</code>,
|
||||
* the namespace prefix of the attribute would be
|
||||
* <code>[namespacePrefix]</code>. When the attribute
|
||||
* has no namespace, an empty <code>String</code> is returned.
|
||||
*
|
||||
* @return <code>String</code> - namespace prefix of this
|
||||
* attribute.
|
||||
*/
|
||||
public String getNamespacePrefix() {
|
||||
return namespace.getPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the URI mapped to this <code>Attribute</code>'s
|
||||
* prefix. If no mapping is found, an empty <code>String</code> is
|
||||
* returned.
|
||||
*
|
||||
* @return <code>String</code> - namespace URI for this <code>Attribute</code>.
|
||||
*/
|
||||
public String getNamespaceURI() {
|
||||
return namespace.getURI();
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return this <code>Attribute</code>'s
|
||||
* <code>{@link Namespace}</code>.
|
||||
*
|
||||
* @return <code>Namespace</code> - Namespace object for this <code>Attribute</code>
|
||||
*/
|
||||
public Namespace getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets this <code>Attribute</code>'s <code>{@link Namespace}</code>.
|
||||
* If the provided namespace is null, the attribute will have no namespace.
|
||||
* The namespace must have a prefix.
|
||||
*
|
||||
* @param namespace the new namespace
|
||||
* @return <code>Element</code> - the element modified.
|
||||
* @throws IllegalNameException if the new namespace is the default
|
||||
* namespace. Attributes cannot be in a default namespace.
|
||||
*/
|
||||
public Attribute setNamespace(Namespace namespace) {
|
||||
if (namespace == null) {
|
||||
namespace = Namespace.NO_NAMESPACE;
|
||||
}
|
||||
|
||||
// Verify the attribute isn't trying to be in a default namespace
|
||||
// Attributes can't be in a default namespace
|
||||
if (namespace != Namespace.NO_NAMESPACE &&
|
||||
"".equals(namespace.getPrefix())) {
|
||||
throw new IllegalNameException("", "attribute namespace",
|
||||
"An attribute namespace without a prefix can only be the " +
|
||||
"NO_NAMESPACE namespace");
|
||||
}
|
||||
this.namespace = namespace;
|
||||
specified = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return the actual textual value of this
|
||||
* <code>Attribute</code>. This will include all text
|
||||
* within the quotation marks.
|
||||
*
|
||||
* @return <code>String</code> - value for this attribute.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the value of the <code>Attribute</code>.
|
||||
*
|
||||
* @param value <code>String</code> value for the attribute.
|
||||
* @return <code>Attribute</code> - this Attribute modified.
|
||||
* @throws IllegalDataException if the given attribute value is
|
||||
* illegal character data (as determined by
|
||||
* {@link Verifier#checkCharacterData}).
|
||||
*/
|
||||
public Attribute setValue(final String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException(
|
||||
"Can not set a null value for an Attribute");
|
||||
}
|
||||
final String reason = Verifier.checkCharacterData(value);
|
||||
if (reason != null) {
|
||||
throw new IllegalDataException(value, "attribute", reason);
|
||||
}
|
||||
this.value = value;
|
||||
specified = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return the declared type of this <code>Attribute</code>.
|
||||
*
|
||||
* @return <code>AttributeType</code> - type for this attribute.
|
||||
*/
|
||||
public AttributeType getAttributeType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the type of the <code>Attribute</code>.
|
||||
*
|
||||
* @param type <code>int</code> type for the attribute.
|
||||
* @return <code>Attribute</code> - this Attribute modified.
|
||||
* @throws IllegalDataException if the given attribute type is
|
||||
* not one of the supported types.
|
||||
*/
|
||||
public Attribute setAttributeType(final AttributeType type) {
|
||||
this.type = type == null ? AttributeType.UNDECLARED : type;
|
||||
specified = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 'specified' flag. True values indicate this attribute
|
||||
* was part of an XML document, false indicates it was defaulted
|
||||
* from a DTD.
|
||||
*
|
||||
* @return the specified flag.
|
||||
* @since JDOM2
|
||||
*/
|
||||
public boolean isSpecified() {
|
||||
return specified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the specified flag to the given value.
|
||||
*
|
||||
* @param specified The value to set the specified flag to.
|
||||
* @since JDOM2
|
||||
*/
|
||||
public void setSpecified(boolean specified) {
|
||||
this.specified = specified;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a <code>String</code> representation of the
|
||||
* <code>Attribute</code>, suitable for debugging.
|
||||
*
|
||||
* @return <code>String</code> - information about the
|
||||
* <code>Attribute</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[Attribute: " +
|
||||
getQualifiedName() +
|
||||
"=\"" +
|
||||
value +
|
||||
"\"" +
|
||||
"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute clone() {
|
||||
final Attribute clone = (Attribute)super.clone();
|
||||
clone.parent = null;
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach this Attribute from its parent.
|
||||
*
|
||||
* @return this Attribute (detached).
|
||||
*/
|
||||
public Attribute detach() {
|
||||
if (parent != null) {
|
||||
parent.removeAttribute(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this Attribute's parent. This is not public!
|
||||
*
|
||||
* @param parent The parent to set
|
||||
* @return this Attribute (state may be indeterminate depending on whether
|
||||
* this has been included in the Element's list yet).
|
||||
*/
|
||||
protected Attribute setParent(Element parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Convenience Methods below here
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* This gets the value of the attribute, in
|
||||
* <code>int</code> form, and if no conversion
|
||||
* can occur, throws a
|
||||
* <code>{@link DataConversionException}</code>
|
||||
*
|
||||
* @return <code>int</code> value of attribute.
|
||||
* @throws DataConversionException when conversion fails.
|
||||
*/
|
||||
public int getIntValue() throws DataConversionException {
|
||||
try {
|
||||
return Integer.parseInt(value.trim());
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
throw new DataConversionException(name, "int");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the value of the attribute, in
|
||||
* <code>long</code> form, and if no conversion
|
||||
* can occur, throws a
|
||||
* <code>{@link DataConversionException}</code>
|
||||
*
|
||||
* @return <code>long</code> value of attribute.
|
||||
* @throws DataConversionException when conversion fails.
|
||||
*/
|
||||
public long getLongValue() throws DataConversionException {
|
||||
try {
|
||||
return Long.parseLong(value.trim());
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
throw new DataConversionException(name, "long");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the value of the attribute, in
|
||||
* <code>float</code> form, and if no conversion
|
||||
* can occur, throws a
|
||||
* <code>{@link DataConversionException}</code>
|
||||
*
|
||||
* @return <code>float</code> value of attribute.
|
||||
* @throws DataConversionException when conversion fails.
|
||||
*/
|
||||
public float getFloatValue() throws DataConversionException {
|
||||
try {
|
||||
// Avoid Float.parseFloat() to support JDK 1.1
|
||||
return Float.valueOf(value.trim()).floatValue();
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
throw new DataConversionException(name, "float");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the value of the attribute, in
|
||||
* <code>double</code> form, and if no conversion
|
||||
* can occur, throws a
|
||||
* <code>{@link DataConversionException}</code>
|
||||
*
|
||||
* @return <code>double</code> value of attribute.
|
||||
* @throws DataConversionException when conversion fails.
|
||||
*/
|
||||
public double getDoubleValue() throws DataConversionException {
|
||||
try {
|
||||
// Avoid Double.parseDouble() to support JDK 1.1
|
||||
return Double.valueOf(value.trim()).doubleValue();
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
// Specially handle INF and -INF that Double.valueOf doesn't do
|
||||
String v = value.trim();
|
||||
if ("INF".equals(v)) {
|
||||
return Double.POSITIVE_INFINITY;
|
||||
}
|
||||
if ("-INF".equals(v)) {
|
||||
return Double.NEGATIVE_INFINITY;
|
||||
}
|
||||
throw new DataConversionException(name, "double");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the effective boolean value of the attribute, or throws a
|
||||
* <code>{@link DataConversionException}</code> if a conversion can't be
|
||||
* performed. True values are: "true", "on", "1", and "yes". False
|
||||
* values are: "false", "off", "0", and "no". Values are trimmed before
|
||||
* comparison. Values other than those listed here throw the exception.
|
||||
*
|
||||
* @return <code>boolean</code> value of attribute.
|
||||
* @throws DataConversionException when conversion fails.
|
||||
*/
|
||||
public boolean getBooleanValue() throws DataConversionException {
|
||||
final String valueTrim = value.trim();
|
||||
if (
|
||||
(valueTrim.equalsIgnoreCase("true")) ||
|
||||
(valueTrim.equalsIgnoreCase("on")) ||
|
||||
(valueTrim.equalsIgnoreCase("1")) ||
|
||||
(valueTrim.equalsIgnoreCase("yes"))) {
|
||||
return true;
|
||||
}
|
||||
else if (
|
||||
(valueTrim.equalsIgnoreCase("false")) ||
|
||||
(valueTrim.equalsIgnoreCase("off")) ||
|
||||
(valueTrim.equalsIgnoreCase("0")) ||
|
||||
(valueTrim.equalsIgnoreCase("no"))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new DataConversionException(name, "boolean");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespaces that are in-scope on this Attribute.
|
||||
* <p>
|
||||
* Attribute has peculiarities that affect the in-scope Namespaces because
|
||||
* there are conditions in which the Attribute's scope is different to its
|
||||
* parent Element's scope. Specifically, if the parent Element is in a
|
||||
* 'default' Namespace that is not the empty Namespace (e.g.
|
||||
* xmlns="someurl") and this Attribute is also in the default Namespace (has
|
||||
* no prefix - but for Attributes that means the Namespace URL is ""), then
|
||||
* this Attribute has a different namespace scope from it's parent Element
|
||||
* because it does not include the 'someurl' Namespace.
|
||||
* <p>
|
||||
* In the above conditions (no-prefix Attribute in an Element with a
|
||||
* non-empty no-prefix Namespace) this Attribute effectively re-binds the ""
|
||||
* prefix to the "" URL, thus the Attribute 'introduces' the Namespace.
|
||||
* It follows then that the getNamespacesIntroduced() will return a list
|
||||
* with the single member {@link Namespace#NO_NAMESPACE}.
|
||||
* <p>
|
||||
* Note that the Attribute's Namespace will always be reported first.
|
||||
* <p>
|
||||
* <strong>Description copied from</strong>
|
||||
* {@link NamespaceAware#getNamespacesInScope()}:
|
||||
* <p>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<Namespace> getNamespacesInScope() {
|
||||
if (getParent() == null) {
|
||||
ArrayList<Namespace> ret = new ArrayList<Namespace>(3);
|
||||
ret.add(getNamespace());
|
||||
ret.add(Namespace.XML_NAMESPACE);
|
||||
return Collections.unmodifiableList(ret);
|
||||
}
|
||||
return orderFirst(getNamespace(), getParent().getNamespacesInScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Namespace> getNamespacesIntroduced() {
|
||||
if (getParent() == null) {
|
||||
return Collections.singletonList(getNamespace());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Namespace> getNamespacesInherited() {
|
||||
if (getParent() == null) {
|
||||
return Collections.singletonList(Namespace.XML_NAMESPACE);
|
||||
}
|
||||
return orderFirst(getNamespace(), getParent().getNamespacesInScope());
|
||||
}
|
||||
|
||||
private static List<Namespace> orderFirst(final Namespace nsa, final List<Namespace> nsl) {
|
||||
if (nsl.get(0) == nsa) {
|
||||
return nsl;
|
||||
}
|
||||
|
||||
// OK, we have our namespace list, but ours is not the first.
|
||||
// we need the Attribute's Namespace to be up front.
|
||||
TreeMap<String, Namespace> tm = new TreeMap<String, Namespace>();
|
||||
for (Namespace ns : nsl) {
|
||||
if (ns != nsa) {
|
||||
tm.put(ns.getPrefix(), ns);
|
||||
}
|
||||
}
|
||||
ArrayList<Namespace> ret = new ArrayList<Namespace>(tm.size() + 1);
|
||||
ret.add(nsa);
|
||||
ret.addAll(tm.values());
|
||||
return Collections.unmodifiableList(ret);
|
||||
}
|
||||
}
|
||||
665
platform/util/jdom/src/org/jdom/AttributeList.java
Normal file
665
platform/util/jdom/src/org/jdom/AttributeList.java
Normal file
@@ -0,0 +1,665 @@
|
||||
/*--
|
||||
|
||||
Copyright (C) 2000-2012 Jason Hunter & Brett McLaughlin.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer that follows
|
||||
these conditions in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. The name "JDOM" must not be used to endorse or promote products
|
||||
derived from this software without prior written permission. For
|
||||
written permission, please contact <request_AT_jdom_DOT_org>.
|
||||
|
||||
4. Products derived from this software may not be called "JDOM", nor
|
||||
may "JDOM" appear in their name, without prior written permission
|
||||
from the JDOM Project Management <request_AT_jdom_DOT_org>.
|
||||
|
||||
In addition, we request (but do not require) that you include in the
|
||||
end-user documentation provided with the redistribution and/or in the
|
||||
software itself an acknowledgement equivalent to the following:
|
||||
"This product includes software developed by the
|
||||
JDOM Project (http://www.jdom.org/)."
|
||||
Alternatively, the acknowledgment may be graphical using the logos
|
||||
available at http://www.jdom.org/images/logos.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the JDOM Project and was originally
|
||||
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
|
||||
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
|
||||
on the JDOM Project, please see <http://www.jdom.org/>.
|
||||
|
||||
*/
|
||||
|
||||
package org.jdom;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <code>AttributeList</code> represents legal JDOM
|
||||
* <code>{@link Attribute}</code> content.
|
||||
* <p>
|
||||
* This class is NOT PUBLIC; users should see it as a simple List
|
||||
* implementation, although it behaves something like a Set because you cannot
|
||||
* add duplicate Attributes. An attribute is considered duplicate if it has the
|
||||
* same Namespace URI and Attribute name as another existing Attribute.
|
||||
*
|
||||
* @author Alex Rosen
|
||||
* @author Philippe Riand
|
||||
* @author Bradley S. Huffman
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
final class AttributeList extends AbstractList<Attribute> implements RandomAccess {
|
||||
/**
|
||||
* The initial size to start the backing array.
|
||||
*/
|
||||
private static final int INITIAL_ARRAY_SIZE = 4;
|
||||
|
||||
/**
|
||||
* The backing array
|
||||
*/
|
||||
private Attribute[] attributeData;
|
||||
|
||||
/**
|
||||
* The current size
|
||||
*/
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* The parent Element
|
||||
*/
|
||||
private final Element parent;
|
||||
|
||||
private static final Comparator<Attribute> ATTRIBUTE_NATURAL = new Comparator<Attribute>() {
|
||||
@Override
|
||||
public int compare(Attribute a1, Attribute a2) {
|
||||
int comp = a1.getNamespacePrefix().compareTo(a2.getNamespacePrefix());
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
return a1.getName().compareTo(a2.getName());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new instance of the AttributeList representing <i>parent</i>
|
||||
* Element's Attributes
|
||||
*
|
||||
* @param parent Element whose Attributes are to be held
|
||||
*/
|
||||
AttributeList(final Element parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and add <i>attribute</i> to the end of the list or replace an
|
||||
* existing <code>Attribute</code> with the same name and
|
||||
* <code>Namespace</code>.
|
||||
*
|
||||
* @param attribute The <code>Attribute</code> to insert into the list.
|
||||
* @return true as specified by <code>Collection.add()</code>.
|
||||
* @throws IllegalAddException if validation rules prevent the add
|
||||
*/
|
||||
@Override
|
||||
public boolean add(final Attribute attribute) {
|
||||
if (attribute.getParent() != null) {
|
||||
throw new IllegalAddException(
|
||||
"The attribute already has an existing parent \""
|
||||
+ attribute.getParent().getQualifiedName() + "\"");
|
||||
}
|
||||
|
||||
if (Verifier.checkNamespaceCollision(attribute, parent) != null) {
|
||||
throw new IllegalAddException(parent, attribute,
|
||||
Verifier.checkNamespaceCollision(attribute, parent));
|
||||
}
|
||||
|
||||
// returns -1 if not exist
|
||||
final int duplicate = indexOfDuplicate(attribute);
|
||||
if (duplicate < 0) {
|
||||
attribute.setParent(parent);
|
||||
ensureCapacity(size + 1);
|
||||
attributeData[size++] = attribute;
|
||||
modCount++;
|
||||
}
|
||||
else {
|
||||
final Attribute old = attributeData[duplicate];
|
||||
old.setParent(null);
|
||||
attributeData[duplicate] = attribute;
|
||||
attribute.setParent(parent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and add <i>attribute</i> to this list at <i>index</i>.
|
||||
*
|
||||
* @param index where to add/insert the <code>Attribute</code>
|
||||
* @param attribute <code>Attribute</code> to add
|
||||
* @throws IllegalAddException if validation rules prevent the add
|
||||
*/
|
||||
@Override
|
||||
public void add(final int index, final Attribute attribute) {
|
||||
if (index < 0 || index > size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index +
|
||||
" Size: " + size());
|
||||
}
|
||||
|
||||
if (attribute.getParent() != null) {
|
||||
throw new IllegalAddException(
|
||||
"The attribute already has an existing parent \"" +
|
||||
attribute.getParent().getQualifiedName() + "\"");
|
||||
}
|
||||
final int duplicate = indexOfDuplicate(attribute);
|
||||
if (duplicate >= 0) {
|
||||
throw new IllegalAddException("Cannot add duplicate attribute");
|
||||
}
|
||||
|
||||
final String reason = Verifier.checkNamespaceCollision(attribute, parent);
|
||||
if (reason != null) {
|
||||
throw new IllegalAddException(parent, attribute, reason);
|
||||
}
|
||||
|
||||
attribute.setParent(parent);
|
||||
|
||||
ensureCapacity(size + 1);
|
||||
if (index == size) {
|
||||
attributeData[size++] = attribute;
|
||||
}
|
||||
else {
|
||||
System.arraycopy(attributeData, index, attributeData, index + 1,
|
||||
size - index);
|
||||
attributeData[index] = attribute;
|
||||
size++;
|
||||
}
|
||||
modCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the <code>Attributes</code> in <i>collection</i>.
|
||||
*
|
||||
* @param collection The <code>Collection</code> of <code>Attributes</code> to add.
|
||||
* @return <code>true</code> if the list was modified as a result of the
|
||||
* add.
|
||||
* @throws IllegalAddException if validation rules prevent the addAll
|
||||
*/
|
||||
@Override
|
||||
public boolean addAll(final Collection<? extends Attribute> collection) {
|
||||
return addAll(size(), collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the <code>Attributes</code> in <i>collection</i> at the specified
|
||||
* <i>index</i> in this list.
|
||||
*
|
||||
* @param index The offset at which to start adding the <code>Attributes</code>
|
||||
* @param collection The <code>Collection</code> containing the <code>Attributes</code>
|
||||
* to add.
|
||||
* @return <code>true</code> if the list was modified as a result of the
|
||||
* add.
|
||||
* @throws IllegalAddException if validation rules prevent the addAll
|
||||
*/
|
||||
@Override
|
||||
public boolean addAll(final int index,
|
||||
final Collection<? extends Attribute> collection) {
|
||||
if (index < 0 || index > size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index +
|
||||
" Size: " + size());
|
||||
}
|
||||
|
||||
if (collection == null) {
|
||||
throw new NullPointerException(
|
||||
"Can not add a null Collection to AttributeList");
|
||||
}
|
||||
final int addcnt = collection.size();
|
||||
if (addcnt == 0) {
|
||||
return false;
|
||||
}
|
||||
if (addcnt == 1) {
|
||||
// quick check for single-add.
|
||||
add(index, collection.iterator().next());
|
||||
return true;
|
||||
}
|
||||
|
||||
ensureCapacity(size() + addcnt);
|
||||
|
||||
final int tmpmodcount = modCount;
|
||||
boolean ok = false;
|
||||
|
||||
int count = 0;
|
||||
|
||||
try {
|
||||
for (Attribute att : collection) {
|
||||
add(index + count, att);
|
||||
count++;
|
||||
}
|
||||
ok = true;
|
||||
}
|
||||
finally {
|
||||
if (!ok) {
|
||||
while (--count >= 0) {
|
||||
remove(index + count);
|
||||
}
|
||||
modCount = tmpmodcount;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current list.
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
if (attributeData != null) {
|
||||
while (size > 0) {
|
||||
size--;
|
||||
attributeData[size].setParent(null);
|
||||
attributeData[size] = null;
|
||||
}
|
||||
}
|
||||
modCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current list and set it to the contents of <i>collection</i>.
|
||||
*
|
||||
* @param collection The <code>Collection</code> to use.
|
||||
* @throws IllegalAddException if validation rules prevent the addAll
|
||||
*/
|
||||
void clearAndSet(final Collection<? extends Attribute> collection) {
|
||||
if (collection == null || collection.isEmpty()) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// keep a backup in case we need to roll-back...
|
||||
final Attribute[] old = attributeData;
|
||||
final int oldSize = size;
|
||||
final int oldModCount = modCount;
|
||||
|
||||
// clear the current system
|
||||
// we need to detatch before we add so that we don't run in to a problem
|
||||
// where an attribute in the to-add list is one that we are 'clearing'
|
||||
// first.
|
||||
while (size > 0) {
|
||||
old[--size].setParent(null);
|
||||
}
|
||||
size = 0;
|
||||
attributeData = null;
|
||||
|
||||
boolean ok = false;
|
||||
try {
|
||||
addAll(0, collection);
|
||||
ok = true;
|
||||
}
|
||||
finally {
|
||||
if (!ok) {
|
||||
// we have an exception pending....
|
||||
// restore the old system.
|
||||
// re-attach the old stuff
|
||||
attributeData = old;
|
||||
while (size < oldSize) {
|
||||
attributeData[size++].setParent(parent);
|
||||
}
|
||||
modCount = oldModCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the capacity of this <code>AttributeList</code> instance, if
|
||||
* necessary, to ensure that it can hold at least the number of items
|
||||
* specified by the minimum capacity argument.
|
||||
*
|
||||
* @param minCapacity the desired minimum capacity.
|
||||
*/
|
||||
private void ensureCapacity(final int minCapacity) {
|
||||
if (attributeData == null) {
|
||||
attributeData =
|
||||
new Attribute[Math.max(minCapacity, INITIAL_ARRAY_SIZE)];
|
||||
return;
|
||||
}
|
||||
else if (minCapacity < attributeData.length) {
|
||||
return;
|
||||
}
|
||||
// most JVM's allocate memory in multiples of 'double-words', on
|
||||
// 64-bit it's 16-bytes, on 32-bit it's 8 bytes which all means it makes
|
||||
// sense to increment the capacity in even values.
|
||||
attributeData = Arrays.copyOf(attributeData, ((minCapacity + INITIAL_ARRAY_SIZE) >>> 1) << 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the <code>Attribute</code> at <i>offset</i>.
|
||||
*
|
||||
* @param index The position of the <code>Attribute</code> to retrieve.
|
||||
* @return The <code>Attribute</code> at position <i>index</i>.
|
||||
*/
|
||||
@Override
|
||||
public Attribute get(final int index) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index +
|
||||
" Size: " + size());
|
||||
}
|
||||
|
||||
return attributeData[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the <code>Attribute</code> with the given name and the same
|
||||
* <code>Namespace</code> URI as <i>namespace</i>.
|
||||
*
|
||||
* @param name name of attribute to return
|
||||
* @param namespace indicate what <code>Namespace</code> URI to consider
|
||||
* @return the <code>Attribute</code>, or null if one doesn't exist.
|
||||
*/
|
||||
Attribute get(final String name, final Namespace namespace) {
|
||||
final int index = indexOf(name, namespace);
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
return attributeData[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return index of the <code>Attribute</code> with the given <i>name</i> and
|
||||
* the same Namespace URI as <i>namespace</i>.
|
||||
*
|
||||
* @param name name of <code>Attribute</code> to retrieve
|
||||
* @param namespace indicate what <code>Namespace</code> URI to consider
|
||||
* @return the index of the attribute that matches the conditions, or
|
||||
* <code>-1</code> if there is none.
|
||||
*/
|
||||
private int indexOf(final String name, final Namespace namespace) {
|
||||
if (attributeData != null) {
|
||||
if (namespace == null) {
|
||||
return indexOf(name, Namespace.NO_NAMESPACE);
|
||||
}
|
||||
final String uri = namespace.getURI();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Attribute att = attributeData[i];
|
||||
if (uri.equals(att.getNamespaceURI()) &&
|
||||
name.equals(att.getName())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the <code>Attribute</code> at <i>index</i>.
|
||||
*
|
||||
* @param index The offset of the <code>Attribute</code> to remove.
|
||||
* @return The removed <code>Attribute</code>.
|
||||
*/
|
||||
@Override
|
||||
public Attribute remove(final int index) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index +
|
||||
" Size: " + size());
|
||||
}
|
||||
|
||||
final Attribute old = attributeData[index];
|
||||
old.setParent(null);
|
||||
System.arraycopy(attributeData, index + 1, attributeData, index,
|
||||
size - index - 1);
|
||||
attributeData[--size] = null; // Let gc do its work
|
||||
modCount++;
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the <code>Attribute</code> with the specified name and the same
|
||||
* URI as <i>namespace</i>.
|
||||
*
|
||||
* @param name name of <code>Attribute</code> to remove
|
||||
* @param namespace indicate what <code>Namespace</code> URI to consider
|
||||
* @return the <code>true</code> if attribute was removed,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
boolean remove(final String name, final Namespace namespace) {
|
||||
final int index = indexOf(name, namespace);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
remove(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the <code>Attribute</code> at <i>index</i> to be <i>attribute</i>.
|
||||
*
|
||||
* @param index The location to set the value to.
|
||||
* @param attribute The <code>Attribute</code> to set.
|
||||
* @return The replaced <code>Attribute</code>.
|
||||
* @throws IllegalAddException if validation rules prevent the set
|
||||
*/
|
||||
@Override
|
||||
public Attribute set(final int index, final Attribute attribute) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index +
|
||||
" Size: " + size());
|
||||
}
|
||||
|
||||
if (attribute.getParent() != null) {
|
||||
throw new IllegalAddException(
|
||||
"The attribute already has an existing parent \"" +
|
||||
attribute.getParent().getQualifiedName() + "\"");
|
||||
}
|
||||
|
||||
final int duplicate = indexOfDuplicate(attribute);
|
||||
if ((duplicate >= 0) && (duplicate != index)) {
|
||||
throw new IllegalAddException("Cannot set duplicate attribute");
|
||||
}
|
||||
|
||||
final String reason = Verifier.checkNamespaceCollision(attribute, parent, index);
|
||||
if (reason != null) {
|
||||
throw new IllegalAddException(parent, attribute, reason);
|
||||
}
|
||||
|
||||
final Attribute old = attributeData[index];
|
||||
old.setParent(null);
|
||||
|
||||
attributeData[index] = attribute;
|
||||
attribute.setParent(parent);
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return index of attribute with same name and Namespace, or -1 if one
|
||||
* doesn't exist
|
||||
*/
|
||||
private int indexOfDuplicate(final Attribute attribute) {
|
||||
return indexOf(attribute.getName(), attribute.getNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <code>Iterator</code> over the <code>Attributes</code> in this
|
||||
* list in the proper sequence.
|
||||
*
|
||||
* @return an iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Attribute> iterator() {
|
||||
return new ALIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of <code>Attributes</code> in this list
|
||||
*
|
||||
* @return The number of <code>Attributes</code> in this list.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this list as a <code>String</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike the Arrays.binarySearch, this method never expects an
|
||||
* "already exists" condition, we only ever add, thus there will never
|
||||
* be a negative insertion-point.
|
||||
*
|
||||
* @param indexes The pointers to search within
|
||||
* @param len The number of pointers to search within
|
||||
* @param val The pointer we are checking for.
|
||||
* @param comp The Comparator to compare with
|
||||
* @return the insertion point.
|
||||
*/
|
||||
private int binarySearch(final int[] indexes, final int len,
|
||||
final int val, final Comparator<? super Attribute> comp) {
|
||||
int left = 0, mid, right = len - 1, cmp;
|
||||
final Attribute base = attributeData[val];
|
||||
while (left <= right) {
|
||||
mid = (left + right) >>> 1;
|
||||
cmp = comp.compare(base, attributeData[indexes[mid]]);
|
||||
if (cmp == 0) {
|
||||
while (mid < right && comp.compare(base, attributeData[indexes[mid + 1]]) == 0) {
|
||||
mid++;
|
||||
}
|
||||
return mid + 1;
|
||||
}
|
||||
else if (cmp < 0) {
|
||||
right = mid - 1;
|
||||
}
|
||||
else {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
private void sortInPlace(final int[] indexes) {
|
||||
// the indexes are a discrete set of values that have no duplicates,
|
||||
// and describe the relative order of each of them.
|
||||
// as a result, we can do some tricks....
|
||||
final int[] unsorted = indexes.clone();
|
||||
Arrays.sort(unsorted);
|
||||
final Attribute[] usc = new Attribute[unsorted.length];
|
||||
for (int i = 0; i < usc.length; i++) {
|
||||
usc[i] = attributeData[indexes[i]];
|
||||
}
|
||||
// usc contains the content in their pre-sorted order....
|
||||
for (int i = 0; i < indexes.length; i++) {
|
||||
attributeData[unsorted[i]] = usc[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the attributes using the supplied comparator. The attributes are
|
||||
* never added using regular mechanisms, so there are never problems with
|
||||
* detached or already-attached Attributes. The sort happens 'in place'.
|
||||
* <p>
|
||||
* If the comparator identifies two (or more) Attributes to be equal, then
|
||||
* the relative order of those attributes will not be changed.
|
||||
*
|
||||
* @param comp The Comparator to use for sorting.
|
||||
*/
|
||||
public void sort(Comparator<? super Attribute> comp) {
|
||||
if (comp == null) {
|
||||
comp = ATTRIBUTE_NATURAL;
|
||||
}
|
||||
final int sz = size;
|
||||
int[] indexes = new int[sz];
|
||||
for (int i = 0; i < sz; i++) {
|
||||
final int ip = binarySearch(indexes, i, i, comp);
|
||||
if (ip < i) {
|
||||
System.arraycopy(indexes, ip, indexes, ip + 1, i - ip);
|
||||
}
|
||||
indexes[ip] = i;
|
||||
}
|
||||
sortInPlace(indexes);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * ContentListIterator * * * * * * * * * * * * * */
|
||||
/* * * * * * * * * * * * * ContentListIterator * * * * * * * * * * * * * */
|
||||
|
||||
/**
|
||||
* A fast iterator that can beat AbstractList because we can access the data
|
||||
* directly. This is important because so much code now uses the for-each
|
||||
* type loop <code>for (Attribute a : element.getAttributes()) {...}</code>,
|
||||
* and that uses iterator().
|
||||
*
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
private final class ALIterator implements Iterator<Attribute> {
|
||||
// The modCount to expect (or throw ConcurrentModeEx)
|
||||
private int expect;
|
||||
// the index of the next Attribute to return.
|
||||
private int cursor = 0;
|
||||
// whether it is legal to call remove()
|
||||
private boolean canremove = false;
|
||||
|
||||
private ALIterator() {
|
||||
expect = modCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return cursor < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute next() {
|
||||
if (modCount != expect) {
|
||||
throw new ConcurrentModificationException("ContentList was " +
|
||||
"modified outside of this Iterator");
|
||||
}
|
||||
if (cursor >= size) {
|
||||
throw new NoSuchElementException("Iterated beyond the end of " +
|
||||
"the ContentList.");
|
||||
}
|
||||
canremove = true;
|
||||
return attributeData[cursor++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (modCount != expect) {
|
||||
throw new ConcurrentModificationException("ContentList was " +
|
||||
"modified outside of this Iterator");
|
||||
}
|
||||
if (!canremove) {
|
||||
throw new IllegalStateException("Can only remove() content " +
|
||||
"after a call to next()");
|
||||
}
|
||||
AttributeList.this.remove(--cursor);
|
||||
expect = modCount;
|
||||
canremove = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
177
platform/util/jdom/src/org/jdom/AttributeType.java
Normal file
177
platform/util/jdom/src/org/jdom/AttributeType.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*--
|
||||
|
||||
Copyright (C) 2011-2012 Jason Hunter & Brett McLaughlin.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer that follows
|
||||
these conditions in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. The name "JDOM" must not be used to endorse or promote products
|
||||
derived from this software without prior written permission. For
|
||||
written permission, please contact <request_AT_jdom_DOT_org>.
|
||||
|
||||
4. Products derived from this software may not be called "JDOM", nor
|
||||
may "JDOM" appear in their name, without prior written permission
|
||||
from the JDOM Project Management <request_AT_jdom_DOT_org>.
|
||||
|
||||
In addition, we request (but do not require) that you include in the
|
||||
end-user documentation provided with the redistribution and/or in the
|
||||
software itself an acknowledgement equivalent to the following:
|
||||
"This product includes software developed by the
|
||||
JDOM Project (http://www.jdom.org/)."
|
||||
Alternatively, the acknowledgment may be graphical using the logos
|
||||
available at http://www.jdom.org/images/logos.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the JDOM Project and was originally
|
||||
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
|
||||
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
|
||||
on the JDOM Project, please see <http://www.jdom.org/>.
|
||||
|
||||
*/
|
||||
|
||||
package org.jdom;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* Use a simple enumeration for the Attribute Types
|
||||
*
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
public enum AttributeType {
|
||||
/**
|
||||
* Attribute type: the attribute has not been declared or type
|
||||
* is unknown.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
UNDECLARED,
|
||||
|
||||
/**
|
||||
* Attribute type: the attribute value is a string.
|
||||
*
|
||||
* @see Attribute#getAttributeType
|
||||
*/
|
||||
CDATA,
|
||||
|
||||
/**
|
||||
* Attribute type: the attribute value is a unique identifier.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
ID,
|
||||
|
||||
/**
|
||||
* Attribute type: the attribute value is a reference to a
|
||||
* unique identifier.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
IDREF,
|
||||
|
||||
/**
|
||||
* Attribute type: the attribute value is a list of references to
|
||||
* unique identifiers.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
IDREFS,
|
||||
/**
|
||||
* Attribute type: the attribute value is the name of an entity.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
ENTITY,
|
||||
/**
|
||||
* <p>
|
||||
* Attribute type: the attribute value is a list of entity names.
|
||||
* </p>
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
ENTITIES,
|
||||
|
||||
/**
|
||||
* Attribute type: the attribute value is a name token.
|
||||
* <p>
|
||||
* According to SAX 2.0 specification, attributes of enumerated
|
||||
* types should be reported as "NMTOKEN" by SAX parsers. But the
|
||||
* major parsers (Xerces and Crimson) provide specific values
|
||||
* that permit to recognize them as {@link #ENUMERATION}.
|
||||
*
|
||||
* @see Attribute#getAttributeType
|
||||
*/
|
||||
NMTOKEN,
|
||||
/**
|
||||
* Attribute type: the attribute value is a list of name tokens.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
NMTOKENS,
|
||||
/**
|
||||
* Attribute type: the attribute value is the name of a notation.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
NOTATION,
|
||||
/**
|
||||
* Attribute type: the attribute value is a name token from an
|
||||
* enumeration.
|
||||
*
|
||||
* @see #getAttributeType
|
||||
*/
|
||||
ENUMERATION;
|
||||
|
||||
/**
|
||||
* Returns the JDOM AttributeType value from the SAX 2.0
|
||||
* attribute type string provided by the parser.
|
||||
*
|
||||
* @param typeName <code>String</code> the SAX 2.0 attribute
|
||||
* type string.
|
||||
* @return <code>int</code> the JDOM attribute type.
|
||||
* @see Attribute#setAttributeType
|
||||
* @see Attributes#getType
|
||||
*/
|
||||
public static AttributeType getAttributeType(String typeName) {
|
||||
if (typeName == null) {
|
||||
return UNDECLARED;
|
||||
}
|
||||
|
||||
try {
|
||||
return valueOf(typeName);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
if (typeName.length() > 0 &&
|
||||
typeName.trim().charAt(0) == '(') {
|
||||
// Xerces 1.4.X reports attributes of enumerated type with
|
||||
// a type string equals to the enumeration definition, i.e.
|
||||
// starting with a parenthesis.
|
||||
return ENUMERATION;
|
||||
}
|
||||
return UNDECLARED;
|
||||
}
|
||||
}
|
||||
}
|
||||
223
platform/util/jdom/src/org/jdom/CDATA.java
Normal file
223
platform/util/jdom/src/org/jdom/CDATA.java
Normal file
@@ -0,0 +1,223 @@
|
||||
/*--
|
||||
|
||||
Copyright (C) 2000-2012 Jason Hunter & Brett McLaughlin.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer that follows
|
||||
these conditions in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. The name "JDOM" must not be used to endorse or promote products
|
||||
derived from this software without prior written permission. For
|
||||
written permission, please contact <request_AT_jdom_DOT_org>.
|
||||
|
||||
4. Products derived from this software may not be called "JDOM", nor
|
||||
may "JDOM" appear in their name, without prior written permission
|
||||
from the JDOM Project Management <request_AT_jdom_DOT_org>.
|
||||
|
||||
In addition, we request (but do not require) that you include in the
|
||||
end-user documentation provided with the redistribution and/or in the
|
||||
software itself an acknowledgement equivalent to the following:
|
||||
"This product includes software developed by the
|
||||
JDOM Project (http://www.jdom.org/)."
|
||||
Alternatively, the acknowledgment may be graphical using the logos
|
||||
available at http://www.jdom.org/images/logos.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the JDOM Project and was originally
|
||||
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
|
||||
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
|
||||
on the JDOM Project, please see <http://www.jdom.org/>.
|
||||
|
||||
*/
|
||||
|
||||
package org.jdom;
|
||||
|
||||
import org.jdom.output.XMLOutputter2;
|
||||
|
||||
/**
|
||||
* An XML CDATA section. Represents character-based content within an XML
|
||||
* document that should be output within special CDATA tags. Semantically it's
|
||||
* identical to a simple {@link Text} object, but output behavior is different.
|
||||
* CDATA makes no guarantees about the underlying textual representation of
|
||||
* character data, but does expose that data as a Java String.
|
||||
*
|
||||
* @author Dan Schaffer
|
||||
* @author Brett McLaughlin
|
||||
* @author Jason Hunter
|
||||
* @author Bradley S. Huffman
|
||||
* @author Victor Toni
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
public class CDATA extends Text {
|
||||
/**
|
||||
* This is the protected, no-args constructor standard in all JDOM
|
||||
* classes. It allows subclasses to get a raw instance with no
|
||||
* initialization.
|
||||
*/
|
||||
protected CDATA() {
|
||||
super(CType.CDATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor creates a new <code>CDATA</code> node, with the
|
||||
* supplied string value as it's character content.
|
||||
*
|
||||
* @param string the node's character content.
|
||||
* @throws IllegalDataException if <code>str</code> contains an
|
||||
* illegal character such as a vertical tab (as determined
|
||||
* by {@link Verifier#checkCharacterData})
|
||||
* or the CDATA end delimiter <code>]]></code>.
|
||||
*/
|
||||
public CDATA(final String string) {
|
||||
super(CType.CDATA);
|
||||
setText(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the value of this <code>CDATA</code> node.
|
||||
*
|
||||
* @param str value for node's content.
|
||||
* @return the object on which the method was invoked
|
||||
* @throws IllegalDataException if <code>str</code> contains an
|
||||
* illegal character such as a vertical tab (as determined
|
||||
* by {@link Verifier#checkCharacterData})
|
||||
* or the CDATA end delimiter <code>]]></code>.
|
||||
*/
|
||||
@Override
|
||||
public CDATA setText(final String str) {
|
||||
// Overrides Text.setText() because this needs to check that CDATA rules
|
||||
// are enforced. We could have a separate Verifier check for CDATA
|
||||
// beyond Text and call that alone before super.setText().
|
||||
|
||||
if (str == null || str.isEmpty()) {
|
||||
value = EMPTY_STRING;
|
||||
return this;
|
||||
}
|
||||
|
||||
final String reason = Verifier.checkCDATASection(str);
|
||||
if (reason != null) {
|
||||
throw new IllegalDataException(str, "CDATA section", reason);
|
||||
}
|
||||
|
||||
value = str;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will append character content to whatever content already
|
||||
* exists within this <code>CDATA</code> node.
|
||||
*
|
||||
* @param str character content to append.
|
||||
* @throws IllegalDataException if <code>str</code> contains an
|
||||
* illegal character such as a vertical tab (as determined
|
||||
* by {@link Verifier#checkCharacterData})
|
||||
* or the CDATA end delimiter <code>]]></code>.
|
||||
*/
|
||||
@Override
|
||||
public void append(final String str) {
|
||||
// Overrides Text.append(String) because this needs to check that CDATA
|
||||
// rules are enforced. We could have a separate Verifier check for CDATA
|
||||
// beyond Text and call that alone before super.setText().
|
||||
|
||||
if (str == null || str.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we need a temp value to ensure that the value is changed _after_
|
||||
// validation
|
||||
final String tmpValue;
|
||||
//noinspection StringEquality
|
||||
if (value == EMPTY_STRING) {
|
||||
tmpValue = str;
|
||||
}
|
||||
else {
|
||||
tmpValue = value + str;
|
||||
}
|
||||
|
||||
// we have to do late checking since the end of a CDATA section could
|
||||
// have been created by concatenating both strings:
|
||||
// "]" + "]>"
|
||||
// or
|
||||
// "]]" + ">"
|
||||
// TODO: maybe this could be optimized for this two cases
|
||||
final String reason = Verifier.checkCDATASection(tmpValue);
|
||||
if (reason != null) {
|
||||
throw new IllegalDataException(str, "CDATA section", reason);
|
||||
}
|
||||
|
||||
value = tmpValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will append the content of another <code>Text</code> node
|
||||
* to this node.
|
||||
*
|
||||
* @param text Text node to append.
|
||||
*/
|
||||
@Override
|
||||
public void append(final Text text) {
|
||||
// Overrides Text.append(Text) because this needs to check that CDATA
|
||||
// rules are enforced. We could have a separate Verifier check for CDATA
|
||||
// beyond Text and call that alone before super.setText().
|
||||
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
append(text.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a <code>String</code> representation of the
|
||||
* <code>CDATA</code> node, suitable for debugging. If the XML
|
||||
* representation of the <code>CDATA</code> node is desired,
|
||||
* either <code>{@link #getText}</code> or
|
||||
* {@link XMLOutputter2#output(CDATA, java.io.Writer)}</code>
|
||||
* should be used.
|
||||
*
|
||||
* @return <code>String</code> - information about this node.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[CDATA: " +
|
||||
getText() +
|
||||
"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDATA clone() {
|
||||
return (CDATA)super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDATA detach() {
|
||||
return (CDATA)super.detach();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CDATA setParent(Parent parent) {
|
||||
return (CDATA)super.setParent(parent);
|
||||
}
|
||||
}
|
||||
114
platform/util/jdom/src/org/jdom/CloneBase.java
Normal file
114
platform/util/jdom/src/org/jdom/CloneBase.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*--
|
||||
|
||||
Copyright (C) 2012 Jason Hunter & Brett McLaughlin.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer that follows
|
||||
these conditions in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. The name "JDOM" must not be used to endorse or promote products
|
||||
derived from this software without prior written permission. For
|
||||
written permission, please contact <request_AT_jdom_DOT_org>.
|
||||
|
||||
4. Products derived from this software may not be called "JDOM", nor
|
||||
may "JDOM" appear in their name, without prior written permission
|
||||
from the JDOM Project Management <request_AT_jdom_DOT_org>.
|
||||
|
||||
In addition, we request (but do not require) that you include in the
|
||||
end-user documentation provided with the redistribution and/or in the
|
||||
software itself an acknowledgement equivalent to the following:
|
||||
"This product includes software developed by the
|
||||
JDOM Project (http://www.jdom.org/)."
|
||||
Alternatively, the acknowledgment may be graphical using the logos
|
||||
available at http://www.jdom.org/images/logos.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the JDOM Project and was originally
|
||||
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
|
||||
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
|
||||
on the JDOM Project, please see <http://www.jdom.org/>.
|
||||
|
||||
*/
|
||||
|
||||
package org.jdom;
|
||||
|
||||
/**
|
||||
* This simple class just tidies up any cloneable classes. This method deals
|
||||
* with any CloneNotSupported exceptions. THis class is package private only.
|
||||
*
|
||||
* @author Rolf Lear
|
||||
*/
|
||||
class CloneBase implements Cloneable {
|
||||
/**
|
||||
* Change the permission of the no-arg constructor from public to protected.
|
||||
* <p>
|
||||
* Otherwise, package-private class's constructor is not really public. Changing this to
|
||||
* 'protected' makes this constructor available to all subclasses regardless of the
|
||||
* subclass's package. This in turn makes it possible to make all th subclasses of this
|
||||
* CloneBase class serializable.
|
||||
*/
|
||||
protected CloneBase() {
|
||||
// This constructor is needed to solve issue #88
|
||||
// There needs to be a no-arg constructor accessible by all
|
||||
// potential subclasses of CloneBase, and 'protected' is actually more
|
||||
// accessible than 'public' since this is a package-private class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a deep clone of this instance. Even if this instance has a parent,
|
||||
* the returned clone will not.
|
||||
* <p>
|
||||
* All JDOM core classes are Cloneable, and never throw
|
||||
* CloneNotSupportedException. Additionally, all Cloneable JDOM classes
|
||||
* return the correct type of instance from this method and there is no
|
||||
* need to cast the result (co-variant return value).
|
||||
* <p>
|
||||
* Subclasses of this should still call super.clone() in their clone method.
|
||||
*/
|
||||
@Override
|
||||
protected CloneBase clone() {
|
||||
/*
|
||||
* Additionally, when you use the concept of 'co-variant return values'
|
||||
* you create 'bridge' methods. By way of example, because we change the
|
||||
* return type of clone() from Object to CloneBase, Java is forced to
|
||||
* put in a 'bridge' method that has an Object return type, even though
|
||||
* we never actually call it. <p> This has an impact on the code
|
||||
* coverage tool Cobertura, which reports that there is missed code (and
|
||||
* there is, the bridge method). It reports it as being '0' calls to the
|
||||
* 'class' line (the class line is marked red). By making this CloneBase
|
||||
* code do the first level of co-variant return, it is this class which
|
||||
* is victim of the Cobertura reporting, not the multiple subclasses
|
||||
* (like Attribute, Document, Content, etc.).
|
||||
*/
|
||||
try {
|
||||
return (CloneBase)super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unable to clone class %s which should always support it.",
|
||||
this.getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user