IDEA-57183 Gant: Ant tasks are considered to be not applicable to String argument

IDEA-61490 Gant: "Cannot determine type of" message for all predefined tasks
This commit is contained in:
peter
2010-12-13 16:42:40 +03:00
parent e1fcc3156a
commit bd17d0cffb
3 changed files with 44 additions and 8 deletions
@@ -2,6 +2,7 @@ package org.jetbrains.plugins.groovy.gant;
import com.intellij.lang.ant.dom.AntDomExtender;
import com.intellij.lang.ant.psi.impl.AntIntrospector;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.impl.light.LightMethodBuilder;
import com.intellij.psi.scope.PsiScopeProcessor;
@@ -22,14 +23,21 @@ class AntBuilderMethod extends LightMethodBuilder implements GrBuilderMethod {
private final PsiFile myPlace;
@Nullable private final Class myAntClass;
public AntBuilderMethod(PsiFile place, String name, PsiType closureType, @Nullable Class antClass) {
public AntBuilderMethod(PsiFile place, String name, PsiType closureType, @Nullable Class antClass, final PsiType stringType) {
super(place.getManager(), GroovyFileType.GROOVY_LANGUAGE, name);
myPlace = place;
myAntClass = antClass;
setModifiers(PsiModifier.PUBLIC);
addParameter("args", new GrMapType(place.getResolveScope()));
setBaseIcon(GantIcons.ANT_TASK);
addParameter(new GrLightParameter("singleArg", stringType, this).setOptional(true));
addParameter(new GrLightParameter("body", closureType, this).setOptional(true));
setReturnType(new Computable<PsiType>() {
@Override
public PsiType compute() {
return PsiType.getJavaLangObject(getManager(), getResolveScope());
}
});
}
@NotNull
@@ -48,11 +56,13 @@ class AntBuilderMethod extends LightMethodBuilder implements GrBuilderMethod {
final AntIntrospector introspector = AntDomExtender.getIntrospector(myAntClass);
if (introspector != null) {
String expectedName = ResolveUtil.getNameHint(processor);
final PsiType closureType = getParameterList().getParameters()[1].getType();
final PsiType stringType = getParameterList().getParameters()[1].getType();
final PsiType closureType = getParameterList().getParameters()[2].getType();
for (String name : Collections.list(introspector.getNestedElements())) {
if (expectedName == null || expectedName.equals(name)) {
final AntBuilderMethod method = new AntBuilderMethod(myPlace, name, closureType, introspector.getElementType(name));
final AntBuilderMethod method = new AntBuilderMethod(myPlace, name, closureType, introspector.getElementType(name),
stringType);
if (!processor.execute(method, ResolveState.initial())) return false;
}
}
@@ -27,10 +27,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiType;
import com.intellij.psi.*;
import com.intellij.psi.impl.light.LightMethodBuilder;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
@@ -85,9 +82,10 @@ public class AntTasksProvider {
final Project project = file.getProject();
final PsiType closureType = JavaPsiFacade.getElementFactory(project).createTypeFromText(GrClosableBlock.GROOVY_LANG_CLOSURE, file);
final PsiClassType stringType = PsiType.getJavaLangString(file.getManager(), file.getResolveScope());
for (String name : antObjects.keySet()) {
methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name)));
methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name), stringType));
}
final Result<Set<LightMethodBuilder>> result =
Result.create(methods, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
@@ -28,6 +28,8 @@ import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUntypedAccessInspection
import org.jetbrains.plugins.groovy.util.TestUtils
/**
@@ -144,6 +146,32 @@ target(aaa: "") {
}""", "include", "includesfile", "includeTargets", "includeTool"
}
public void testUntypedTargets() throws Exception {
myFixture.enableInspections(new GroovyUntypedAccessInspection())
myFixture.configureByText "a.gant", """
target (default : '') {
echo(message: 'Echo task.')
copy(file: 'from.txt', tofile: 'to.txt')
delete(file: 'to.txt')
}"""
myFixture.checkHighlighting(true, false, false)
}
public void testStringTargets() throws Exception {
myFixture.enableInspections(new GroovyAssignabilityCheckInspection())
myFixture.configureByText "a.gant", """
target (default : '') {
echo<warning descr="'echo' cannot be applied to '(java.io.FileInputStream)'">(new FileInputStream<warning descr="Ambiguous constructor call">()</warning>)</warning>
echo("hello2")
echo(message: 'Echo task.')
ant.fail('Failure reason')
}"""
myFixture.checkHighlighting(true, false, false)
}
static final def GANT_JARS = ["gant.jar", "ant.jar", "ant-junit.jar", "ant-launcher.jar", "commons.jar"]
}