Skip to content

Commit

Permalink
Merge pull request #29 from oroinc/ticket/OPP-75
Browse files Browse the repository at this point in the history
OPP-75: Replace methods, classes and constants marked for removal
  • Loading branch information
amosingiewicz committed Mar 4, 2024
2 parents 15dd353 + a1907ac commit b23d509
Show file tree
Hide file tree
Showing 55 changed files with 554 additions and 351 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.iml
build/
.idea-sandbox/
.DS_Store
.DS_Store
config/extra-settings.gradle.kts
47 changes: 42 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
plugins {
id("org.jetbrains.intellij") version "1.14.2"
id("groovy")
}


dependencies {
sourceSets.named("test") {
testImplementation("org.codehaus.groovy:groovy-all:2.4.14")
}
}

buildscript {
project.apply {
from("$rootDir/config/extra-settings.gradle.kts")
}
}

group = "com.oroplatform"
version = "2023.1"
version = "2023.2"

val javaLanguageVersionSetting = project.extra["javaLanguageVersionSetting"].toString()

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaLanguageVersionSetting))
}
}

intellij {
pluginName.set("idea-oroplatform-plugin")
type.set("IU")
version.set("2023.1")
version.set("2023.3.1")
plugins.set(listOf(
"com.jetbrains.php:231.8109.51",
"com.jetbrains.php:233.11799.297",
"yaml",
"java-i18n",
"properties",
"css-impl",
"JavaScript",
"com.jetbrains.twig:231.8109.78"
"com.jetbrains.twig:233.11799.297"
))
sandboxDir.set("${project.rootDir}/.idea-sandbox")
}
Expand All @@ -27,6 +49,21 @@ repositories {

tasks {
runIde {
ideDir.set(file("/home/michael/Programs/PhpStorm-231.8770.68"))
val pathToIde = project.extra["pathToIde"]
ideDir.set(file("$pathToIde"))
}
buildSearchableOptions {
enabled = true
}
test {
// OPP-80: The tests that target PHP code completion and JS completion
// or those that use the information no longer present in classes.php in the newer version of the platform
// are obsolete, as they assume that classes.php will store
// data required for indexing, hence they should be removed from tests
// Alek Mosingiewicz
setExcludes(listOf(
"*com/oroplatform/idea/oroplatform/intellij/codeAssist/javascript*",
"*com/oroplatform/idea/oroplatform/intellij/codeAssist/yml/v1/AclPhpReferenceTest*",
))
}
}
2 changes: 2 additions & 0 deletions config/extra-settings.gradle.kts.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val pathToIde by extra("/path/to/your/phpstorm/ide")
val javaLanguageVersionSetting by extra("17")
12 changes: 6 additions & 6 deletions src/main/java/com/oroplatform/idea/oroplatform/Icons.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.oroplatform.idea.oroplatform;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.RowIcon;
import com.jetbrains.php.PhpIcons;

import javax.swing.*;

public class Icons {
public static final Icon DOCTRINE = IconLoader.getIcon("icons/doctrine.png");
public static final Icon ROUTE = IconLoader.getIcon("icons/route.png");
public static final Icon ORO = IconLoader.getIcon("icons/oro.png");
public static final Icon DOCTRINE = IconLoader.getIcon("icons/doctrine.png", Icons.class);
public static final Icon ROUTE = IconLoader.getIcon("icons/route.png", Icons.class);
public static final Icon ORO = IconLoader.getIcon("icons/oro.png", Icons.class);
public static final Icon PUBLIC_METHOD;

static {
final RowIcon publicMethod = new RowIcon(2);
publicMethod.setIcon(PhpIcons.METHOD_ICON, 0);
publicMethod.setIcon(PhpIcons.PUBLIC_ICON, 1);
publicMethod.setIcon(AllIcons.Nodes.Method, 0);
publicMethod.setIcon(AllIcons.Nodes.Public, 1);

PUBLIC_METHOD = publicMethod;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.oroplatform.idea.oroplatform;

import com.intellij.AbstractBundle;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.PropertyKey;

Expand All @@ -10,6 +11,6 @@ public class OroPlatformBundle {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

public static String message(@PropertyKey(resourceBundle = BUNDLE_NAME) String key, Object... params) {
return CommonBundle.message(BUNDLE, key, params);
return AbstractBundle.message(BUNDLE, key, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import gnu.trove.THashSet;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ExtensionFileFilter implements VirtualFileFilter {
private final Set<String> extensions = new THashSet<>();
private final Set<String> extensions = new HashSet<>();

public ExtensionFileFilter(String... extensions) {
this.extensions.addAll(Arrays.asList(extensions));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
package com.oroplatform.idea.oroplatform.intellij;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.notification.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.oroplatform.idea.oroplatform.OroPlatformBundle;
import com.oroplatform.idea.oroplatform.settings.OroPlatformSettings;
import org.jetbrains.annotations.NotNull;

class OroNotifications {
private final static NotificationGroup GROUP = NotificationGroup.balloonGroup(OroPlatformBundle.message("notifications.group"));
private final static NotificationGroup GROUP = NotificationGroupManager
.getInstance()
.getNotificationGroup("Oro Notifications");

static void showPluginEnableNotification(@NotNull final Project project) {
final Notification notification = GROUP.createNotification(
OroPlatformBundle.message("notifications.enablePluginTitle"),
OroPlatformBundle.message("notifications.enablePlugin"),
NotificationType.INFORMATION,
(thisNotification, event) -> {
thisNotification.expire();
OroPlatformBundle.message("notifications.enablePluginTitle"),
OroPlatformBundle.message("notifications.enablePlugin"),
NotificationType.INFORMATION);

final OroPlatformSettings settings = OroPlatformSettings.getInstance(project);
final OroPlatformSettings settings = OroPlatformSettings.getInstance(project);

if("enable".equals(event.getDescription())) {
settings.setPluginEnabled(true);
showPluginEnabledNotification(project);
} else if("dismiss".equals(event.getDescription())) {
settings.setPluginEnableDismissed(true);
}
});
notification.addAction(new NotificationAction(OroPlatformBundle.message("notifications.enablePlugin.accept")) {
@Override
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
notification.expire();
settings.setPluginEnabled(true);
showPluginEnabledNotification(project);
}
});

notification.addAction(new NotificationAction(
OroPlatformBundle.message("notifications.enablePlugin.dismiss")) {
@Override
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
notification.expire();
settings.setPluginEnableDismissed(true);
}
});
Notifications.Bus.notify(notification, project);
}

private static void showPluginEnabledNotification(@NotNull final Project project) {
Notifications.Bus.notify(GROUP.createNotification(
OroPlatformBundle.message("notifications.group"),
OroPlatformBundle.message("notifications.pluginEnabled"),
NotificationType.INFORMATION, null
OroPlatformBundle.message("notifications.group"),
OroPlatformBundle.message("notifications.pluginEnabled"),
NotificationType.INFORMATION
), project);
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
package com.oroplatform.idea.oroplatform.intellij;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.startup.ProjectActivity;
import com.intellij.openapi.vfs.VfsUtil;
import com.oroplatform.idea.oroplatform.settings.OroPlatformSettings;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ProjectConfigurator implements ProjectComponent {

private final Project project;

public ProjectConfigurator(@NotNull Project project) {
this.project = project;
}
public class ProjectConfigurator implements ProjectActivity {

@Nullable
@Override
public void projectOpened() {
if(couldPluginBeEnabled()) {
public Object execute(@NotNull Project project, @NotNull Continuation<? super Unit> continuation) {
if(couldPluginBeEnabled(project)) {
OroNotifications.showPluginEnableNotification(project);
}
return continuation;
}

private boolean couldPluginBeEnabled() {
return isOroPlatformDetected() && OroPlatformSettings.getInstance(project).couldPluginBeEnabled();
}

private boolean isOroPlatformDetected() {
return VfsUtil.findRelativeFile(project.getBaseDir(), "vendor", "oro", "platform") != null ||
VfsUtil.findRelativeFile(project.getBaseDir(), "package", "platform", "src", "Oro") != null;
}

@Override
public void projectClosed() {

}

@Override
public void initComponent() {

private boolean couldPluginBeEnabled(@NotNull Project project) {
return isOroPlatformDetected(project) && OroPlatformSettings.getInstance(project).couldPluginBeEnabled();
}

@Override
public void disposeComponent() {

}

@NotNull
@Override
public String getComponentName() {
return "ProjectConfigurator";
private boolean isOroPlatformDetected(@NotNull Project project) {
return VfsUtil.findRelativeFile(ProjectUtil.guessProjectDir(project), "vendor", "oro", "platform") != null ||
VfsUtil.findRelativeFile(ProjectUtil.guessProjectDir(project), "package", "platform", "src", "Oro") != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class PhpMethodLookupElement extends PhpLookupElement {
private final Method method;

PhpMethodLookupElement(@NotNull Method method) {
super(getFQN(method), INDEX_KEY, method.getIcon(), null, method.getProject(), null);
super(method); // OPP-75: there's no default constructor, so choosing the least problematic solution
this.method = method;
this.lookupString = getFQN(method); // TODO FQN should come ideally from method itself, check why it's not the case
}

private static String getFQN(Method method) {
Expand All @@ -29,7 +30,7 @@ private static String getFQN(Method method) {
}

@Override
public void renderElement(LookupElementPresentation presentation) {
public void renderElement(@NotNull LookupElementPresentation presentation) {
super.renderElement(presentation);

final Collection<String> parameters = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ResourceReference(PsiElement element, String resourceName, String pattern

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
public ResolveResult @NotNull [] multiResolve(boolean incompleteCode) {
final String[] parts = StringUtil.trimStart(resourceName, "@").split("/|:");

return bundles.findAll().stream()
Expand All @@ -65,7 +65,7 @@ public ResolveResult[] multiResolve(boolean incompleteCode) {

@NotNull
@Override
public Object[] getVariants() {
public Object @NotNull [] getVariants() {
final String rootPath = StringUtil.trimStart(pathInResources.stream().collect(Collectors.joining("/")) + "/", "/");
return bundles.findAll().stream()
.flatMap(bundle ->
Expand Down

0 comments on commit b23d509

Please sign in to comment.