[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
This commit is contained in:
Nikolay Chashnikov
2023-05-15 17:05:22 +02:00
committed by intellij-monorepo-bot
parent 9843d2a01a
commit 564ea2b8a4
29 changed files with 40 additions and 625 deletions

View File

@@ -15,12 +15,5 @@
*/
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
public class JpsElementChildRole<E extends JpsElement> {
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) {
}
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) {
}
}

View File

@@ -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 extends EventListener> T getPublisher(Class<T> listenerClass);
void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName);
void fireElementChanged(@NotNull JpsElement element);
<T extends JpsElement>
void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole<T> role);
<T extends JpsElement>
void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole<T> role);
}

View File

@@ -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();

View File

@@ -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<T extends JpsElement> {
void urlAdded(@NotNull T element, @NotNull String url);
void urlRemoved(@NotNull T element, @NotNull String url);
}

View File

@@ -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<Self extends JpsElementBase<Self>> implements JpsElement, JpsElement.BulkModificationSupport<Self> {
@@ -34,25 +33,17 @@ public abstract class JpsElementBase<Self extends JpsElementBase<Self>> 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) {

View File

@@ -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<Self extends JpsNamedCompositeElementBase<Self>> extends JpsCompositeElementBase<Self>
@@ -48,13 +47,6 @@ public abstract class JpsNamedCompositeElementBase<Self extends JpsNamedComposit
@Override
public void setName(@NlsSafe @NotNull String name) {
if (!myName.equals(name)) {
String oldName = myName;
myName = name;
final JpsEventDispatcher eventDispatcher = getEventDispatcher();
if (eventDispatcher != null) {
eventDispatcher.fireElementRenamed(this, oldName, name);
}
}
myName = name;
}
}

View File

@@ -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.library;
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 JpsLibraryListener extends EventListener {
void libraryAdded(@NotNull JpsLibrary library);
void libraryRemoved(@NotNull JpsLibrary library);
}

View File

@@ -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.library;
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 JpsLibraryRootListener extends EventListener {
void rootAdded(@NotNull JpsLibraryRoot root);
void rootRemoved(@NotNull JpsLibraryRoot root);
}

View File

@@ -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 JpsModuleContentRootsListener extends JpsUrlListChangeListener<JpsModule> {
}

View File

@@ -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<JpsModule> {
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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 <T extends JpsElement, K extends JpsElementChildRole<T> & JpsElementCreator<T>> 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 <T extends JpsElement, P, K extends JpsElementChildRole<T> & JpsElementParameterizedCreator<T, P>> T getOrSetChild(@NotNull K role, @NotNull Supplier<P> 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 extends JpsElement> T setChild(JpsElementChildRole<T> 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 <T extends JpsElement> void fireChildSet(JpsElementChildRole<T> role, T child) {
final JpsEventDispatcher eventDispatcher = getEventDispatcher();
if (eventDispatcher != null) {
eventDispatcher.fireElementAdded(child, role);
}
}
@Override
public <T extends JpsElement> void removeChild(@NotNull JpsElementChildRole<T> 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();
}
}

View File

@@ -67,10 +67,6 @@ public final class JpsElementCollectionImpl<E extends JpsElement> extends JpsEle
public <X extends E> 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<E extends JpsElement> 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);
}
}

View File

@@ -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

View File

@@ -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<Class<?>, EventDispatcher<?>> myDispatchers = new HashMap<>();
@NotNull
@Override
public <T extends EventListener> T getPublisher(Class<T> 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 <T extends JpsElement> void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole<T> role) {
role.fireElementAdded(this, element);
}
@Override
public <T extends JpsElement> void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole<T> role) {
role.fireElementRemoved(this, element);
}
}

View File

@@ -32,14 +32,14 @@ public final class JpsGlobalImpl extends JpsRootElementBase<JpsGlobalImpl> 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));
}

View File

@@ -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);

View File

@@ -32,8 +32,8 @@ public final class JpsProjectImpl extends JpsRootElementBase<JpsProjectImpl> 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<JpsProjectImpl> 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));
}

View File

@@ -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<E extends JpsRootElementBase<E>> extends JpsCompositeElementBase<E> {
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<E> original, JpsModel model, JpsEventDispatcher dispatcher) {
protected JpsRootElementBase(JpsCompositeElementBase<E> original, JpsModel model) {
super(original);
myModel = model;
myEventDispatcher = dispatcher;
}
@Override
protected JpsEventDispatcher getEventDispatcher() {
return myEventDispatcher;
}
@NotNull

View File

@@ -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<JpsLibrary> {
private static final JpsLibraryRole INSTANCE = new JpsLibraryRole();
@@ -15,14 +12,4 @@ public final class JpsLibraryRole extends JpsElementChildRoleBase<JpsLibrary> {
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);
}
}

View File

@@ -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<JpsLibraryRoot> {
@@ -30,16 +28,6 @@ public final class JpsLibraryRootRole extends JpsElementChildRoleBase<JpsLibrary
myRootType = rootType;
}
@Override
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRoot element) {
dispatcher.getPublisher(JpsLibraryRootListener.class).rootAdded(element);
}
@Override
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRoot element) {
dispatcher.getPublisher(JpsLibraryRootListener.class).rootRemoved(element);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@@ -1,13 +1,10 @@
// 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.JpsElementChildRole;
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.module.JpsModule;
import org.jetbrains.jps.model.module.JpsModuleListener;
public final class JpsModuleRole extends JpsElementChildRoleBase<JpsModule> {
private static final JpsElementChildRole<JpsModule> INSTANCE = new JpsModuleRole();
@@ -16,14 +13,4 @@ public final class JpsModuleRole extends JpsElementChildRoleBase<JpsModule> {
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);
}
}

View File

@@ -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<JpsModuleSourceRoot> {
private static final JpsModuleSourceRootRole INSTANCE = new JpsModuleSourceRootRole();
@@ -15,14 +12,4 @@ public final class JpsModuleSourceRootRole extends JpsElementChildRoleBase<JpsMo
private JpsModuleSourceRootRole() {
super("module source root");
}
@Override
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleSourceRoot element) {
dispatcher.getPublisher(JpsModuleSourceRootListener.class).sourceRootAdded(element);
}
@Override
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleSourceRoot element) {
dispatcher.getPublisher(JpsModuleSourceRootListener.class).sourceRootRemoved(element);
}
}

View File

@@ -34,13 +34,11 @@ public class JpsJavaExtensionTest extends JpsJavaModelTestCase {
}
public void testDependency() {
final JpsModel model = myModel.createModifiableModel(new TestJpsEventDispatcher());
final JpsModule module = model.getProject().addModule("m", JpsJavaModuleType.INSTANCE);
final JpsLibrary library = model.getProject().addLibrary("l", JpsJavaLibraryType.INSTANCE);
final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE);
final JpsLibrary library = myProject.addLibrary("l", JpsJavaLibraryType.INSTANCE);
final JpsLibraryDependency dependency = module.getDependenciesList().addLibraryDependency(library);
getJavaService().getOrCreateDependencyExtension(dependency).setScope(JpsJavaDependencyScope.TEST);
getJavaService().getOrCreateDependencyExtension(dependency).setExported(true);
model.commit();
List<JpsDependencyElement> dependencies = assertOneElement(myProject.getModules()).getDependenciesList().getDependencies();
assertEquals(2, dependencies.size());

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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<? extends JpsModuleSourceRoot> 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<JpsDependencyElement> 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);

View File

@@ -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<JpsElement> myAdded = new ArrayList<>();
private final List<JpsElement> myRemoved = new ArrayList<>();
private final List<JpsElement> myChanged = new ArrayList<>();
@Override
public <T extends JpsElement> void fireElementAdded(@NotNull T element, @NotNull JpsElementChildRole<T> role) {
super.fireElementAdded(element, role);
myAdded.add(element);
}
@Override
public <T extends JpsElement> void fireElementRemoved(@NotNull T element, @NotNull JpsElementChildRole<T> 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 <T extends JpsElement> List<T> retrieveAdded(Class<T> type) {
return retrieve(type, myAdded);
}
public <T extends JpsElement> List<T> retrieveRemoved(Class<T> type) {
return retrieve(type, myRemoved);
}
public <T extends JpsElement> List<T> retrieveChanged(Class<T> type) {
return retrieve(type, myChanged);
}
public void clear() {
myAdded.clear();
myRemoved.clear();
myChanged.clear();
}
private static <T extends JpsElement> List<T> retrieve(Class<T> type, List<JpsElement> list) {
final List<T> result = new ArrayList<>();
final Iterator<JpsElement> iterator = list.iterator();
while (iterator.hasNext()) {
JpsElement element = iterator.next();
if (type.isInstance(element)) {
result.add(type.cast(element));
iterator.remove();
}
}
return result;
}
}