From 564ea2b8a45e005184d98f7ef0d37a452a91f955 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Mon, 15 May 2023 17:05:22 +0200 Subject: [PATCH] [jps model] API cleanup: remove unused deprecated API related to JpsEventDispatcher (IDEA-312594) This will make it simpler to migrate implementation of JpsModel to use the workspace entity storage (IDEA-252970). GitOrigin-RevId: f359bb075c6ee628bbe896ea16992532ebae8806 --- .../jps/model/JpsElementChildRole.java | 7 -- .../jps/model/JpsEventDispatcher.java | 39 --------- .../src/org/jetbrains/jps/model/JpsModel.java | 6 -- .../jps/model/JpsUrlListChangeListener.java | 28 ------- .../jps/model/ex/JpsElementBase.java | 17 +--- .../ex/JpsNamedCompositeElementBase.java | 10 +-- .../jps/model/library/JpsLibraryListener.java | 30 ------- .../model/library/JpsLibraryRootListener.java | 30 ------- .../module/JpsModuleContentRootsListener.java | 25 ------ .../module/JpsModuleExcludeRootsListener.java | 25 ------ .../jps/model/module/JpsModuleListener.java | 30 ------- .../module/JpsModuleSourceRootListener.java | 31 ------- .../jps/model/ex/JpsElementContainerImpl.java | 62 +++----------- .../model/impl/JpsElementCollectionImpl.java | 8 -- .../jps/model/impl/JpsElementFactoryImpl.java | 10 +-- .../model/impl/JpsEventDispatcherBase.java | 52 ------------ .../jps/model/impl/JpsGlobalImpl.java | 8 +- .../jps/model/impl/JpsModelImpl.java | 19 ++--- .../jps/model/impl/JpsProjectImpl.java | 8 +- .../jps/model/impl/JpsRootElementBase.java | 13 +-- .../model/library/impl/JpsLibraryRole.java | 15 +--- .../library/impl/JpsLibraryRootRole.java | 12 --- .../jps/model/module/impl/JpsModuleRole.java | 15 +--- .../module/impl/JpsModuleSourceRootRole.java | 13 --- .../jps/model/JpsJavaExtensionTest.java | 6 +- .../jetbrains/jps/model/JpsLibraryTest.java | 13 --- .../jetbrains/jps/model/JpsModelTestCase.java | 4 +- .../jetbrains/jps/model/JpsModuleTest.java | 47 +---------- .../jps/model/TestJpsEventDispatcher.java | 82 ------------------- 29 files changed, 40 insertions(+), 625 deletions(-) delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/JpsEventDispatcher.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/JpsUrlListChangeListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryRootListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleContentRootsListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleExcludeRootsListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleListener.java delete mode 100644 jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRootListener.java delete mode 100644 jps/model-impl/src/org/jetbrains/jps/model/impl/JpsEventDispatcherBase.java delete mode 100644 jps/model-impl/testSrc/org/jetbrains/jps/model/TestJpsEventDispatcher.java diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsElementChildRole.java b/jps/model-api/src/org/jetbrains/jps/model/JpsElementChildRole.java index 9ce082cea2f8..c3d3e146bcaa 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsElementChildRole.java +++ b/jps/model-api/src/org/jetbrains/jps/model/JpsElementChildRole.java @@ -15,12 +15,5 @@ */ package org.jetbrains.jps.model; -import org.jetbrains.annotations.NotNull; - public class JpsElementChildRole { - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) { - } - - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) { - } } diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsEventDispatcher.java b/jps/model-api/src/org/jetbrains/jps/model/JpsEventDispatcher.java deleted file mode 100644 index 3d503b05eb72..000000000000 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsEventDispatcher.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model; - -import org.jetbrains.annotations.NotNull; - -import java.util.EventListener; - -/** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ -@Deprecated(forRemoval = true) -public interface JpsEventDispatcher { - @NotNull - T getPublisher(Class listenerClass); - - void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName); - - void fireElementChanged(@NotNull JpsElement element); - - - void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole role); - - - void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole role); -} diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsModel.java b/jps/model-api/src/org/jetbrains/jps/model/JpsModel.java index 5b18cf9c2dd6..e7b8e4d2fc81 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsModel.java +++ b/jps/model-api/src/org/jetbrains/jps/model/JpsModel.java @@ -27,12 +27,6 @@ public interface JpsModel { @NotNull JpsGlobal getGlobal(); - /** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ - @Deprecated(forRemoval = true) - @NotNull JpsModel createModifiableModel(@NotNull JpsEventDispatcher eventDispatcher); - void registerExternalReference(@NotNull JpsElementReference reference); void commit(); diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsUrlListChangeListener.java b/jps/model-api/src/org/jetbrains/jps/model/JpsUrlListChangeListener.java deleted file mode 100644 index c8fa650a4c18..000000000000 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsUrlListChangeListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model; - -import org.jetbrains.annotations.NotNull; - -/** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ -@Deprecated(forRemoval = true) -public interface JpsUrlListChangeListener { - void urlAdded(@NotNull T element, @NotNull String url); - - void urlRemoved(@NotNull T element, @NotNull String url); -} diff --git a/jps/model-api/src/org/jetbrains/jps/model/ex/JpsElementBase.java b/jps/model-api/src/org/jetbrains/jps/model/ex/JpsElementBase.java index 5530fbb8cce1..328f1ad9f924 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/ex/JpsElementBase.java +++ b/jps/model-api/src/org/jetbrains/jps/model/ex/JpsElementBase.java @@ -18,7 +18,6 @@ package org.jetbrains.jps.model.ex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.JpsElement; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.JpsModel; public abstract class JpsElementBase> implements JpsElement, JpsElement.BulkModificationSupport { @@ -34,25 +33,17 @@ public abstract class JpsElementBase> implemen myParent = parent; } + /** + * @deprecated does nothing, all calls must be removed + */ + @Deprecated protected void fireElementChanged() { - final JpsEventDispatcher eventDispatcher = getEventDispatcher(); - if (eventDispatcher != null) { - eventDispatcher.fireElementChanged(this); - } } protected static void setParent(@NotNull JpsElement element, @Nullable JpsElementBase parent) { ((JpsElementBase)element).setParent(parent); } - @Nullable - protected JpsEventDispatcher getEventDispatcher() { - if (myParent != null) { - return myParent.getEventDispatcher(); - } - return null; - } - @Nullable protected JpsModel getModel() { if (myParent != null) { diff --git a/jps/model-api/src/org/jetbrains/jps/model/ex/JpsNamedCompositeElementBase.java b/jps/model-api/src/org/jetbrains/jps/model/ex/JpsNamedCompositeElementBase.java index 4baa0043e1b9..3ec89a589a2b 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/ex/JpsNamedCompositeElementBase.java +++ b/jps/model-api/src/org/jetbrains/jps/model/ex/JpsNamedCompositeElementBase.java @@ -17,7 +17,6 @@ package org.jetbrains.jps.model.ex; import com.intellij.openapi.util.NlsSafe; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.JpsNamedElement; public abstract class JpsNamedCompositeElementBase> extends JpsCompositeElementBase @@ -48,13 +47,6 @@ public abstract class JpsNamedCompositeElementBase { -} diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleExcludeRootsListener.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleExcludeRootsListener.java deleted file mode 100644 index 22c7c065a1f0..000000000000 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleExcludeRootsListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model.module; - -import org.jetbrains.jps.model.JpsUrlListChangeListener; - -/** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ -@Deprecated(forRemoval = true) -public interface JpsModuleExcludeRootsListener extends JpsUrlListChangeListener { -} diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleListener.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleListener.java deleted file mode 100644 index 7299f61fbe9d..000000000000 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleListener.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model.module; - -import org.jetbrains.annotations.NotNull; - -import java.util.EventListener; - -/** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ -@SuppressWarnings("DeprecatedIsStillUsed") -@Deprecated(forRemoval = true) -public interface JpsModuleListener extends EventListener { - void moduleAdded(@NotNull JpsModule module); - void moduleRemoved(@NotNull JpsModule module); -} diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRootListener.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRootListener.java deleted file mode 100644 index 10021d8c370b..000000000000 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRootListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model.module; - -import org.jetbrains.annotations.NotNull; - -import java.util.EventListener; - -/** - * @deprecated modifications of JpsModel were never fully supported, and they won't be since JpsModel will be superseded by {@link com.intellij.workspaceModel.storage.WorkspaceEntityStorage the workspace model}. - */ -@SuppressWarnings("DeprecatedIsStillUsed") -@Deprecated(forRemoval = true) -public interface JpsModuleSourceRootListener extends EventListener { - void sourceRootAdded(@NotNull JpsModuleSourceRoot root); - void sourceRootRemoved(@NotNull JpsModuleSourceRoot root); - void sourceRootChanged(@NotNull JpsModuleSourceRoot root); -} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java index b11613d315cc..adc0506dbb29 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java @@ -3,7 +3,6 @@ package org.jetbrains.jps.model.ex; import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.*; import java.util.ArrayList; @@ -57,51 +56,30 @@ public class JpsElementContainerImpl extends JpsElementContainerEx implements Jp @NotNull @Override public & JpsElementCreator> T getOrSetChild(@NotNull K role) { - T added = null; - try { - synchronized (myDataLock) { - final T cached = (T)myElements.get(role); - if (cached != null) { - return cached; - } - return added = putChild(role, role.create()); - } - } - finally { - if (added != null) { - fireChildSet(role, added); + synchronized (myDataLock) { + final T cached = (T)myElements.get(role); + if (cached != null) { + return cached; } + return putChild(role, role.create()); } } @Override public & JpsElementParameterizedCreator> T getOrSetChild(@NotNull K role, @NotNull Supplier

param) { - T added = null; - try { - synchronized (myDataLock) { - final T cached = (T)myElements.get(role); - if (cached != null) { - return cached; - } - return added = putChild(role, role.create(param.get())); - } - } - finally { - if (added != null) { - fireChildSet(role, added); + synchronized (myDataLock) { + final T cached = (T)myElements.get(role); + if (cached != null) { + return cached; } + return putChild(role, role.create(param.get())); } } @Override public T setChild(JpsElementChildRole role, T child) { - try { - synchronized (myDataLock) { - return putChild(role, child); - } - } - finally { - fireChildSet(role, child); + synchronized (myDataLock) { + return putChild(role, child); } } @@ -112,13 +90,6 @@ public class JpsElementContainerImpl extends JpsElementContainerEx implements Jp return child; } - private void fireChildSet(JpsElementChildRole role, T child) { - final JpsEventDispatcher eventDispatcher = getEventDispatcher(); - if (eventDispatcher != null) { - eventDispatcher.fireElementAdded(child, role); - } - } - @Override public void removeChild(@NotNull JpsElementChildRole role) { //noinspection unchecked @@ -127,10 +98,6 @@ public class JpsElementContainerImpl extends JpsElementContainerEx implements Jp removed = (T)myElements.remove(role); } if (removed == null) return; - final JpsEventDispatcher eventDispatcher = getEventDispatcher(); - if (eventDispatcher != null) { - eventDispatcher.fireElementRemoved(removed, role); - } JpsElementBase.setParent(removed, null); } @@ -184,9 +151,4 @@ public class JpsElementContainerImpl extends JpsElementContainerEx implements Jp setChild(role, (T)modifiedChild.getBulkModificationSupport().createCopy()); } } - - @Nullable - private JpsEventDispatcher getEventDispatcher() { - return myParent.getEventDispatcher(); - } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionImpl.java index 5d3ef2dec794..2e59a0cce93f 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionImpl.java @@ -67,10 +67,6 @@ public final class JpsElementCollectionImpl extends JpsEle public X addChild(X element) { myElements.add(element); setParent(element, this); - final JpsEventDispatcher eventDispatcher = getEventDispatcher(); - if (eventDispatcher != null) { - eventDispatcher.fireElementAdded(element, myChildRole); - } return element; } @@ -78,10 +74,6 @@ public final class JpsElementCollectionImpl extends JpsEle public void removeChild(@NotNull E element) { final boolean removed = myElements.remove(element); if (removed) { - final JpsEventDispatcher eventDispatcher = getEventDispatcher(); - if (eventDispatcher != null) { - eventDispatcher.fireElementRemoved(element, myChildRole); - } setParent(element, null); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java index 43df0dba9529..27f5bca1e7fb 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java @@ -36,15 +36,7 @@ import org.jetbrains.jps.model.module.impl.JpsModuleSourceRootImpl; public final class JpsElementFactoryImpl extends JpsElementFactory { @Override public JpsModel createModel() { - return new JpsModelImpl(new JpsEventDispatcherBase() { - @Override - public void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName) { - } - - @Override - public void fireElementChanged(@NotNull JpsElement element) { - } - }); + return new JpsModelImpl(); } @Override diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsEventDispatcherBase.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsEventDispatcherBase.java deleted file mode 100644 index cc112555b39b..000000000000 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsEventDispatcherBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model.impl; - -import com.intellij.util.EventDispatcher; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElement; -import org.jetbrains.jps.model.JpsElementChildRole; -import org.jetbrains.jps.model.JpsEventDispatcher; - -import java.util.EventListener; -import java.util.HashMap; -import java.util.Map; - -public abstract class JpsEventDispatcherBase implements JpsEventDispatcher { - private final Map, EventDispatcher> myDispatchers = new HashMap<>(); - - @NotNull - @Override - public T getPublisher(Class listenerClass) { - EventDispatcher dispatcher = myDispatchers.get(listenerClass); - if (dispatcher == null) { - dispatcher = EventDispatcher.create(listenerClass); - myDispatchers.put(listenerClass, dispatcher); - } - //noinspection unchecked - return (T)dispatcher.getMulticaster(); - } - - @Override - public void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole role) { - role.fireElementAdded(this, element); - } - - @Override - public void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole role) { - role.fireElementRemoved(this, element); - } -} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java index ab3ea71bc069..fb4a615a16cc 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java @@ -32,14 +32,14 @@ public final class JpsGlobalImpl extends JpsRootElementBase imple private final JpsLibraryCollectionImpl myLibraryCollection; private JpsPathMapper myPathMapper = JpsPathMapper.IDENTITY; - public JpsGlobalImpl(@NotNull JpsModel model, JpsEventDispatcher eventDispatcher) { - super(model, eventDispatcher); + public JpsGlobalImpl(@NotNull JpsModel model) { + super(model); myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryRole.LIBRARIES_COLLECTION_ROLE)); myContainer.setChild(JpsFileTypesConfigurationImpl.ROLE, new JpsFileTypesConfigurationImpl()); } - public JpsGlobalImpl(JpsGlobalImpl original, JpsModel model, JpsEventDispatcher eventDispatcher) { - super(original, model, eventDispatcher); + public JpsGlobalImpl(JpsGlobalImpl original, JpsModel model) { + super(original, model); myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.getChild(JpsLibraryRole.LIBRARIES_COLLECTION_ROLE)); } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsModelImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsModelImpl.java index 1053639c0cbc..a8fe04f3f90a 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsModelImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsModelImpl.java @@ -17,7 +17,6 @@ package org.jetbrains.jps.model.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.JpsElementReference; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.JpsModel; public final class JpsModelImpl implements JpsModel { @@ -25,15 +24,15 @@ public final class JpsModelImpl implements JpsModel { private final JpsGlobalImpl myGlobal; private JpsModelImpl myOriginalModel; - public JpsModelImpl(JpsEventDispatcher eventDispatcher) { - myProject = new JpsProjectImpl(this, eventDispatcher); - myGlobal = new JpsGlobalImpl(this, eventDispatcher); + public JpsModelImpl() { + myProject = new JpsProjectImpl(this); + myGlobal = new JpsGlobalImpl(this); } - private JpsModelImpl(JpsModelImpl original, JpsEventDispatcher eventDispatcher) { + private JpsModelImpl(JpsModelImpl original) { myOriginalModel = original; - myProject = new JpsProjectImpl(original.myProject, this, eventDispatcher); - myGlobal = new JpsGlobalImpl(original.myGlobal, this, eventDispatcher); + myProject = new JpsProjectImpl(original.myProject, this); + myGlobal = new JpsGlobalImpl(original.myGlobal, this); } @Override @@ -48,12 +47,6 @@ public final class JpsModelImpl implements JpsModel { return myGlobal; } - @NotNull - @Override - public JpsModel createModifiableModel(@NotNull JpsEventDispatcher eventDispatcher) { - return new JpsModelImpl(this, eventDispatcher); - } - @Override public void registerExternalReference(@NotNull JpsElementReference reference) { myProject.addExternalReference(reference); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java index df1f35fcafc5..7d72a136c4a9 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java @@ -32,8 +32,8 @@ public final class JpsProjectImpl extends JpsRootElementBase imp private final JpsLibraryCollection myLibraryCollection; private String myName = ""; - public JpsProjectImpl(@NotNull JpsModel model, JpsEventDispatcher eventDispatcher) { - super(model, eventDispatcher); + public JpsProjectImpl(@NotNull JpsModel model) { + super(model); myContainer.setChild(JpsModuleRole.MODULE_COLLECTION_ROLE); myContainer.setChild(EXTERNAL_REFERENCES_COLLECTION_ROLE); myContainer.setChild(JpsSdkReferencesTableImpl.ROLE); @@ -41,8 +41,8 @@ public final class JpsProjectImpl extends JpsRootElementBase imp myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.setChild(JpsLibraryRole.LIBRARIES_COLLECTION_ROLE)); } - public JpsProjectImpl(JpsProjectImpl original, JpsModel model, JpsEventDispatcher eventDispatcher) { - super(original, model, eventDispatcher); + public JpsProjectImpl(JpsProjectImpl original, JpsModel model) { + super(original, model); myLibraryCollection = new JpsLibraryCollectionImpl(myContainer.getChild(JpsLibraryRole.LIBRARIES_COLLECTION_ROLE)); } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsRootElementBase.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsRootElementBase.java index f26658a54bc4..4c4d2b0541ec 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsRootElementBase.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsRootElementBase.java @@ -16,29 +16,20 @@ package org.jetbrains.jps.model.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.model.ex.JpsCompositeElementBase; public abstract class JpsRootElementBase> extends JpsCompositeElementBase { private final JpsModel myModel; - private final JpsEventDispatcher myEventDispatcher; - protected JpsRootElementBase(@NotNull JpsModel model, JpsEventDispatcher eventDispatcher) { + protected JpsRootElementBase(@NotNull JpsModel model) { super(); myModel = model; - myEventDispatcher = eventDispatcher; } - protected JpsRootElementBase(JpsCompositeElementBase original, JpsModel model, JpsEventDispatcher dispatcher) { + protected JpsRootElementBase(JpsCompositeElementBase original, JpsModel model) { super(original); myModel = model; - myEventDispatcher = dispatcher; - } - - @Override - protected JpsEventDispatcher getEventDispatcher() { - return myEventDispatcher; } @NotNull diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRole.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRole.java index e6ce9d759520..69535e224880 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRole.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRole.java @@ -1,12 +1,9 @@ // 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. package org.jetbrains.jps.model.library.impl; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsEventDispatcher; -import org.jetbrains.jps.model.ex.JpsElementCollectionRole; import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; +import org.jetbrains.jps.model.ex.JpsElementCollectionRole; import org.jetbrains.jps.model.library.JpsLibrary; -import org.jetbrains.jps.model.library.JpsLibraryListener; public final class JpsLibraryRole extends JpsElementChildRoleBase { private static final JpsLibraryRole INSTANCE = new JpsLibraryRole(); @@ -15,14 +12,4 @@ public final class JpsLibraryRole extends JpsElementChildRoleBase { private JpsLibraryRole() { super("library"); } - - @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { - dispatcher.getPublisher(JpsLibraryListener.class).libraryAdded(element); - } - - @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { - dispatcher.getPublisher(JpsLibraryListener.class).libraryRemoved(element); - } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootRole.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootRole.java index 947436ade6eb..35b5481ee2f8 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootRole.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootRole.java @@ -16,10 +16,8 @@ package org.jetbrains.jps.model.library.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; import org.jetbrains.jps.model.library.JpsLibraryRoot; -import org.jetbrains.jps.model.library.JpsLibraryRootListener; import org.jetbrains.jps.model.library.JpsOrderRootType; public final class JpsLibraryRootRole extends JpsElementChildRoleBase { @@ -30,16 +28,6 @@ public final class JpsLibraryRootRole extends JpsElementChildRoleBase { private static final JpsElementChildRole INSTANCE = new JpsModuleRole(); @@ -16,14 +13,4 @@ public final class JpsModuleRole extends JpsElementChildRoleBase { private JpsModuleRole() { super("module"); } - - @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { - dispatcher.getPublisher(JpsModuleListener.class).moduleAdded(element); - } - - @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { - dispatcher.getPublisher(JpsModuleListener.class).moduleRemoved(element); - } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootRole.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootRole.java index 9cb1f732a305..ca85ff14ad50 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootRole.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootRole.java @@ -1,12 +1,9 @@ // 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. package org.jetbrains.jps.model.module.impl; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; import org.jetbrains.jps.model.ex.JpsElementCollectionRole; import org.jetbrains.jps.model.module.JpsModuleSourceRoot; -import org.jetbrains.jps.model.module.JpsModuleSourceRootListener; public final class JpsModuleSourceRootRole extends JpsElementChildRoleBase { private static final JpsModuleSourceRootRole INSTANCE = new JpsModuleSourceRootRole(); @@ -15,14 +12,4 @@ public final class JpsModuleSourceRootRole extends JpsElementChildRoleBase dependencies = assertOneElement(myProject.getModules()).getDependenciesList().getDependencies(); assertEquals(2, dependencies.size()); diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsLibraryTest.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsLibraryTest.java index 6b1b69a12647..f03123d2d167 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsLibraryTest.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsLibraryTest.java @@ -38,19 +38,6 @@ public class JpsLibraryTest extends JpsModelTestCase { assertEquals("file://my-url", assertOneElement(library.getRoots(JpsOrderRootType.COMPILED)).getUrl()); } - public void testModifiableCopy() { - myProject.addLibrary("a", JpsJavaLibraryType.INSTANCE); - - final JpsModel modifiableModel = myModel.createModifiableModel(new TestJpsEventDispatcher()); - final JpsLibrary modifiable = assertOneElement(modifiableModel.getProject().getLibraryCollection().getLibraries()); - modifiable.addRoot("file://my-url", JpsOrderRootType.COMPILED); - modifiableModel.commit(); - - final JpsLibrary library = assertOneElement(myProject.getLibraryCollection().getLibraries()); - assertEquals("file://my-url", assertOneElement(library.getRoots(JpsOrderRootType.COMPILED)).getUrl()); - assertEmpty(library.getRoots(JpsOrderRootType.SOURCES)); - } - public void testCreateReferenceByLibrary() { final JpsLibrary library = myProject.addLibrary("l", JpsJavaLibraryType.INSTANCE); final JpsLibraryReference reference = library.createReference().asExternal(myModel); diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModelTestCase.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModelTestCase.java index c9b532b64c3c..4b0359a04164 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModelTestCase.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModelTestCase.java @@ -20,14 +20,12 @@ import org.jetbrains.jps.model.impl.JpsModelImpl; public abstract class JpsModelTestCase extends UsefulTestCase { protected JpsModel myModel; - protected TestJpsEventDispatcher myDispatcher; protected JpsProject myProject; @Override public void setUp() throws Exception { super.setUp(); - myDispatcher = new TestJpsEventDispatcher(); - myModel = new JpsModelImpl(myDispatcher); + myModel = new JpsModelImpl(); myProject = myModel.getProject(); } } diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java index 35a440c155cc..2e21e3046529 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java @@ -27,10 +27,7 @@ public class JpsModuleTest extends JpsModelTestCase { public void testAddSourceRoot() { final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE); JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("com.xxx"); - final JpsModuleSourceRoot sourceRoot = module.addSourceRoot("file://url", JavaSourceRootType.SOURCE, properties); - - assertSameElements(myDispatcher.retrieveAdded(JpsModule.class), module); - assertSameElements(myDispatcher.retrieveAdded(JpsModuleSourceRoot.class), sourceRoot); + module.addSourceRoot("file://url", JavaSourceRootType.SOURCE, properties); final JpsModuleSourceRoot root = assertOneElement(module.getSourceRoots()); assertEquals("file://url", root.getUrl()); @@ -56,28 +53,6 @@ public class JpsModuleTest extends JpsModelTestCase { assertEquals("*.class", pattern.getPattern()); } - public void testModifiableModel() { - final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE); - final JpsModuleSourceRoot root0 = module.addSourceRoot("url1", JavaSourceRootType.SOURCE); - myDispatcher.clear(); - - final JpsModel modifiableModel = myModel.createModifiableModel(new TestJpsEventDispatcher()); - final JpsModule modifiableModule = assertOneElement(modifiableModel.getProject().getModules()); - modifiableModule.addSourceRoot("url2", JavaSourceRootType.TEST_SOURCE); - modifiableModel.commit(); - - assertEmpty(myDispatcher.retrieveAdded(JpsModule.class)); - assertEmpty(myDispatcher.retrieveRemoved(JpsModule.class)); - - final List roots = module.getSourceRoots(); - assertEquals(2, roots.size()); - assertSame(root0, roots.get(0)); - final JpsModuleSourceRoot root1 = roots.get(1); - assertEquals("url2", root1.getUrl()); - assertOrderedEquals(myDispatcher.retrieveAdded(JpsModuleSourceRoot.class), root1); - assertEmpty(myDispatcher.retrieveChanged(JpsModuleSourceRoot.class)); - } - public void testAddDependency() { final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE); final JpsLibrary library = myProject.addLibrary("l", JpsJavaLibraryType.INSTANCE); @@ -92,26 +67,6 @@ public class JpsModuleTest extends JpsModelTestCase { assertSame(dep, assertInstanceOf(dependencies.get(2), JpsModuleDependency.class).getModule()); } - public void testChangeElementInModifiableModel() { - final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE); - final JpsModule dep = myProject.addModule("dep", JpsJavaModuleType.INSTANCE); - final JpsLibrary library = myProject.addLibrary("l", JpsJavaLibraryType.INSTANCE); - module.getDependenciesList().addLibraryDependency(library); - myDispatcher.clear(); - - final JpsModel modifiableModel = myModel.createModifiableModel(new TestJpsEventDispatcher()); - final JpsModule m = modifiableModel.getProject().getModules().get(0); - assertEquals("m", m.getName()); - m.getDependenciesList().getDependencies().get(1).remove(); - m.getDependenciesList().addModuleDependency(dep); - modifiableModel.commit(); - assertOneElement(myDispatcher.retrieveRemoved(JpsLibraryDependency.class)); - assertSame(dep, assertOneElement(myDispatcher.retrieveAdded(JpsModuleDependency.class)).getModuleReference().resolve()); - List dependencies = module.getDependenciesList().getDependencies(); - assertEquals(2, dependencies.size()); - assertSame(dep, assertInstanceOf(dependencies.get(1), JpsModuleDependency.class).getModuleReference().resolve()); - } - public void testCreateReferenceByModule() { final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE); final JpsModuleReference reference = module.createReference().asExternal(myModel); diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/TestJpsEventDispatcher.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/TestJpsEventDispatcher.java deleted file mode 100644 index cfd26fffa4b3..000000000000 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/TestJpsEventDispatcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.jps.model; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.impl.JpsEventDispatcherBase; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class TestJpsEventDispatcher extends JpsEventDispatcherBase implements JpsEventDispatcher { - private final List myAdded = new ArrayList<>(); - private final List myRemoved = new ArrayList<>(); - private final List myChanged = new ArrayList<>(); - - @Override - public void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole role) { - super.fireElementAdded(element, role); - myAdded.add(element); - } - - @Override - public void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole role) { - super.fireElementRemoved(element, role); - myRemoved.add(element); - } - - @Override - public void fireElementChanged(@NotNull JpsElement element) { - myChanged.add(element); - } - - @Override - public void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName) { - } - - public List retrieveAdded(Class type) { - return retrieve(type, myAdded); - } - - public List retrieveRemoved(Class type) { - return retrieve(type, myRemoved); - } - - public List retrieveChanged(Class type) { - return retrieve(type, myChanged); - } - - public void clear() { - myAdded.clear(); - myRemoved.clear(); - myChanged.clear(); - } - - - private static List retrieve(Class type, List list) { - final List result = new ArrayList<>(); - final Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - JpsElement element = iterator.next(); - if (type.isInstance(element)) { - result.add(type.cast(element)); - iterator.remove(); - } - } - return result; - } -}