mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correct registration of type definitions in context of parent element
force instantiation of AntStructuredElement children rename tests added
This commit is contained in:
@@ -13,6 +13,8 @@ public interface AntStructuredElement extends AntElement {
|
||||
@Nullable
|
||||
AntTypeDefinition getTypeDefinition();
|
||||
|
||||
void registerCustomType(final AntTypeDefinition def);
|
||||
|
||||
void registerRefId(final String id, AntElement element);
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -102,6 +102,17 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc
|
||||
return myDefinition;
|
||||
}
|
||||
|
||||
public void registerCustomType(final AntTypeDefinition def) {
|
||||
if (myDefinition != null) {
|
||||
if (!myDefinitionCloned) {
|
||||
myDefinition = new AntTypeDefinitionImpl((AntTypeDefinitionImpl) myDefinition);
|
||||
myDefinitionCloned = true;
|
||||
}
|
||||
myDefinition.registerNestedType(def.getTypeId(), def.getClassName());
|
||||
}
|
||||
getAntFile().registerCustomType(def);
|
||||
}
|
||||
|
||||
public void registerRefId(final String id, AntElement element) {
|
||||
if (myReferencedElements == null) {
|
||||
myReferencedElements = new HashMap<String, AntElement>();
|
||||
@@ -171,6 +182,9 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc
|
||||
AntElementFactory.createAntElement(this, (XmlElement) element);
|
||||
if (antElement != null) {
|
||||
children.add(antElement);
|
||||
if (antElement instanceof AntStructuredElement) {
|
||||
antElement.getChildren();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.intellij.lang.ant.psi.impl;
|
||||
|
||||
import com.intellij.lang.ant.psi.AntElement;
|
||||
import com.intellij.lang.ant.psi.AntStructuredElement;
|
||||
import com.intellij.lang.ant.psi.AntTypeDef;
|
||||
import com.intellij.lang.ant.psi.introspection.AntTypeDefinition;
|
||||
import com.intellij.lang.ant.psi.introspection.AntTypeId;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.xml.XmlElement;
|
||||
import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import org.apache.tools.ant.Task;
|
||||
@@ -54,7 +56,10 @@ public class AntTypeDefImpl extends AntTaskImpl implements AntTypeDef {
|
||||
myNewDefinition = null;
|
||||
} else {
|
||||
myNewDefinition = AntFileImpl.createTypeDefinition(id, clazz, Task.class.isAssignableFrom(clazz));
|
||||
getAntFile().registerCustomType(myNewDefinition);
|
||||
final AntStructuredElement se = PsiTreeUtil.getParentOfType(this, AntStructuredElementImpl.class);
|
||||
if (se != null) {
|
||||
se.registerCustomType(myNewDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a">
|
||||
<param name="p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="<ren>a">
|
||||
<echo message="${p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a-after">
|
||||
<param name="p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a-after">
|
||||
<echo message="${p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="<ren>a">
|
||||
<param name="p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a">
|
||||
<echo message="${p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a-after">
|
||||
<param name="p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a-after">
|
||||
<echo message="${p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a,b"/>
|
||||
<target name="<ren>a"/>
|
||||
<target name="b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a-after,b"/>
|
||||
<target name="a-after"/>
|
||||
<target name="b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a,b"/>
|
||||
<target name="a"/>
|
||||
<target name="<ren>b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a,b-after"/>
|
||||
<target name="a"/>
|
||||
<target name="b-after"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="<ren>a,b"/>
|
||||
<target name="a"/>
|
||||
<target name="b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a-after,b"/>
|
||||
<target name="a-after"/>
|
||||
<target name="b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a,<ren>b"/>
|
||||
<target name="a"/>
|
||||
<target name="b"/>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test" depends="a,b-after"/>
|
||||
<target name="a"/>
|
||||
<target name="b-after"/>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a">
|
||||
<param name="<ren>p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a">
|
||||
<echo message="${p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a">
|
||||
<param name="p-after" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a">
|
||||
<echo message="${p-after}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a">
|
||||
<param name="p" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a">
|
||||
<echo message="${<ren>p}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<antcall target="a">
|
||||
<param name="p-after" value="v"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="a">
|
||||
<echo message="${p-after}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<path id="<ren>id"/>
|
||||
<rmic>
|
||||
<classpath refid="id"/>
|
||||
</rmic>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<path id="id-after" />
|
||||
<rmic>
|
||||
<classpath refid="id-after"/>
|
||||
</rmic>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<path id="id"/>
|
||||
<rmic>
|
||||
<classpath refid="<ren>id"/>
|
||||
</rmic>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<project name="testProject" default="test">
|
||||
<target name="test">
|
||||
<path id="id-after" />
|
||||
<rmic>
|
||||
<classpath refid="id-after"/>
|
||||
</rmic>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<project name="testProject" default="test">
|
||||
<property name="<ren>p1" value="v1"/>
|
||||
<target name="test">
|
||||
<echo message="${p1}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<project name="testProject" default="test">
|
||||
<property name="p1-after" value="v1"/>
|
||||
<target name="test">
|
||||
<echo message="${p1-after}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<project name="testProject" default="test">
|
||||
<property name="p1" value="v1"/>
|
||||
<target name="test">
|
||||
<echo message="${<ren>p1}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<project name="testProject" default="test">
|
||||
<property name="p1-after" value="v1"/>
|
||||
<target name="test">
|
||||
<echo message="${p1-after}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
<project name="testProject" default="t">
|
||||
<target name="<ren>t"/>
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
<project name="testProject" default="t-after">
|
||||
<target name="t-after"/>
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
<project name="testProject" default="<ren>t">
|
||||
<target name="t"/>
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
<project name="testProject" default="t-after">
|
||||
<target name="t-after"/>
|
||||
</project>
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.intellij.lang.ant;
|
||||
|
||||
import com.intellij.lang.ant.psi.AntFile;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.refactoring.RefactoringFactory;
|
||||
import com.intellij.refactoring.RenameRefactoring;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
|
||||
public class AntRenameTest extends LightCodeInsightTestCase {
|
||||
|
||||
public void testSimpleProperty() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSimplePropertyReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParam() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParamReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRefid() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRefidReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSingleTarget() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSingleTargetReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAntCall() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAntCallReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDependsTarget1() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDependsTarget2() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDependsTargetReference1() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDependsTargetReference2() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath().replace('\\', '/') + "/plugins/ant/tests/data/psi/rename/";
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
final String filename = getTestName(true) + ".xml";
|
||||
VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl(
|
||||
"file://" + getTestDataPath() + filename);
|
||||
String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
|
||||
int off = text.indexOf("<ren>");
|
||||
text = text.replace("<ren>", "");
|
||||
configureFromFileText(filename, text);
|
||||
myFile = myFile.getViewProvider().getPsi(AntSupport.getLanguage());
|
||||
assertNotNull(myFile);
|
||||
assertTrue(myFile instanceof AntFile);
|
||||
PsiElement element = myFile.findElementAt(off);
|
||||
final PsiReference[] refs = element.getReferences();
|
||||
if (refs.length > 0) {
|
||||
int i = 0;
|
||||
element = refs[0].resolve();
|
||||
while (element != null && !text.substring(off).trim().startsWith(((PsiNamedElement) element).getName())) {
|
||||
element = refs[++i].resolve();
|
||||
}
|
||||
} else {
|
||||
element = element.getParent();
|
||||
}
|
||||
assertNotNull(element);
|
||||
assertTrue(element instanceof PsiNamedElement);
|
||||
final RenameRefactoring rename = RefactoringFactory.getInstance(getProject()).createRename(
|
||||
element, ((PsiNamedElement) element).getName() + "-after");
|
||||
rename.setSearchInComments(false);
|
||||
rename.setSearchInNonJavaFiles(false);
|
||||
rename.run();
|
||||
checkResultByFile(filename + "-after");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user