tests fix

This commit is contained in:
Alexey Kudravtsev
2009-10-23 10:49:54 +04:00
parent b13e4915aa
commit fa0c0ebf66
8 changed files with 40 additions and 42 deletions
@@ -19,6 +19,7 @@
*/
package com.intellij.lang.java;
import com.intellij.formatting.Block;
import com.intellij.formatting.FormattingModel;
import com.intellij.formatting.FormattingModelBuilder;
import com.intellij.lang.ASTNode;
@@ -47,9 +48,9 @@ public class JavaFormattingModelBuilder implements FormattingModelBuilder {
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
final FileElement fileElement = TreeUtil.getFileElement((TreeElement)SourceTreeToPsiMap.psiElementToTree(element));
LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), AbstractJavaBlock.createJavaBlock(fileElement,
settings),
FormattingDocumentModelImpl.createOn(element.getContainingFile()));
Block block = AbstractJavaBlock.createJavaBlock(fileElement, settings);
FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), block, model);
}
public TextRange getRangeAffectingIndent(final PsiFile file, final int offset, final ASTNode elementAtOffset) {
@@ -37,32 +37,30 @@ public class JavaImportOptimizer implements ImportOptimizer {
@NotNull
public Runnable processFile(final PsiFile file) {
if (file instanceof PsiJavaFile) {
Project project = file.getProject();
final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult((PsiJavaFile)file);
return new Runnable() {
public void run() {
try {
if (newImportList != null) {
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
final Document document = manager.getDocument(file);
if (document != null) {
manager.commitDocument(document);
}
final PsiImportList oldImportList = ((PsiJavaFile)file).getImportList();
assert oldImportList != null;
oldImportList.replace(newImportList);
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
};
}
else {
if (!(file instanceof PsiJavaFile)) {
return EmptyRunnable.getInstance();
}
Project project = file.getProject();
final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult((PsiJavaFile)file);
return new Runnable() {
public void run() {
try {
if (newImportList != null) {
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
final Document document = manager.getDocument(file);
if (document != null) {
manager.commitDocument(document);
}
final PsiImportList oldImportList = ((PsiJavaFile)file).getImportList();
assert oldImportList != null;
oldImportList.replace(newImportList);
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
};
}
public boolean supports(PsiFile file) {
@@ -76,15 +76,12 @@ public class ImportHelper{
List<Pair<String, Boolean>> resultList = new ArrayList<Pair<String, Boolean>>(names.size());
for(int i = 0; i < entries.length; i++){
PackageEntry entry = entries[i];
//if (!entry.isSpecial()) {
for(int j = 0; j < names.size(); j++){
if (entryForName[j] == i){
resultList.add(names.get(j));
names.set(j, null);
}
for(int j = 0; j < names.size(); j++){
if (entryForName[j] == i){
resultList.add(names.get(j));
names.set(j, null);
}
//}
}
}
for (Pair<String, Boolean> name : names) {
if (name != null) resultList.add(name);
@@ -36,9 +36,8 @@ public class JavaHelper extends Helper {
if (element.getTreePrev() != null) {
ASTNode prev = element.getTreePrev();
ASTNode lastCompositePrev;
while (prev instanceof CompositeElement && !TreeUtil.isStrongWhitespaceHolder(prev.getElementType())) {
lastCompositePrev = prev;
ASTNode lastCompositePrev = prev;
prev = prev.getLastChildNode();
if (prev == null) { // element.prev is "empty composite"
return getIndentInner(lastCompositePrev, includeNonSpace, recursionLevel + 1);
@@ -1,5 +1,6 @@
package b;
import a.*;
import static u.U.C;
public class B extends A {
@@ -103,10 +103,12 @@ public class PackageEntry {
if (entry.isWithSubpackages() != isWithSubpackages()) {
return !isWithSubpackages();
}
if (entry == ALL_OTHER_IMPORTS_ENTRY || entry == ALL_OTHER_STATIC_IMPORTS_ENTRY) return true;
if (this == ALL_OTHER_IMPORTS_ENTRY || this == ALL_OTHER_STATIC_IMPORTS_ENTRY) return false;
return StringUtil.countChars(entry.getPackageName(), '.') < StringUtil.countChars(getPackageName(), '.');
}
@NonNls
@Override
public String toString() {
return (isStatic() ? "static " : "") + getPackageName();
@@ -66,7 +66,7 @@ public class DocumentBasedFormattingModel implements FormattingModel {
mySettings = settings;
myFileType = fileType;
myDocumentModel = FormattingDocumentModelImpl.createOn(file);
myDocument = ((FormattingDocumentModelImpl)myDocumentModel).getDocument();
myDocument = myDocumentModel.getDocument();
}
@NotNull
@@ -85,8 +85,8 @@ public class DocumentBasedFormattingModel implements FormattingModel {
// When processing injection in cdata / comment we need not remove start / end markers that present as whitespace during check in
// com.intellij.formatting.WhiteSpace and during building formatter model = blocks in e.g. com.intellij.psi.formatter.xml.XmlTagBlock
if ((removesStartMarker = (removesPattern(textRange, whiteSpace, marker = "<![CDATA[") ||
removesPattern(textRange, whiteSpace, marker ="<!--["))) ||
if ((removesStartMarker = removesPattern(textRange, whiteSpace, marker = "<![CDATA[") ||
removesPattern(textRange, whiteSpace, marker ="<!--[")) ||
removesPattern(textRange, whiteSpace, marker = "]]>") ||
removesPattern(textRange, whiteSpace, marker = "]-->")
) {
@@ -533,7 +533,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
fileName), text, LocalTimeCounter.currentTime(), false);
}
protected static PsiFile createPseudoPhysicalFile(String fileName, String text) throws IncorrectOperationException {
protected static PsiFile createPseudoPhysicalFile(@NonNls String fileName, String text) throws IncorrectOperationException {
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, text, LocalTimeCounter.currentTime(), true);
}