Skip to content

Commit

Permalink
#107 | Deprecated API - Diagrams & Impex
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Dec 23, 2022
1 parent 9ecbb5e commit 98276f8
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 55 deletions.
2 changes: 1 addition & 1 deletion resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ hybris.gutter.navigate.no.matching.populators=No matching populators found
hybris.gutter.populator.class.navigate.choose.class.title=Choose Populator
hybris.gutter.populator.class.tooltip.navigate.declaration=Navigate to the hybris populator

hybris.module.dependencies.diagram.provider.name=[y] Module Dependencies
hybris.module.dependencies.diagram.provider.name=[y] module dependencies

hybris.stats.permission.no=I disagree
hybris.scope.custom.ts.files=Custom Type System Files
Expand Down
2 changes: 2 additions & 0 deletions src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ object HybrisConstants {

const val NOTIFICATION_GROUP_HYBRIS = "[y] SAP Commerce Cloud"

const val IDEA_EDITION_ULTIMATE = "Ultimate Edition"

const val IMPEX_CONFIG_PREFIX = "\$config"
const val IMPEX_CONFIG_COMPLETE_PREFIX = "$IMPEX_CONFIG_PREFIX-"
const val IMPEX_CATALOG_VERSION_ONLINE = "Online"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public PsiFile createFile(FileViewProvider viewProvider) {
return new FlexibleSearchFile(viewProvider);
}

public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
@Override
@NotNull
public SpaceRequirements spaceExistenceTypeBetweenTokens(final ASTNode left, final ASTNode right) {
return SpaceRequirements.MAY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.intellij.application.options.CodeStyleAbstractPanel;
import com.intellij.application.options.TabbedLanguageCodeStylePanel;
import com.intellij.idea.plugin.hybris.flexibleSearch.FlexibleSearchLanguage;
import com.intellij.openapi.options.Configurable;
import com.intellij.psi.codeStyle.CodeStyleConfigurable;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
import com.intellij.psi.codeStyle.CustomCodeStyleSettings;
Expand All @@ -45,11 +45,12 @@ public String getConfigurableDisplayName() {

@NotNull
@Override
public Configurable createSettingsPage(final CodeStyleSettings settings, final CodeStyleSettings modelSettings) {
public CodeStyleConfigurable createConfigurable(final @NotNull CodeStyleSettings settings, final @NotNull CodeStyleSettings modelSettings) {
return new CodeStyleAbstractConfigurable(settings, modelSettings, "FlexibleSearch") {

@Override
protected CodeStyleAbstractPanel createPanel(final CodeStyleSettings settings) {
@NotNull
protected CodeStyleAbstractPanel createPanel(final @NotNull CodeStyleSettings settings) {
return new SimpleCodeStyleMainPanel(getCurrentSettings(), settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public static FlexibleSearchParserUtils.ErrorState get(PsiBuilder builder) {

public static void initState(FlexibleSearchParserUtils.ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
state.extendsSets = extendsSets;
PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
PsiFile file = builder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
Expand Down
7 changes: 5 additions & 2 deletions src/com/intellij/idea/plugin/hybris/impex/ImpexLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import com.intellij.idea.plugin.hybris.common.HybrisConstants;
import com.intellij.lang.Language;

import java.io.Serial;

public class ImpexLanguage extends Language {

private static final ImpexLanguage INSTANCE = new ImpexLanguage();
@Serial
private static final long serialVersionUID = -6312784074276675105L;
private static final Language INSTANCE = new ImpexLanguage();

public static ImpexLanguage getInstance() {
public static Language getInstance() {
return INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public PsiFile createFile(final FileViewProvider viewProvider) {

@NotNull
@Override
public SpaceRequirements spaceExistanceTypeBetweenTokens(final ASTNode left, final ASTNode right) {
public SpaceRequirements spaceExistenceTypeBetweenTokens(final ASTNode left, final ASTNode right) {
return SpaceRequirements.MAY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public String getConfigurableDisplayName() {
@NotNull
@Override
public CodeStyleConfigurable createConfigurable(@NotNull final CodeStyleSettings settings, @NotNull final CodeStyleSettings originalSettings) {

return new CodeStyleAbstractConfigurable(settings, originalSettings, HybrisConstants.IMPEX) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.intellij.idea.plugin.hybris.impex.psi.ImpexPsiNamedElement
import com.intellij.idea.plugin.hybris.impex.psi.references.ImpexMacrosReferenceBase
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReference
import com.intellij.psi.search.SearchScope
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.refactoring.rename.RenamePsiElementProcessor
Expand All @@ -38,10 +39,9 @@ class ImpexMacrosRenameProcessor : RenamePsiElementProcessor() {
return element is ImpexMacroNameDec || element is ImpexMacroUsageDec
}

override fun findReferences(element: PsiElement): MutableCollection<PsiReference?> {
override fun findReferences(element: PsiElement, searchScope: SearchScope, searchInCommentsAndStrings: Boolean): MutableCollection<PsiReference> {
val file = element.containingFile
val psiElements = PsiTreeUtil.collectElements(
file, { el -> (el is ImpexMacroNameDec || el is ImpexMacroUsageDec) && el.text == element.text })
val psiElements = PsiTreeUtil.collectElements(file) { el -> (el is ImpexMacroNameDec || el is ImpexMacroUsageDec) && el.text == element.text }

return psiElements.map { ImpexMacrosReferenceBase(it) }.toMutableList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.containers.Predicate;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -49,6 +48,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

/**
* Created 22:43 01 January 2015
Expand Down Expand Up @@ -167,7 +167,7 @@ public static PsiElement findSiblingByPredicate(
return null;
} else {
for (PsiElement child = sibling.getNextSibling(); child != null; child = child.getNextSibling()) {
if (predicate.apply(child)) {
if (predicate.test(child)) {
return child;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.intellij.idea.plugin.hybris.moduleDiagram;

import com.intellij.diagram.AbstractDiagramElementManager;
import com.intellij.diagram.presentation.DiagramState;
import com.intellij.diagram.DiagramBuilder;
import com.intellij.idea.plugin.hybris.actions.ActionUtils;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.ui.SimpleColoredText;
Expand Down Expand Up @@ -62,11 +62,14 @@ public String getElementTitle(final ModuleDepDiagramItem element) {
return element.toString();
}

@Nullable
@Override
public SimpleColoredText getItemName(final Object element, final DiagramState diagramState) {
return element instanceof ModuleDepDiagramItem
? new SimpleColoredText(((ModuleDepDiagramItem) element).getName(), DEFAULT_TITLE_ATTR)
public @Nullable SimpleColoredText getItemName(
@Nullable final ModuleDepDiagramItem nodeElement,
@Nullable final Object nodeItem,
@NotNull final DiagramBuilder builder
) {
return nodeElement != null
? new SimpleColoredText(nodeElement.getName(), DEFAULT_TITLE_ATTR)
: null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package com.intellij.idea.plugin.hybris.moduleDiagram;

import com.intellij.diagram.AbstractDiagramNodeContentManager;
import com.intellij.diagram.DiagramBuilder;
import com.intellij.diagram.DiagramCategory;
import com.intellij.diagram.presentation.DiagramState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author Eugene.Kudelevsky
Expand All @@ -29,9 +31,10 @@ public class ModuleDepDiagramNodeContentManager extends AbstractDiagramNodeConte

@Override
public boolean isInCategory(
final Object o,
final DiagramCategory diagramCategory,
final DiagramState diagramState
@Nullable final Object nodeElement,
@Nullable final Object item,
@NotNull final DiagramCategory category,
@Nullable final DiagramBuilder builder
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,56 @@ public String getID() {
}

@Override
@NotNull
public DiagramVisibilityManager createVisibilityManager() {
return new ModuleDepDiagramVisibilityManager();
}

@Override
public DiagramNodeContentManager getNodeContentManager() {
@NotNull
public DiagramNodeContentManager createNodeContentManager() {
return myNodeContentManager;
}

@Override
@NotNull
public DiagramElementManager<ModuleDepDiagramItem> getElementManager() {
return myElementManager;
}

@Override
@NotNull
public DiagramVfsResolver<ModuleDepDiagramItem> getVfsResolver() {
return myVfsResolver;
}

@Override
@NotNull
public DiagramColorManager getColorManager() {
return myColorManager;
}

@SuppressWarnings("unchecked")
@Override
@NotNull
public DiagramRelationshipManager<ModuleDepDiagramItem> getRelationshipManager() {
return (DiagramRelationshipManager<ModuleDepDiagramItem>) DiagramRelationshipManager.NO_RELATIONSHIP_MANAGER;
}

@Override
@NotNull
public String getPresentableName() {
return HybrisI18NBundleUtils.message("hybris.module.dependencies.diagram.provider.name");
}

@Override
@NotNull
public Icon getActionIcon(final boolean isPopup) {
return HybrisIcons.HYBRIS_ICON;
}

@Override
@NotNull
public DiagramDataModel<ModuleDepDiagramItem> createDataModel(
@NotNull final Project project,
@Nullable final ModuleDepDiagramItem item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public List<Module> commit(

final boolean[] finished = {false};

StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
StartupManager.getInstance(project).runAfterOpened(() -> {
finished[0] = true;

finishImport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class DebugRunConfigurationConfigurator implements RunConfigurationConfig

@Override
public void configure(
@NotNull final HybrisProjectDescriptor hybrisProjectDescriptor,
final HybrisProjectDescriptor hybrisProjectDescriptor,
@NotNull final Project project,
@NotNull final HybrisConfiguratorCache cache
final HybrisConfiguratorCache cache
) {

final RunManager runManager = RunManager.getInstance(project);
Expand All @@ -65,23 +65,24 @@ private void createRemoteDebug(
final RemoteConfigurationType remoteConfigurationType = ConfigurationTypeUtil.findConfigurationType(
RemoteConfigurationType.class);
final ConfigurationFactory configurationFactory = remoteConfigurationType.getConfigurationFactories()[0];
final String configurationName = HybrisI18NBundleUtils.message(
"hybris.project.import.run.configuration.remote.debug");
final String configurationName = HybrisI18NBundleUtils.message("hybris.project.import.run.configuration.remote.debug");

if (runManager.findConfigurationByName(configurationName) != null) {
return;
}
final RunnerAndConfigurationSettings runner = runManager.createRunConfiguration(
final RunnerAndConfigurationSettings runner = runManager.createConfiguration(
configurationName,
configurationFactory
);

final RemoteConfiguration remoteConfiguration = (RemoteConfiguration) runner.getConfiguration();
remoteConfiguration.PORT = getDebugPort(hybrisProjectDescriptor, cache);
remoteConfiguration.setAllowRunningInParallel(false);

ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
runner.setSingleton(true);
runner.setActivateToolWindowBeforeRun(true);
runManager.addConfiguration(runner, true);
runner.storeInDotIdeaFolder();
runManager.addConfiguration(runner);
runManager.setSelectedConfiguration(runner);
}));
}
Expand Down Expand Up @@ -129,7 +130,7 @@ private String findPortProperty(
final Optional<String> transport = Arrays.stream(debugOptions.split(" "))
.filter(e -> e.startsWith(HybrisConstants.X_RUNJDWP_TRANSPORT))
.findAny();
if (!transport.isPresent()) {
if (transport.isEmpty()) {
return null;
}
final Optional<String> address = Arrays.stream(transport.get().split(","))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,6 @@ private void removeMake(final Project project) {
final ConfigurationFactory configurationFactory = antRunConfigurationType.getConfigurationFactories()[0];
final RunnerAndConfigurationSettings template = runManager.getConfigurationTemplate(configurationFactory);
final AntRunConfiguration runConfiguration = (AntRunConfiguration) template.getConfiguration();
runManager.setBeforeRunTasks(runConfiguration, Collections.<BeforeRunTask>emptyList(), false);
runManager.setBeforeRunTasks(runConfiguration, Collections.<BeforeRunTask>emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void configure(

NamedScope defaultScope = customScope != null ? customScope : hybrisScope != null ? hybrisScope : platformScope;
if (defaultScope != null) {
FindSettings.getInstance().setCustomScope(defaultScope.getName());
FindSettings.getInstance().setDefaultScopeName(defaultScope.getName());
FindSettings.getInstance().setCustomScope(defaultScope.getPresentableName());
FindSettings.getInstance().setDefaultScopeName(defaultScope.getPresentableName());
}
}

Expand Down Expand Up @@ -139,18 +139,18 @@ public static PackageSet createCustomTsImpexBeansFilesPattern() {
impexFilePatternPackageSet);
}

private static void addOrReplaceScopes(@NotNull Project project, @NotNull List<NamedScope> newScopes) {
private static void addOrReplaceScopes(@NotNull final Project project, @NotNull final List<NamedScope> newScopes) {
final Set<String> newScopeNames = newScopes
.stream()
.map(NamedScope::getName)
.map(NamedScope::getPresentableName)
.collect(Collectors.toSet());

final NamedScopeManager namedScopeManager = NamedScopeManager.getInstance(project);
final NamedScope[] existingScopes = namedScopeManager.getEditableScopes();

final NamedScope[] filteredScopes = Arrays
.stream(existingScopes)
.filter(it -> !newScopeNames.contains(it.getName()))
.filter(it -> !newScopeNames.contains(it.getPresentableName()))
.toArray(NamedScope[]::new);

namedScopeManager.setScopes(ArrayUtil.mergeArrays(
Expand All @@ -159,7 +159,7 @@ private static void addOrReplaceScopes(@NotNull Project project, @NotNull List<N
));
}

private static boolean groupExists(@NotNull ModifiableModuleModel model, final String groupName) {
private static boolean groupExists(@NotNull final ModifiableModuleModel model, final String groupName) {
return Arrays
.stream(model.getModules())
.map(model::getModuleGroupPath)
Expand All @@ -172,7 +172,7 @@ private static NamedScope createScope(@NotNull final String groupName) {
SEARCH_SCOPE_GROUP_PREFIX + groupName,
"*//*"
);
return new NamedScope(SEARCH_SCOPE_Y_PREFIX + " " + groupName, filePatternPackageSet);
return new NamedScope(SEARCH_SCOPE_Y_PREFIX + ' ' + groupName, filePatternPackageSet);
}

@NotNull
Expand All @@ -190,7 +190,7 @@ private static NamedScope createScopeFor2Groups(@NotNull final String firstGroup
secondFilePatternPackageSet
);
return new NamedScope(
SEARCH_SCOPE_Y_PREFIX + " " + firstGroupName + " " + secondGroupName,
SEARCH_SCOPE_Y_PREFIX + ' ' + firstGroupName + ' ' + secondGroupName,
unionPackageSet
);
}
Expand Down
Loading

0 comments on commit 98276f8

Please sign in to comment.