(no message)

This commit is contained in:
Alexey Kudravtsev
2005-01-21 20:47:36 +03:00
parent ecd0e2ca70
commit e87ca5b56b
5 changed files with 83 additions and 61 deletions

View File

@@ -83,16 +83,15 @@ public class AddImportAction implements QuestionAction {
StatisticsManager.getInstance().incMemberUseCount(null, targetClass);
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
public void run() {
final Runnable action = new Runnable() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
_addImport(ref, targetClass);
}
};
ApplicationManager.getApplication().runWriteAction(action);
});
}
},
"Add Import",
null);
"Add Import",
null);
}
private void _addImport(PsiJavaCodeReferenceElement ref, PsiClass targetClass) {
@@ -130,12 +129,12 @@ public class AddImportAction implements QuestionAction {
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
if (daemonCodeAnalyzer != null) {
daemonCodeAnalyzer.updateVisibleHighlighters(myEditor);
}
public void run() {
DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
if (daemonCodeAnalyzer != null) {
daemonCodeAnalyzer.updateVisibleHighlighters(myEditor);
}
});
}
});
}
}

View File

@@ -465,58 +465,50 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
if (isReferenceTo(element)) return this;
switch (getKind()) {
case CLASS_NAME_KIND:
case CLASS_FQ_NAME_KIND:
{
if (!(element instanceof PsiClass)) {
throw new IncorrectOperationException();
}
return bindToClass((PsiClass)element);
}
case CLASS_NAME_KIND:
case CLASS_FQ_NAME_KIND:
if (!(element instanceof PsiClass)) {
throw new IncorrectOperationException();
}
return bindToClass((PsiClass)element);
case PACKAGE_NAME_KIND:
{
if (!(element instanceof PsiPackage)) {
throw new IncorrectOperationException();
}
return bindToPackage((PsiPackage)element);
}
case PACKAGE_NAME_KIND:
if (!(element instanceof PsiPackage)) {
throw new IncorrectOperationException();
}
return bindToPackage((PsiPackage)element);
case CLASS_OR_PACKAGE_NAME_KIND:
case CLASS_FQ_OR_PACKAGE_NAME_KIND:
{
if (element instanceof PsiClass) {
return bindToClass((PsiClass)element);
}
else if (element instanceof PsiPackage) {
return bindToPackage((PsiPackage)element);
}
else {
throw new IncorrectOperationException();
}
}
case CLASS_OR_PACKAGE_NAME_KIND:
case CLASS_FQ_OR_PACKAGE_NAME_KIND:
if (element instanceof PsiClass) {
return bindToClass((PsiClass)element);
}
else if (element instanceof PsiPackage) {
return bindToPackage((PsiPackage)element);
}
else {
throw new IncorrectOperationException();
}
case CLASS_IN_QUALIFIED_NEW_KIND:
{
if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass)element;
final String name = aClass.getName();
if (name == null) {
throw new IncorrectOperationException();
}
final TreeElement ref =
Parsing.parseJavaCodeReferenceText(aClass.getManager(), name.toCharArray(), SharedImplUtil.findCharTableByTree(this));
getTreeParent().replaceChildInternal(this, ref);
return SourceTreeToPsiMap.treeElementToPsi(ref);
}
else {
throw new IncorrectOperationException();
}
}
case CLASS_IN_QUALIFIED_NEW_KIND:
if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass)element;
final String name = aClass.getName();
if (name == null) {
throw new IncorrectOperationException();
}
final TreeElement ref =
Parsing.parseJavaCodeReferenceText(aClass.getManager(), name.toCharArray(), SharedImplUtil.findCharTableByTree(this));
getTreeParent().replaceChildInternal(this, ref);
return SourceTreeToPsiMap.treeElementToPsi(ref);
}
else {
throw new IncorrectOperationException();
}
default:
LOG.assertTrue(false);
return null;
default:
LOG.assertTrue(false);
return null;
}
}

View File

@@ -6,6 +6,7 @@ import com.intellij.lexer.Lexer;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -19,6 +20,8 @@ import com.intellij.psi.impl.source.*;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerEx;
import com.intellij.psi.impl.source.parsing.*;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlTagValue;
import com.intellij.util.CharTable;
import com.intellij.util.IncorrectOperationException;
@@ -38,6 +41,8 @@ public class ChangeUtil implements Constants {
PsiTreeChangeEventImpl event = null;
PsiElement parentPsiElement = SourceTreeToPsiMap.treeElementToPsi(parent);
PsiFile file = parentPsiElement.getContainingFile();
checkConsistency(file);
boolean physical = parentPsiElement.isPhysical();
if (physical) {
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
@@ -91,6 +96,7 @@ public class ChangeUtil implements Constants {
if (document != null) {
PsiDocumentManagerImpl.checkConsistency(file, document);
}
checkTextRanges(file);
}
}
@@ -701,4 +707,29 @@ public class ChangeUtil implements Constants {
if (containingFile.isPhysical()) manager.childrenChanged(event);
checkConsistency(containingFile);
}
public static int checkTextRanges(PsiElement root) {
TextRange range = root.getTextRange();
int off = range.getStartOffset();
PsiElement[] children = root.getChildren();
if (children.length != 0) {
for (int i = 0; i < children.length; i++) {
PsiElement child = children[i];
off += checkTextRanges(child);
}
}
else {
off += root.getTextLength();
}
LOG.assertTrue(off == range.getEndOffset());
String fileText = root.getContainingFile().getText();
LOG.assertTrue(root.getText().equals(fileText.substring(range.getStartOffset(), range.getEndOffset())));
if (root instanceof XmlTag) {
XmlTagValue value = ((XmlTag)root).getValue();
TextRange textRange = value.getTextRange();
LOG.assertTrue(value.getText().equals(fileText.substring(textRange.getStartOffset(), textRange.getEndOffset())));
}
return range.getLength();
}
}

View File

@@ -427,7 +427,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification
myTags = result.toArray(new XmlTag[result.size()]);
return myTags;
}
public XmlTag[] findSubTags(String name) {
return findSubTags(name, null);
}

View File

@@ -369,7 +369,7 @@ public class XmlUtil {
while (subTagNum < subTags.length - 1 && subTags[subTagNum + 1].getName().equals(childElementName)) {
subTagNum++;
}
if (childElementName.equals(child.getName())) {
if (childElementName.equals(child.getLocalName())) {
// insert child just after anchor
// insert into the position specified by index
subTagNum = index == -1 || index > subTagNum - prevSubTagNum ? subTagNum : prevSubTagNum + index;