mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] @DelegatesTo provider API
This commit is contained in:
+2
-2
@@ -50,10 +50,10 @@ import static org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.GrDelegatesT
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class DefaultDelegatesToProvider {
|
||||
public class DefaultDelegatesToProvider implements GrDelegatesToProvider {
|
||||
|
||||
@Nullable
|
||||
public static DelegatesToInfo getDelegatesToInfo(@NotNull final GrClosableBlock closableBlock) {
|
||||
public DelegatesToInfo getDelegatesToInfo(@NotNull final GrClosableBlock closableBlock) {
|
||||
GrCall call = getContainingCall(closableBlock);
|
||||
if (call == null) return null;
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.plugins.groovy.lang.resolve.delegatesTo;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
|
||||
public interface GrDelegatesToProvider {
|
||||
|
||||
ExtensionPointName<GrDelegatesToProvider> EP_NAME = ExtensionPointName.create("org.intellij.groovy.delegatesToProvider");
|
||||
|
||||
@Nullable
|
||||
DelegatesToInfo getDelegatesToInfo(@NotNull GrClosableBlock closure);
|
||||
}
|
||||
+11
-1
@@ -16,9 +16,19 @@
|
||||
package org.jetbrains.plugins.groovy.lang.resolve.delegatesTo
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.util.CachedValueProvider.Result
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
|
||||
@JvmField val DELEGATES_TO_KEY = Key.create<String>("groovy.closure.delegatesTo.type")
|
||||
@JvmField val DELEGATES_TO_STRATEGY_KEY = Key.create<Int>("groovy.closure.delegatesTo.strategy")
|
||||
|
||||
fun getDelegatesToInfo(closure: GrClosableBlock): DelegatesToInfo? = DefaultDelegatesToProvider.getDelegatesToInfo(closure)
|
||||
fun getDelegatesToInfo(closure: GrClosableBlock): DelegatesToInfo? = CachedValuesManager.getCachedValue(closure) {
|
||||
Result.create(doGetDelegatesToInfo(closure), PsiModificationTracker.MODIFICATION_COUNT)
|
||||
}
|
||||
|
||||
private fun doGetDelegatesToInfo(closure: GrClosableBlock): DelegatesToInfo? {
|
||||
return GrDelegatesToProvider.EP_NAME.extensions.asSequence().mapNotNull { it.getDelegatesToInfo(closure) }.firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
<extensionPoint name="mvc.runCommandHandler" interface="org.jetbrains.plugins.groovy.mvc.actions.MvcRunCommandActionHandler"/>
|
||||
<extensionPoint name="gdslScriptProvider" interface="org.jetbrains.plugins.groovy.dsl.GdslScriptProvider"/>
|
||||
<extensionPoint name="expectedPackageNameProvider" interface="org.jetbrains.plugins.groovy.lang.resolve.ExpectedPackageNameProvider"/>
|
||||
<extensionPoint name="delegatesToProvider" interface="org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.GrDelegatesToProvider"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.intellij.groovy">
|
||||
@@ -248,6 +249,7 @@
|
||||
<expectedPackageNameProvider implementation="org.jetbrains.plugins.groovy.lang.resolve.DefaultExpectedPackageNameProvider"
|
||||
order="last"/>
|
||||
<importContributor implementation="org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor"/>
|
||||
<delegatesToProvider implementation="org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DefaultDelegatesToProvider" id="default"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.properties">
|
||||
|
||||
Reference in New Issue
Block a user