mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-50450 Gradle code insight
Basic gradle code insight infrastructure
This commit is contained in:
@@ -61,6 +61,12 @@
|
||||
<scriptTypeDetector implementation="org.jetbrains.plugins.gradle.config.GradleScriptTypeDetector"/>
|
||||
<defaultImportContributor implementation="org.jetbrains.plugins.gradle.config.GradleDefaultImportContributor"/>
|
||||
<groovyFrameworkConfigNotification implementation="org.jetbrains.plugins.gradle.config.GradleGroovyConfigNotification"/>
|
||||
|
||||
<membersContributor implementation="org.jetbrains.plugins.gradle.service.resolve.GradleScriptContributor"/>
|
||||
<methodDescriptor class="org.gradle.api.Project"
|
||||
name="apply"
|
||||
namedArgsProvider="org.jetbrains.plugins.gradle.service.resolve.GradleProjectApplyArgsProvider"/>
|
||||
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.gradle.service.resolve;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider;
|
||||
import org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 7/23/13 5:53 PM
|
||||
*/
|
||||
public class GradleProjectApplyArgsProvider extends GroovyNamedArgumentProvider {
|
||||
|
||||
@Override
|
||||
public void getNamedArguments(@NotNull GrCall call,
|
||||
@Nullable PsiElement resolve,
|
||||
@Nullable String argumentName,
|
||||
boolean forCompletion,
|
||||
Map<String, NamedArgumentDescriptor> result)
|
||||
{
|
||||
result.put("plugin", new NamedArgumentDescriptor());
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.gradle.service.resolve;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 7/23/13 4:21 PM
|
||||
*/
|
||||
public class GradleScriptContributor extends NonCodeMembersContributor {
|
||||
|
||||
// TODO den add doc
|
||||
@NotNull private static final Map<String, String> CONTRIBUTORS = ContainerUtilRt.newHashMap();
|
||||
static {
|
||||
CONTRIBUTORS.put("repositories", "org.gradle.api.artifacts.dsl.RepositoryHandler");
|
||||
CONTRIBUTORS.put("dependencies", "org.gradle.api.artifacts.dsl.DependencyHandler");
|
||||
}
|
||||
|
||||
@NotNull @NonNls private static final String ROOT_CONTRIBUTOR_CLASS_NAME = "org.gradle.api.Project";
|
||||
|
||||
@Override
|
||||
public void processDynamicElements(@NotNull PsiType qualifierType,
|
||||
PsiClass aClass,
|
||||
PsiScopeProcessor processor,
|
||||
PsiElement place,
|
||||
ResolveState state) {
|
||||
if (place == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(aClass instanceof GroovyScriptClass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiFile file = aClass.getContainingFile();
|
||||
if (file == null || !file.getName().endsWith(GradleConstants.EXTENSION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GroovyPsiManager psiManager = GroovyPsiManager.getInstance(aClass.getProject());
|
||||
String contributorClassName = ROOT_CONTRIBUTOR_CLASS_NAME;
|
||||
for (GrMethodCall current = PsiTreeUtil.getParentOfType(place, GrMethodCall.class);
|
||||
current != null;
|
||||
current = PsiTreeUtil.getParentOfType(current, GrMethodCall.class))
|
||||
{
|
||||
GrExpression expression = current.getInvokedExpression();
|
||||
if (expression != null) {
|
||||
String text = expression.getText();
|
||||
if (text == null || text.equals(place.getText())) {
|
||||
continue;
|
||||
}
|
||||
String s = CONTRIBUTORS.get(text);
|
||||
if (s != null) {
|
||||
contributorClassName = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PsiClass contributorClass = psiManager.findClassWithCache(contributorClassName, place.getResolveScope());
|
||||
if (contributorClass != null) {
|
||||
contributorClass.processDeclarations(processor, state, null, place);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,17 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class GradleConstants {
|
||||
|
||||
@NotNull public static final ProjectSystemId SYSTEM_ID = new ProjectSystemId("GRADLE");
|
||||
@NotNull @NonNls public static final ProjectSystemId SYSTEM_ID = new ProjectSystemId("GRADLE");
|
||||
|
||||
@NonNls public static final String EXTENSION = "gradle";
|
||||
@NonNls public static final String DEFAULT_SCRIPT_NAME = "build.gradle";
|
||||
@NonNls public static final String SETTINGS_FILE_NAME = "settings.gradle";
|
||||
@NotNull @NonNls public static final String EXTENSION = "gradle";
|
||||
@NotNull @NonNls public static final String DEFAULT_SCRIPT_NAME = "build.gradle";
|
||||
@NotNull @NonNls public static final String SETTINGS_FILE_NAME = "settings.gradle";
|
||||
|
||||
public static final String SYSTEM_DIRECTORY_PATH_KEY = "GRADLE_USER_HOME";
|
||||
@NotNull @NonNls public static final String SYSTEM_DIRECTORY_PATH_KEY = "GRADLE_USER_HOME";
|
||||
|
||||
@NonNls public static final String TOOL_WINDOW_TOOLBAR_PLACE = "GRADLE_SYNC_CHANGES_TOOLBAR";
|
||||
@NotNull @NonNls public static final String TOOL_WINDOW_TOOLBAR_PLACE = "GRADLE_SYNC_CHANGES_TOOLBAR";
|
||||
|
||||
@NonNls public static final String HELP_TOPIC_TOOL_WINDOW = "reference.toolwindows.gradle";
|
||||
@NotNull @NonNls public static final String HELP_TOPIC_TOOL_WINDOW = "reference.toolwindows.gradle";
|
||||
|
||||
private GradleConstants() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user