From a6fba129195c1b9da63214a866387b76db92208c Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 19 May 2017 18:06:11 +0300 Subject: [PATCH 1/4] platform: always load some commonly used Kotlin stdlib classes by platform classloader This is needed to allow using methods with these classes in API (IDEA-171552). --- .../intellij/ide/plugins/cl/PluginClassLoader.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java index d965b2723079..34c220c83abf 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java +++ b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java @@ -91,10 +91,13 @@ public class PluginClassLoader extends UrlClassLoader { } private static boolean mustBeLoadedByPlatform(String className) { - //FunctionX interfaces from kotlin-runtime must be loaded by the platform classloader. Otherwise if a plugin bundles its own version - // of kotlin-runtime.jar it won't be possible to call platform's methods with Kotlin functional types in signatures from such a plugin. - //We assume that FunctionX interfaces don't change between Kotlin versions so it's safe to always load them from platform's kotlin-runtime. - return className.startsWith("kotlin.jvm.functions."); + //some commonly used classes from kotlin-runtime must be loaded by the platform classloader. Otherwise if a plugin bundles its own version + // of kotlin-runtime.jar it won't be possible to call platform's methods with these types in signatures from such a plugin. + //We assume that these classes don't change between Kotlin versions so it's safe to always load them from platform's kotlin-runtime. + return className.startsWith("kotlin.") && (className.startsWith("kotlin.jvm.functions.") + || className.equals("kotlin.sequences.Sequence") + || className.equals("kotlin.Pair") + || className.equals("kotlin.Triple")); } @Nullable From c8c1b7497e803e16c389b78c60370de3f2337cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Fri, 19 May 2017 17:07:33 +0200 Subject: [PATCH 2/4] IDEA-170276 DevKit: "Component type mismatch" should allow non-inheritors --- .../RegistrationProblemsInspection.java | 37 ++++++++----------- ...=> ApplicationComponentMustNotInherit.xml} | 0 .../MyApplicationComponentMustNotInherit.java | 1 + .../MyApplicationComponentWrongClass.java | 1 - ...egistrationProblemsInspectionCodeTest.java | 6 +-- 5 files changed, 20 insertions(+), 25 deletions(-) rename plugins/devkit/testData/inspections/registrationProblems/code/{ApplicationComponentWrongClass.xml => ApplicationComponentMustNotInherit.xml} (100%) create mode 100644 plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentMustNotInherit.java delete mode 100644 plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentWrongClass.java diff --git a/plugins/devkit/src/inspections/RegistrationProblemsInspection.java b/plugins/devkit/src/inspections/RegistrationProblemsInspection.java index f37675ba82db..b288812eb227 100644 --- a/plugins/devkit/src/inspections/RegistrationProblemsInspection.java +++ b/plugins/devkit/src/inspections/RegistrationProblemsInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -112,17 +112,17 @@ public class RegistrationProblemsInspection extends DevKitInspectionBase { final PsiIdentifier nameIdentifier = checkedClass.getNameIdentifier(); if (CHECK_JAVA_CODE && - nameIdentifier != null && - checkedClass.getQualifiedName() != null && - checkedClass.getContainingFile().getVirtualFile() != null) - { + nameIdentifier != null && + checkedClass.getQualifiedName() != null && + checkedClass.getContainingFile().getVirtualFile() != null) { final Set componentClasses = RegistrationCheckerUtil.getRegistrationTypes(checkedClass, CHECK_ACTIONS); if (componentClasses != null && !componentClasses.isEmpty()) { - List problems = null; + List problems = new SmartList<>(); for (PsiClass compClass : componentClasses) { - if (!checkedClass.isInheritor(compClass, true)) { - problems = addProblem(problems, manager.createProblemDescriptor(nameIdentifier, + if (ActionType.ACTION.myClassName.equals(compClass.getQualifiedName()) && + !checkedClass.isInheritor(compClass, true)) { + problems.add(manager.createProblemDescriptor(nameIdentifier, DevKitBundle.message("inspections.registration.problems.incompatible.message", compClass.isInterface() ? DevKitBundle.message("keyword.implement") : @@ -133,28 +133,23 @@ public class RegistrationProblemsInspection extends DevKitInspectionBase { } if (ActionType.ACTION.isOfType(checkedClass)) { if (ConstructorType.getNoArgCtor(checkedClass) == null) { - problems = addProblem(problems, manager.createProblemDescriptor(nameIdentifier, - DevKitBundle.message("inspections.registration.problems.missing.noarg.ctor"), - new CreateConstructorFix(checkedClass, isOnTheFly), - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly)); + problems.add(manager.createProblemDescriptor(nameIdentifier, + DevKitBundle.message("inspections.registration.problems.missing.noarg.ctor"), + new CreateConstructorFix(checkedClass, isOnTheFly), + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly)); } } if (isAbstract(checkedClass)) { - problems = addProblem(problems, manager.createProblemDescriptor(nameIdentifier, - DevKitBundle.message("inspections.registration.problems.abstract"), isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)); + problems.add(manager.createProblemDescriptor(nameIdentifier, + DevKitBundle.message("inspections.registration.problems.abstract"), isOnTheFly, + LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)); } - return problems != null ? problems.toArray(new ProblemDescriptor[problems.size()]) : null; + return ArrayUtil.toObjectArray(problems, ProblemDescriptor.class); } } return null; } - private static List addProblem(List problems, ProblemDescriptor problemDescriptor) { - if (problems == null) problems = new SmartList<>(); - problems.add(problemDescriptor); - return problems; - } - @Nullable private static ProblemDescriptor[] checkPluginXml(XmlFile xmlFile, InspectionManager manager, boolean isOnTheFly) { final XmlDocument document = xmlFile.getDocument(); diff --git a/plugins/devkit/testData/inspections/registrationProblems/code/ApplicationComponentWrongClass.xml b/plugins/devkit/testData/inspections/registrationProblems/code/ApplicationComponentMustNotInherit.xml similarity index 100% rename from plugins/devkit/testData/inspections/registrationProblems/code/ApplicationComponentWrongClass.xml rename to plugins/devkit/testData/inspections/registrationProblems/code/ApplicationComponentMustNotInherit.xml diff --git a/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentMustNotInherit.java b/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentMustNotInherit.java new file mode 100644 index 000000000000..620a2f0a0fe2 --- /dev/null +++ b/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentMustNotInherit.java @@ -0,0 +1 @@ +public class MyApplicationComponentMustNotInherit {} \ No newline at end of file diff --git a/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentWrongClass.java b/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentWrongClass.java deleted file mode 100644 index 21f7577a2c98..000000000000 --- a/plugins/devkit/testData/inspections/registrationProblems/code/MyApplicationComponentWrongClass.java +++ /dev/null @@ -1 +0,0 @@ -public class MyApplicationComponentWrongClass {} \ No newline at end of file diff --git a/plugins/devkit/testSources/inspections/RegistrationProblemsInspectionCodeTest.java b/plugins/devkit/testSources/inspections/RegistrationProblemsInspectionCodeTest.java index ab4439905551..446400d688c1 100644 --- a/plugins/devkit/testSources/inspections/RegistrationProblemsInspectionCodeTest.java +++ b/plugins/devkit/testSources/inspections/RegistrationProblemsInspectionCodeTest.java @@ -42,9 +42,9 @@ public class RegistrationProblemsInspectionCodeTest extends PluginModuleTestCase myFixture.testHighlighting("AbstractApplicationComponent.java"); } - public void testComponentWrongClass() { - setPluginXml("ApplicationComponentWrongClass.xml"); - myFixture.testHighlighting("MyApplicationComponentWrongClass.java"); + public void testApplicationComponentMustNotInherit() { + setPluginXml("ApplicationComponentMustNotInherit.xml"); + myFixture.testHighlighting("MyApplicationComponentMustNotInherit.java"); } public void testActionAbstractClass() { From bfb19beef0c24345d694829d66e1e6ef5180fc49 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 19 May 2017 17:11:59 +0200 Subject: [PATCH 3/4] removed privileged action wrapper --- .../intellij/util/io/DirectBufferWrapper.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/DirectBufferWrapper.java b/platform/util/src/com/intellij/util/io/DirectBufferWrapper.java index f87c70f826e7..db4b89c7ba75 100644 --- a/platform/util/src/com/intellij/util/io/DirectBufferWrapper.java +++ b/platform/util/src/com/intellij/util/io/DirectBufferWrapper.java @@ -83,19 +83,13 @@ abstract class DirectBufferWrapper extends ByteBufferWrapper { throw new RuntimeException(e); } } - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - @Nullable - public Object run() { - try { - Cleaner cleaner = ((DirectBuffer)buffer).cleaner(); - if (cleaner != null) cleaner.clean(); // Already cleaned otherwise - return null; - } - catch (Throwable e) { - return buffer; - } - } - }) == null; + try { + Cleaner cleaner = ((DirectBuffer)buffer).cleaner(); + if (cleaner != null) cleaner.clean(); // Already cleaned otherwise + return true; + } + catch (Throwable e) { + return false; + } } } From 27ab0796188ceff76aaa0f3f63b487ea9bfde141 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 19 May 2017 18:17:42 +0300 Subject: [PATCH 4/4] PY-24302: Set module explicitly for newly created configurations There could be more than one module, so we need to take it from context --- python/src/com/jetbrains/python/testing/PyTestsShared.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/python/src/com/jetbrains/python/testing/PyTestsShared.kt b/python/src/com/jetbrains/python/testing/PyTestsShared.kt index 578a168567e2..27bc2f301f28 100644 --- a/python/src/com/jetbrains/python/testing/PyTestsShared.kt +++ b/python/src/com/jetbrains/python/testing/PyTestsShared.kt @@ -613,6 +613,7 @@ object PyTestsConfigurationProducer : com.jetbrains.python.testing.AbstractPytho configuration.workingDirectory = targetForConfig.second } } + configuration.module = context?.module configuration.setGeneratedName() return true }