consulo.roots.impl.ModuleRootLayerImpl Java Examples

The following examples show how to use consulo.roots.impl.ModuleRootLayerImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrderEntrySerializationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static OrderEntry loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) {
  String type = element.getAttributeValue(ORDER_ENTRY_TYPE_ATTR);
  if(type == null) {
    return null;
  }
  OrderEntryType orderEntryType = getProvidersAsMap().get(type);
  if(orderEntryType == null) {
    return new UnknownOrderEntryImpl(new UnknownOrderEntryType(type, element), (ModuleRootLayerImpl)moduleRootLayer);
  }

  try {
    return orderEntryType.loadOrderEntry(element, moduleRootLayer);
  }
  catch (InvalidDataException e) {
    return new UnknownOrderEntryImpl(new UnknownOrderEntryType(type, element), (ModuleRootLayerImpl)moduleRootLayer);
  }
}
 
Example #2
Source File: LibraryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private LibraryImpl(@Nonnull LibraryImpl from, LibraryImpl newSource, ModuleRootLayerImpl rootModel) {
  this(from.myLibraryTable, rootModel, newSource, from.myName, from.myKind);
  from.checkDisposed();

  if (from.myKind != null && from.myProperties != null) {
    myProperties = myKind.createDefaultProperties();
    Object state = from.myProperties.getState();
    if (state != null) {
      //noinspection unchecked
      myProperties.loadState(state);
    }
  }
  for (OrderRootType rootType : getAllRootTypes()) {
    final VirtualFilePointerContainer thatContainer = from.myRoots.get(rootType);
    if (thatContainer != null && !thatContainer.isEmpty()) {
      getOrCreateContainer(rootType).addAll(thatContainer);
    }
  }
  if (from.myExcludedRoots != null) {
    myExcludedRoots = from.myExcludedRoots.clone(myPointersDisposable);
  }
}
 
Example #3
Source File: RootModelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private void loadState(Element element, @Nullable ProgressIndicator progressIndicator) {
  String currentLayer = element.getAttributeValue("current-layer");
  if (currentLayer != null) {
    setCurrentLayerSafe(currentLayer);

    for (Element moduleLayerElement : element.getChildren("module-layer")) {
      String name = moduleLayerElement.getAttributeValue("name");

      ModuleRootLayerImpl moduleRootLayer = new ModuleRootLayerImpl(null, this);
      moduleRootLayer.loadState(moduleLayerElement, progressIndicator);

      ModuleRootLayerImpl layer = myLayers.put(name, moduleRootLayer);
      if (layer != null) {
        // dispose old layout
        Disposer.dispose(layer);
      }
    }
  }

  // old format - create default profile and load it
  if (myLayers.isEmpty()) {
    initDefaultLayer(element);
  }
}
 
Example #4
Source File: RootModelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public ModifiableModuleRootLayer addLayer(@Nonnull String name, @Nullable String nameForCopy, boolean activate) {
  ModuleRootLayerImpl moduleRootLayer = myLayers.get(name);
  if (moduleRootLayer != null) {
    return moduleRootLayer;
  }

  ModuleRootLayerImpl layer = new ModuleRootLayerImpl(null, this);

  if (nameForCopy != null) {
    ModuleRootLayerImpl original = myLayers.get(nameForCopy);
    if (original != null) {
      original.copy(layer, false);
    }
  }
  myLayers.put(name, layer);
  if (activate) {
    setCurrentLayerSafe(name);
  }
  return layer;
}
 
Example #5
Source File: RootModelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean removeLayer(@Nonnull String name, boolean initDefault) {
  assertWritable();
  ModuleRootLayerImpl removedLayer = myLayers.remove(name);
  if (removedLayer != null) {
    Disposer.dispose(removedLayer);

    if (initDefault && myLayers.isEmpty()) {
      initDefaultLayer(null);
    }

    if (Comparing.equal(myCurrentLayerName, name)) {
      setCurrentLayerSafe(myLayers.isEmpty() ? null : ContainerUtil.getFirstItem(myLayers.keySet()));
    }
  }
  return removedLayer != null;
}
 
Example #6
Source File: RootModelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAllLayers(boolean initDefault) {
  assertWritable();

  for (ModuleRootLayerImpl layer : myLayers.values()) {
    Disposer.dispose(layer);
  }
  myLayers.clear();

  if (initDefault) {
    initDefaultLayer(null);
  }
  else {
    setCurrentLayerSafe(null);
  }
}
 
Example #7
Source File: AddUsingAction.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
private void execute0(final NamespaceReference namespaceReference)
{
	PsiDocumentManager.getInstance(myProject).commitAllDocuments();

	WriteCommandAction.runWriteCommandAction(myProject, () ->
	{
		addUsing(namespaceReference.getNamespace());

		String libraryName = namespaceReference.getLibraryName();
		if(libraryName != null)
		{
			Module moduleForFile = ModuleUtilCore.findModuleForPsiElement(myFile);
			if(moduleForFile != null)
			{
				ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForFile);

				final ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel();

				modifiableModel.addOrderEntry(new DotNetLibraryOrderEntryImpl((ModuleRootLayerImpl) moduleRootManager.getCurrentLayer(), libraryName));

				WriteAction.run(modifiableModel::commit);
			}
		}
	});
}
 
Example #8
Source File: Unity3dProjectImportUtil.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
private static void addAsLibrary(VirtualFile virtualFile, ModuleRootLayerImpl layer)
{
	if(virtualFile.getFileType() == DotNetModuleFileType.INSTANCE)
	{
		VirtualFile archiveRootForLocalFile = ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile);
		if(archiveRootForLocalFile != null)
		{
			Library library = layer.getModuleLibraryTable().createLibrary();
			Library.ModifiableModel modifiableModel = library.getModifiableModel();
			modifiableModel.addRoot(archiveRootForLocalFile, BinariesOrderRootType.getInstance());
			VirtualFile docFile = virtualFile.getParent().findChild(virtualFile.getNameWithoutExtension() + ".xml");
			if(docFile != null)
			{
				modifiableModel.addRoot(docFile, DocumentationOrderRootType.getInstance());
			}
			modifiableModel.commit();

			LibraryOrderEntry libraryOrderEntry = layer.findLibraryOrderEntry(library);
			assert libraryOrderEntry != null;
			libraryOrderEntry.setExported(true);
		}
	}
}
 
Example #9
Source File: LibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LibraryOrderEntryImpl(@Nonnull String name,
                             @Nonnull String level,
                             @Nonnull ModuleRootLayerImpl rootLayer,
                             DependencyScope dependencyScope,
                             boolean exported,
                             boolean init) {
  super(LibraryOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
  myScope = dependencyScope;
  myExported = exported;
  searchForLibrary(name, level);
  addListeners();
  if(init) {
    init();
  }
}
 
Example #10
Source File: LibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private LibraryOrderEntryImpl(@Nonnull LibraryOrderEntryImpl that, @Nonnull ModuleRootLayerImpl rootLayer) {
  super(LibraryOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
  if (that.myLibrary == null) {
    myLibraryName = that.myLibraryName;
    myLibraryLevel = that.myLibraryLevel;
  }
  else {
    myLibrary = that.myLibrary;
  }
  myExported = that.myExported;
  myScope = that.myScope;
  addListeners();
  init();
}
 
Example #11
Source File: LibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LibraryOrderEntryImpl(@Nonnull Library library, @Nonnull ModuleRootLayerImpl rootLayer) {
  super(LibraryOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
  LOGGER.assertTrue(library.getTable() != null);
  myLibrary = library;
  addListeners();
  init();
}
 
Example #12
Source File: ModuleOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModuleOrderEntryImpl(@Nonnull String moduleName, @Nonnull ModuleRootLayerImpl rootLayer, @Nonnull DependencyScope dependencyScope, boolean exported,
                            boolean productionOnTestDependency) {
  super(ModuleOrderEntryType.getInstance(), rootLayer);
  myModulePointer = ModuleUtilCore.createPointer(rootLayer.getProject(), moduleName);
  myScope = dependencyScope;
  myExported = exported;
  myProductionOnTestDependency = productionOnTestDependency;
}
 
Example #13
Source File: Unity3dPackageOrderEntryType.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Unity3dPackageOrderEntry loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException
{
	String name = element.getAttributeValue("name");
	return new Unity3dPackageOrderEntry((ModuleRootLayerImpl) moduleRootLayer, name);
}
 
Example #14
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public ModifiableModuleRootLayer setCurrentLayer(@Nonnull String name) {
  assertWritable();
  ModuleRootLayerImpl moduleRootLayer = myLayers.get(name);
  if (moduleRootLayer == null) {
    return null;
  }
  myCurrentLayerName = name;
  myCachedCurrentLayer = moduleRootLayer;
  return moduleRootLayer;
}
 
Example #15
Source File: ModuleOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ModuleOrderEntryImpl(ModuleOrderEntryImpl that, ModuleRootLayerImpl rootLayer) {
  super(ModuleOrderEntryType.getInstance(), rootLayer);
  final NamedPointer<Module> thatModule = that.myModulePointer;
  myModulePointer = ModuleUtilCore.createPointer(rootLayer.getProject(), thatModule.getName());
  myExported = that.myExported;
  myProductionOnTestDependency = that.myProductionOnTestDependency;
  myScope = that.myScope;
}
 
Example #16
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ModuleRootLayerImpl getCurrentLayer() {
  if (myCachedCurrentLayer != null) {
    return myCachedCurrentLayer;
  }
  ModuleRootLayerImpl moduleRootLayer = myLayers.get(myCurrentLayerName);
  LOGGER.assertTrue(moduleRootLayer != null);
  return myCachedCurrentLayer = moduleRootLayer;
}
 
Example #17
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean isChanged() {
  if (!myWritable) return false;

  RootModelImpl sourceModel = getSourceModel();

  if (!Comparing.equal(myCurrentLayerName, sourceModel.myCurrentLayerName)) {
    return true;
  }

  for (Map.Entry<String, ModuleRootLayerImpl> entry : myLayers.entrySet()) {
    ModuleRootLayerImpl sourceLayer = sourceModel.myLayers.get(entry.getKey());
    // new layer
    if (sourceLayer == null) {
      return true;
    }

    if (entry.getValue().isChanged(sourceLayer)) {
      return true;
    }
  }
  // check for deleted layers
  for (String layerName : sourceModel.myLayers.keySet()) {
    ModuleRootLayerImpl layer = myLayers.get(layerName);
    if (layer == null) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void putState(Element parent) {
  parent.setAttribute("current-layer", myCurrentLayerName);

  for (Map.Entry<String, ModuleRootLayerImpl> entry : myLayers.entrySet()) {
    Element element = new Element("module-layer");
    element.setAttribute("name", entry.getKey());

    entry.getValue().writeExternal(element);

    parent.addContent(element);
  }
}
 
Example #19
Source File: ModuleLibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModuleLibraryOrderEntryImpl(Library library, ModuleRootLayerImpl rootLayer, boolean isExported, DependencyScope scope, boolean init) {
  super(ModuleLibraryOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
  myLibrary = library;
  myExported = isExported;
  myScope = scope;
  Disposer.register(this, myLibrary);
  if (init) {
    init();
  }
}
 
Example #20
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private void initDefaultLayer(Element element) {
  setCurrentLayerSafe(DEFAULT_LAYER_NAME);

  ModuleRootLayerImpl moduleRootLayer = new ModuleRootLayerImpl(null, this);
  myLayers.put(myCurrentLayerName, moduleRootLayer);

  if (element != null) {
    moduleRootLayer.loadState(element, null);
  }
}
 
Example #21
Source File: RootModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
RootModelImpl(@Nonnull RootModelImpl rootModel, @Nonnull ModuleRootManagerImpl moduleRootManager, @Nonnull RootConfigurationAccessor rootConfigurationAccessor) {
  myModuleRootManager = moduleRootManager;
  myWritable = true;
  myConfigurationAccessor = rootConfigurationAccessor;

  myLayers.clear();
  for (Map.Entry<String, ModuleRootLayerImpl> entry : rootModel.myLayers.entrySet()) {
    ModuleRootLayerImpl moduleRootLayer = new ModuleRootLayerImpl(entry.getValue(), this);
    myLayers.put(entry.getKey(), moduleRootLayer);
  }
  setCurrentLayerSafe(rootModel.myCurrentLayerName);
}
 
Example #22
Source File: LibraryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private LibraryImpl(LibraryTable table, @Nullable ModuleRootLayerImpl rootModel, LibraryImpl newSource, String name, @Nullable PersistentLibraryKind<?> kind) {
  myTraceableDisposable = TraceableDisposable.newTraceDisposable(true);
  myLibraryTable = table;
  myRootModel = rootModel;
  mySource = newSource;
  myKind = kind;
  myName = name;
  Disposer.register(this, myPointersDisposable);
}
 
Example #23
Source File: ContentEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public ContentEntry cloneEntry(@Nonnull ModuleRootLayerImpl rootModel) {
  assert !isDisposed();

  ContentEntryImpl cloned = new ContentEntryImpl(myRoot.getUrl(), rootModel);
  for (ContentFolder contentFolder : myContentFolders) {
    if (contentFolder instanceof ClonableContentFolder) {
      ContentFolderImpl folder = (ContentFolderImpl)((ClonableContentFolder)contentFolder).cloneFolder(cloned);
      cloned.addFolder(folder);
    }
  }

  return cloned;
}
 
Example #24
Source File: ContentEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ContentEntryImpl(@Nonnull Element e, @Nonnull ModuleRootLayerImpl m) {
  this(getUrlFrom(e), m);

  for (Element child : e.getChildren(ContentFolderImpl.ELEMENT_NAME)) {
    myContentFolders.add(new ContentFolderImpl(child, this));
  }
}
 
Example #25
Source File: ModuleExtensionWithSdkOrderEntryType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ModuleExtensionWithSdkOrderEntryImpl loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException {
  String moduleExtensionId = element.getAttributeValue(EXTENSION_ID_ATTRIBUTE);
  if (moduleExtensionId == null) {
    throw new InvalidDataException();
  }
  return new ModuleExtensionWithSdkOrderEntryImpl(moduleExtensionId, (ModuleRootLayerImpl)moduleRootLayer, false);
}
 
Example #26
Source File: Unity3dPackageOrderEntry.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
public Unity3dPackageOrderEntry(@Nonnull ModuleRootLayerImpl rootLayer, String nameWithVersion, boolean init)
{
	super(Unity3dPackageOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
	myNameWithVersion = nameWithVersion;
	if(init)
	{
		init();

		myProjectRootManagerImpl.addOrderWithTracking(this);
	}
}
 
Example #27
Source File: LibraryOrderEntryType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public LibraryOrderEntryImpl loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException {
  String name = element.getAttributeValue(NAME_ATTR);
  if (name == null) {
    throw new InvalidDataException();
  }

  String level = element.getAttributeValue(LEVEL_ATTR, LibraryTablesRegistrar.PROJECT_LEVEL);
  DependencyScope dependencyScope = DependencyScope.readExternal(element);
  boolean exported = element.getAttributeValue(EXPORTED_ATTR) != null;
  return new LibraryOrderEntryImpl(name, level, (ModuleRootLayerImpl)moduleRootLayer, dependencyScope, exported, false);
}
 
Example #28
Source File: ModuleExtensionWithSdkOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModuleExtensionWithSdkOrderEntryImpl(@Nonnull String moduleExtensionId, @Nonnull ModuleRootLayerImpl rootModel, boolean init) {
  super(ModuleExtensionWithSdkOrderEntryType.getInstance(), rootModel, ProjectRootManagerImpl.getInstanceImpl(rootModel.getProject()));
  myModuleExtensionId = moduleExtensionId;
  if (init) {
    init();

    myProjectRootManagerImpl.addOrderWithTracking(this);
  }
}
 
Example #29
Source File: ModuleOrderEntryType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ModuleOrderEntryImpl loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException {
  String moduleName = element.getAttributeValue(MODULE_NAME_ATTR);
  if (moduleName == null) {
    throw new InvalidDataException();
  }
  DependencyScope dependencyScope = DependencyScope.readExternal(element);
  boolean exported = element.getAttributeValue(EXPORTED_ATTR) != null;
  boolean productionOnTestDependency = element.getAttributeValue(PRODUCTION_ON_TEST_ATTRIBUTE) != null;
  return new ModuleOrderEntryImpl(moduleName, (ModuleRootLayerImpl)moduleRootLayer, dependencyScope, exported, productionOnTestDependency);
}
 
Example #30
Source File: ModuleLibraryOrderEntryType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ModuleLibraryOrderEntryImpl loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException {
  boolean exported = element.getAttributeValue(EXPORTED_ATTR) != null;
  DependencyScope scope = DependencyScope.readExternal(element);
  Library library = LibraryTableImplUtil.loadLibrary(element, (ModuleRootLayerImpl)moduleRootLayer);
  return new ModuleLibraryOrderEntryImpl(library, (ModuleRootLayerImpl)moduleRootLayer, exported, scope, false);
}