Cleanup (formatting; warnings)

This commit is contained in:
Roman Shevchenko
2014-10-02 13:02:36 +02:00
parent abdab3a22d
commit 85e4e2a750
5 changed files with 46 additions and 36 deletions
@@ -228,14 +228,13 @@ class Bar {
}
}
'''
IdentifierHighlighterPassFactory.ourTestingIdentifierHighlighting = true
try {
IdentifierHighlighterPassFactory.doWithHighlightingEnabled {
def infos = myFixture.doHighlighting()
//import highlighted twice: for each overloaded usage target
assert infos.findAll { it.severity == HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY && myFixture.file.text.substring(it.startOffset, it.endOffset) == 'foo' }.size() == 3
}
finally {
IdentifierHighlighterPassFactory.ourTestingIdentifierHighlighting = false
assert infos.findAll {
it.severity == HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY &&
myFixture.file.text.substring(it.startOffset, it.endOffset) == 'foo'
}.size() == 3
}
}
@@ -67,7 +67,7 @@ public class IdentifierHighlighterPass extends TextEditorHighlightingPass {
@Override
public void doCollectInformation(@NotNull final ProgressIndicator progress) {
final HighlightUsagesHandlerBase<PsiElement> handler = HighlightUsagesHandler.createCustomHandler(myEditor, myFile);
@SuppressWarnings("unchecked") HighlightUsagesHandlerBase<PsiElement> handler = HighlightUsagesHandler.createCustomHandler(myEditor, myFile);
if (handler != null) {
List<PsiElement> targets = handler.getTargets();
handler.computeUsages(targets);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.impl;
import com.intellij.codeHighlighting.Pass;
@@ -27,27 +26,41 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
/**
* @author yole
*/
public class IdentifierHighlighterPassFactory extends AbstractProjectComponent implements TextEditorHighlightingPassFactory {
public static boolean ourTestingIdentifierHighlighting = false;
private static final int[] AFTER_PASSES = {Pass.UPDATE_ALL};
private static boolean ourTestingIdentifierHighlighting = false;
public IdentifierHighlighterPassFactory(Project project, TextEditorHighlightingPassRegistrar highlightingPassRegistrar) {
super(project);
highlightingPassRegistrar.registerTextEditorHighlightingPass(this, null, new int[]{Pass.UPDATE_ALL}, false, -1);
highlightingPassRegistrar.registerTextEditorHighlightingPass(this, null, AFTER_PASSES, false, -1);
}
@Override
public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) {
if (editor.isOneLineMode()) return null;
if (CodeInsightSettings.getInstance().HIGHLIGHT_IDENTIFIER_UNDER_CARET &&
(!ApplicationManager.getApplication().isHeadlessEnvironment() || ourTestingIdentifierHighlighting)
&& file.isPhysical()) {
if (!editor.isOneLineMode() &&
CodeInsightSettings.getInstance().HIGHLIGHT_IDENTIFIER_UNDER_CARET &&
(!ApplicationManager.getApplication().isHeadlessEnvironment() || ourTestingIdentifierHighlighting) &&
file.isPhysical()) {
return new IdentifierHighlighterPass(file.getProject(), file, editor);
}
return null;
}
@TestOnly
public static void doWithHighlightingEnabled(@NotNull Runnable r) {
ourTestingIdentifierHighlighting = true;
try {
r.run();
}
finally {
ourTestingIdentifierHighlighting = false;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
public class HighlightUsagesAction extends AnAction implements DumbAware {
public HighlightUsagesAction() {
@@ -33,18 +34,17 @@ public class HighlightUsagesAction extends AnAction implements DumbAware {
}
@Override
public void update(final AnActionEvent event) {
final Presentation presentation = event.getPresentation();
final DataContext dataContext = event.getDataContext();
presentation.setEnabled(CommonDataKeys.PROJECT.getData(dataContext) != null &&
CommonDataKeys.EDITOR.getData(dataContext) != null);
public void update(@NotNull AnActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setEnabled(e.getProject() != null && CommonDataKeys.EDITOR.getData(e.getDataContext()) != null);
}
@Override
public void actionPerformed(AnActionEvent e) {
public void actionPerformed(@NotNull AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final Project project = e.getProject();
if (editor == null || project == null) return;
String commandName = getTemplatePresentation().getText();
if (commandName == null) commandName = "";
@@ -17,7 +17,6 @@ package org.jetbrains.java.decompiler;
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.StandardFileSystems;
@@ -81,7 +80,7 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase {
return p > 0 && knowProblems.contains(path.substring(p + 2));
}
// todo[r.sh] drop when IDEA129734 get fixed
// todo[r.sh] drop when IDEA-129734 get fixed
private final Set<String> knowProblems = ContainerUtil.newHashSet(
"java/lang/reflect/AnnotatedElement.class", "java/util/stream/Nodes.class", "java/util/stream/FindOps.class",
"java/util/stream/Collectors.class", "java/util/stream/DistinctOps.class", "java/util/stream/IntPipeline.class",
@@ -94,23 +93,22 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase {
String path = PluginPathManager.getPluginHomePath("java-decompiler") + "/testData/Navigation.class";
VirtualFile file = StandardFileSystems.local().findFileByPath(path);
assertNotNull(path, file);
myFixture.configureFromExistingVirtualFile(file);
String text = myFixture.getEditor().getDocument().getText();
assertTrue(text, text.startsWith(IdeaDecompiler.BANNER));
myFixture.openFileInEditor(file);
doTestNavigation(11, 14, 14, 10); // to "m2()"
doTestNavigation(15, 21, 14, 17); // to "int i"
doTestNavigation(16, 28, 15, 13); // to "int r"
}
private void doTestNavigation(int line, int column, int expLine, int expColumn) {
Editor editor = myFixture.getEditor();
int offset = editor.getDocument().getLineStartOffset(line - 1) + column - 1;
PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), editor, offset);
private void doTestNavigation(int line, int column, int expectedLine, int expectedColumn) {
PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset(line, column));
assertTrue(String.valueOf(target), target instanceof Navigatable);
((Navigatable)target).navigate(true);
int expected = editor.getDocument().getLineStartOffset(expLine - 1) + expColumn - 1;
assertEquals(expected, editor.getCaretModel().getOffset());
int expected = offset(expectedLine, expectedColumn);
assertEquals(expected, myFixture.getCaretOffset());
}
private int offset(int line, int column) {
return myFixture.getEditor().getDocument().getLineStartOffset(line - 1) + column - 1;
}
}