From e87ca5b56b6e8d0cee475de1385a825eb6e951e2 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 21 Jan 2005 20:47:36 +0300 Subject: [PATCH] (no message) --- .../daemon/impl/actions/AddImportAction.java | 21 +++-- .../PsiJavaCodeReferenceElementImpl.java | 88 +++++++++---------- .../psi/impl/source/tree/ChangeUtil.java | 31 +++++++ .../psi/impl/source/xml/XmlTagImpl.java | 2 +- source/com/intellij/xml/util/XmlUtil.java | 2 +- 5 files changed, 83 insertions(+), 61 deletions(-) diff --git a/source/com/intellij/codeInsight/daemon/impl/actions/AddImportAction.java b/source/com/intellij/codeInsight/daemon/impl/actions/AddImportAction.java index b307744a2aa5..c27275255469 100644 --- a/source/com/intellij/codeInsight/daemon/impl/actions/AddImportAction.java +++ b/source/com/intellij/codeInsight/daemon/impl/actions/AddImportAction.java @@ -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); } - }); + } + }); } } diff --git a/source/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java b/source/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java index e08ddade4fb3..9e6cf457df45 100644 --- a/source/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java +++ b/source/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java @@ -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; } } diff --git a/source/com/intellij/psi/impl/source/tree/ChangeUtil.java b/source/com/intellij/psi/impl/source/tree/ChangeUtil.java index f961d8753ede..e302e6144149 100644 --- a/source/com/intellij/psi/impl/source/tree/ChangeUtil.java +++ b/source/com/intellij/psi/impl/source/tree/ChangeUtil.java @@ -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(); + } } diff --git a/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java index a5592792b8a0..0dad2352ea06 100644 --- a/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -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); } diff --git a/source/com/intellij/xml/util/XmlUtil.java b/source/com/intellij/xml/util/XmlUtil.java index 8f8729970210..1bfa161efdf0 100644 --- a/source/com/intellij/xml/util/XmlUtil.java +++ b/source/com/intellij/xml/util/XmlUtil.java @@ -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;