Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Kalishev
2011-08-25 17:32:26 +04:00
8 changed files with 89 additions and 67 deletions
@@ -24,6 +24,7 @@ import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Key;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
@@ -33,6 +34,7 @@ import com.intellij.util.Processor;
import com.intellij.util.containers.Convertor;
import junit.runner.BaseTestRunner;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.After;
import org.junit.AfterClass;
@@ -51,19 +53,22 @@ public class JUnitUtil {
@NonNls public static final String RUN_WITH = "org.junit.runner.RunWith";
@NonNls public static final String SUITE_METHOD_NAME = "suite";
public static boolean isSuiteMethod(final PsiMethod psiMethod) {
if (psiMethod == null) return false;
private static final Key<PsiType> TEST_INTERFACE_KEY = Key.create(TEST_INTERFACE);
public static boolean isSuiteMethod(@NotNull PsiMethod psiMethod, @NotNull Project project) {
if (!psiMethod.hasModifierProperty(PsiModifier.PUBLIC)) return false;
if (!psiMethod.hasModifierProperty(PsiModifier.STATIC)) return false;
if (psiMethod.isConstructor()) return false;
final PsiType returnType = psiMethod.getReturnType();
if (returnType != null) {
if (!returnType.equalsToText(TEST_INTERFACE) && !returnType.equalsToText(TESTSUITE_CLASS)) {
final PsiType testType =
JavaPsiFacade.getInstance(psiMethod.getProject()).getElementFactory().createTypeFromText(TEST_INTERFACE, null);
if (!TypeConversionUtil.isAssignable(testType, returnType)) {
return false;
}
if (returnType == null || returnType instanceof PsiPrimitiveType) return false;
if (!returnType.equalsToText(TEST_INTERFACE) && !returnType.equalsToText(TESTSUITE_CLASS)) {
PsiType cachedTestInterfaceType = project.getUserData(TEST_INTERFACE_KEY);
if (cachedTestInterfaceType == null) {
final PsiType testType = JavaPsiFacade.getInstance(project).getElementFactory().createTypeFromText(TEST_INTERFACE, null);
project.putUserData(TEST_INTERFACE_KEY,testType);
cachedTestInterfaceType = testType;
}
if (!TypeConversionUtil.isAssignable(cachedTestInterfaceType, returnType)) {
return false;
}
}
return psiMethod.getParameterList().getParametersCount() == 0;
@@ -109,7 +114,7 @@ public class JUnitUtil {
return isTestClass(psiClass, true, true);
}
private static boolean isTestClass(final PsiClass psiClass, boolean checkAbstract, boolean checkForTestCaseInheritance) {
private static boolean isTestClass(@NotNull PsiClass psiClass, boolean checkAbstract, boolean checkForTestCaseInheritance) {
if (!PsiClassUtil.isRunnableClass(psiClass, true, checkAbstract)) return false;
if (checkForTestCaseInheritance && isTestCaseInheritor(psiClass)) return true;
final PsiModifierList modifierList = psiClass.getModifierList();
@@ -118,7 +123,7 @@ public class JUnitUtil {
for (final PsiMethod method : psiClass.getAllMethods()) {
ProgressManager.checkCanceled();
if (isSuiteMethod(method)) return true;
if (isSuiteMethod(method, psiClass.getProject())) return true;
if (isTestAnnotated(method)) return true;
}
@@ -241,7 +246,7 @@ public class JUnitUtil {
public static PsiMethod findFirstTestMethod(PsiClass clazz) {
PsiMethod testMethod = null;
for (PsiMethod method : clazz.getMethods()) {
if (isTestMethod(MethodLocation.elementInClass(method, clazz)) || isSuiteMethod(method)) {
if (isTestMethod(MethodLocation.elementInClass(method, clazz)) || isSuiteMethod(method, clazz.getProject())) {
testMethod = method;
break;
}
@@ -36,24 +36,24 @@ import java.util.List;
public class FrameworkSupportNode extends CheckedTreeNode {
private final FrameworkSupportProvider myProvider;
private final FrameworkSupportNode myParentNode;
private final FrameworkSupportConfigurable myConfigurable;
private FrameworkSupportConfigurable myConfigurable;
private final List<FrameworkSupportNode> myChildren = new ArrayList<FrameworkSupportNode>();
private final FrameworkSupportModelBase myModel;
private final Disposable myParentDisposable;
public FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelBase model,
Disposable parentDisposable) {
super(provider);
myParentDisposable = parentDisposable;
setChecked(false);
myProvider = provider;
myParentNode = parentNode;
model.registerComponent(provider, this);
myConfigurable = provider.createConfigurable(model);
Disposer.register(parentDisposable, myConfigurable);
myModel = model;
if (parentNode != null) {
parentNode.add(this);
parentNode.myChildren.add(this);
}
setConfigurableComponentEnabled(false);
}
public List<FrameworkSupportNode> getChildren() {
@@ -75,7 +75,12 @@ public class FrameworkSupportNode extends CheckedTreeNode {
return myParentNode;
}
public FrameworkSupportConfigurable getConfigurable() {
public synchronized FrameworkSupportConfigurable getConfigurable() {
if (myConfigurable == null) {
myConfigurable = myProvider.createConfigurable(myModel);
setConfigurableComponentEnabled(false);
Disposer.register(myParentDisposable, myConfigurable);
}
return myConfigurable;
}
@@ -79,6 +79,7 @@ public abstract class Location<E extends PsiElement> {
return null;
}
@NotNull
public PsiLocation<E> toPsiLocation() {
return new PsiLocation<E>(getProject(), getPsiElement());
}
@@ -38,7 +38,7 @@ public class PsiLocation<E extends PsiElement> extends Location<E> {
myModule = ModuleUtil.findModuleForPsiElement(psiElement);
}
public PsiLocation(Project project, Module module, E psiElement) {
public PsiLocation(@NotNull Project project, Module module, @NotNull E psiElement) {
myPsiElement = psiElement;
myProject = project;
myModule = module;
@@ -60,10 +60,8 @@ public class PsiLocation<E extends PsiElement> extends Location<E> {
}
@NotNull
public <T extends PsiElement> Iterator<Location<T>> getAncestors(final Class<T> ancestorClass, final boolean strict) {
final T first;
if (!strict && ancestorClass.isInstance(myPsiElement)) first = (T)myPsiElement;
else first = findNext(myPsiElement, ancestorClass);
public <T extends PsiElement> Iterator<Location<T>> getAncestors(@NotNull final Class<T> ancestorClass, final boolean strict) {
final T first = strict || !ancestorClass.isInstance(myPsiElement) ? findNext(myPsiElement, ancestorClass) : (T)myPsiElement;
return new Iterator<Location<T>>() {
private T myCurrent = first;
public boolean hasNext() {
@@ -83,6 +81,7 @@ public class PsiLocation<E extends PsiElement> extends Location<E> {
};
}
@NotNull
public PsiLocation<E> toPsiLocation() {
return this;
}
@@ -96,7 +95,7 @@ public class PsiLocation<E extends PsiElement> extends Location<E> {
return null;
}
public static <T extends PsiElement> Location<T> fromPsiElement(final Project project, final T element) {
public static <T extends PsiElement> Location<T> fromPsiElement(@NotNull Project project, final T element) {
if (element == null) return null;
return new PsiLocation<T>(project, element);
}
@@ -106,8 +105,7 @@ public class PsiLocation<E extends PsiElement> extends Location<E> {
}
public static <T extends PsiElement> Location<T> fromPsiElement(T element, Module module) {
if (element == null) return null;
if (!element.isValid()) return null;
if (element == null || !element.isValid()) return null;
return module != null ? new PsiLocation<T>(element.getProject(), module, element) : new PsiLocation<T>(element.getProject(), element);
}
}
@@ -15,8 +15,10 @@
*/
package com.intellij.util.ui;
import org.jetbrains.annotations.NonNls;
public interface ClientPropertyHolder {
void putClientProperty(String key, Object value);
void putClientProperty(@NonNls String key, @NonNls Object value);
}
@@ -64,6 +64,7 @@ import java.util.regex.Pattern;
/**
* @author max
*/
@SuppressWarnings("StaticMethodOnlyUsedInOneClass")
public class UIUtil {
private static final String TABLE_DECORATION_KEY = "TABLE_DECORATION_KEY";
@@ -116,7 +117,7 @@ public class UIUtil {
// accessed only from EDT
private static final HashMap<Color, BufferedImage> ourAppleDotSamples = new HashMap<Color, BufferedImage>();
private static final String ROOT_PANE = "JRootPane.future";
@NonNls private static final String ROOT_PANE = "JRootPane.future";
private UIUtil() { }
@@ -207,6 +208,7 @@ public class UIUtil {
g.drawLine(x1, y1, x2, y2);
}
@NotNull
public static String[] splitText(String text, FontMetrics fontMetrics, int widthLimit, char separator) {
ArrayList<String> lines = new ArrayList<String>();
String currentLine = "";
@@ -753,7 +755,8 @@ public class UIUtil {
return theme.toString();
}
}
catch (Exception ignore) { }
catch (Exception ignored) {
}
}
return null;
}
@@ -1265,7 +1268,7 @@ public class UIUtil {
}
public static boolean isActionClick(MouseEvent e, int effectiveType, boolean allowShift) {
if ((!allowShift && isCloseClick(e)) || e.isPopupTrigger() || e.getID() != effectiveType) return false;
if (!allowShift && isCloseClick(e) || e.isPopupTrigger() || e.getID() != effectiveType) return false;
return e.getButton() == MouseEvent.BUTTON1;
}
@@ -1296,13 +1299,13 @@ public class UIUtil {
public static String getCssFontDeclaration(final Font font, @Nullable Color fgColor, @Nullable Color linkColor, @Nullable String liImg) {
URL resource = liImg != null ? SystemInfo.class.getResource(liImg) : null;
String fontFamilyAndSize = "font-family:" + font.getFamily() + "; font-size:" + font.getSize() + ";";
//@Language("CSS")
@NonNls String fontFamilyAndSize = "font-family:" + font.getFamily() + "; font-size:" + font.getSize() + ";";
@NonNls @Language("HTML")
String body = "body, div, td {" + fontFamilyAndSize + " " + (fgColor != null ? "color:" + ColorUtil.toHex(fgColor) : "") + "}";
if (resource != null) {
body += "ul {list-style-image: " + resource.toExternalForm() +"}";
}
String link = linkColor != null ? "a {" + fontFamilyAndSize + " color:" + ColorUtil.toHex(linkColor) + "}" : "";
@NonNls String link = linkColor != null ? "a {" + fontFamilyAndSize + " color:" + ColorUtil.toHex(linkColor) + "}" : "";
return "<style> " + body + " " + link + "</style>";
}
@@ -1548,8 +1551,8 @@ public class UIUtil {
Point containerLocation = container.getLocation();
Dimension containerSize = container.getSize();
result.x = containerLocation.x + (containerSize.width / 2 - child.width / 2);
result.y = containerLocation.y + (containerSize.height / 2 - child.height / 2);
result.x = containerLocation.x + containerSize.width / 2 - child.width / 2;
result.y = containerLocation.y + containerSize.height / 2 - child.height / 2;
return result;
}
@@ -1575,7 +1578,7 @@ public class UIUtil {
}
public static String convertSpace2Nbsp(String html) {
StringBuilder result = new StringBuilder();
@NonNls StringBuilder result = new StringBuilder();
int currentPos = 0;
int braces = 0;
while (currentPos < html.length()) {
@@ -1753,7 +1756,7 @@ public class UIUtil {
}
public static class MacTreeUI extends BasicTreeUI {
public static final String SOURCE_LIST_CLIENT_PROPERTY = "mac.ui.source.list";
@NonNls public static final String SOURCE_LIST_CLIENT_PROPERTY = "mac.ui.source.list";
private static final Icon TREE_COLLAPSED_ICON = getTreeCollapsedIcon();
private static final Icon TREE_EXPANDED_ICON = getTreeExpandedIcon();
@@ -1790,7 +1793,7 @@ public class UIUtil {
if (pressedPath != null) {
Rectangle bounds = getPathBounds(tree, pressedPath);
if (e.getY() >= (bounds.y + bounds.height)) {
if (e.getY() >= bounds.y + bounds.height) {
return;
}
@@ -1849,14 +1852,14 @@ public class UIUtil {
public void actionPerformed(ActionEvent e) {
final Object source = e.getSource();
if (source instanceof JTree) {
int toSelect = -1;
int toScroll = -1;
JTree tree = (JTree)source;
int selectionRow = tree.getLeadSelectionRow();
if (selectionRow != -1) {
TreePath selectionPath = tree.getPathForRow(selectionRow);
if (selectionPath != null) {
boolean leaf = tree.getModel().isLeaf(selectionPath.getLastPathComponent());
int toSelect = -1;
int toScroll = -1;
if (!leaf && tree.isExpanded(selectionRow)) {
if (selectionRow + 1 < tree.getRowCount()) {
toSelect = selectionRow + 1;
@@ -1966,7 +1969,7 @@ public class UIUtil {
rowGraphics.setClip(clipBounds);
final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
if (sourceList != null && ((Boolean)sourceList)) {
if (sourceList != null && (Boolean)sourceList) {
if (selected) {
if (tree.hasFocus()) {
LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
@@ -2011,7 +2014,7 @@ public class UIUtil {
// draw background for the given clip bounds
final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
if (sourceList != null && ((Boolean)sourceList)) {
if (sourceList != null && (Boolean)sourceList) {
Graphics2D backgroundGraphics = (Graphics2D)g.create();
backgroundGraphics.setClip(xOffset, bounds.y, containerWidth, bounds.height);
LIST_BACKGROUND_PAINTER.paintBorder(tree, backgroundGraphics, xOffset, bounds.y, containerWidth, bounds.height);
@@ -2196,7 +2199,7 @@ public class UIUtil {
}
public TextPainter underlined(final Color color) {
if (myLines.size() > 0) {
if (!myLines.isEmpty()) {
final LineInfo info = myLines.get(myLines.size() - 1).getSecond();
info.underlined = true;
info.underlineColor = color;
@@ -2206,7 +2209,7 @@ public class UIUtil {
}
public TextPainter withBullet(final char c) {
if (myLines.size() > 0) {
if (!myLines.isEmpty()) {
final LineInfo info = myLines.get(myLines.size() - 1).getSecond();
info.withBullet = true;
info.bulletChar = c;
@@ -2224,7 +2227,7 @@ public class UIUtil {
}
public TextPainter smaller() {
if (myLines.size() > 0) {
if (!myLines.isEmpty()) {
myLines.get(myLines.size() - 1).getSecond().smaller = true;
}
@@ -2232,7 +2235,7 @@ public class UIUtil {
}
public TextPainter center() {
if (myLines.size() > 0) {
if (!myLines.isEmpty()) {
myLines.get(myLines.size() - 1).getSecond().center = true;
}
@@ -2243,9 +2246,9 @@ public class UIUtil {
* _position(block width, block height) => (x, y) of the block
*/
public void draw(@NotNull final Graphics g, final PairFunction<Integer, Integer, Pair<Integer, Integer>> _position) {
final int[] maxWidth = new int[] {0};
final int[] height = new int[] {0};
final int[] maxBulletWidth = new int[] {0};
final int[] maxWidth = {0};
final int[] height = {0};
final int[] maxBulletWidth = {0};
ContainerUtil.process(myLines, new Processor<Pair<String, LineInfo>>() {
@Override
public boolean process(final Pair<String, LineInfo> pair) {
@@ -2275,7 +2278,7 @@ public class UIUtil {
final Pair<Integer, Integer> position = _position.fun(maxWidth[0] + 20, height[0]);
assert position != null;
final int[] yOffset = new int[] {position.getSecond()};
final int[] yOffset = {position.getSecond()};
ContainerUtil.process(myLines, new Processor<Pair<String, LineInfo>>() {
@Override
public boolean process(final Pair<String, LineInfo> pair) {
@@ -2299,7 +2302,7 @@ public class UIUtil {
g.setColor(myMacShadowColor);
if (info.withBullet) {
g.drawString(String.valueOf(info.bulletChar) + " ", x - fm.stringWidth(" " + info.bulletChar), yOffset[0] + 1);
g.drawString(info.bulletChar + " ", x - fm.stringWidth(" " + info.bulletChar), yOffset[0] + 1);
}
g.drawString(pair.getFirst(), xOffset, yOffset[0] + 1);
@@ -2307,13 +2310,13 @@ public class UIUtil {
}
if (info.withBullet) {
g.drawString(String.valueOf(info.bulletChar) + " ", x - fm.stringWidth(" " + info.bulletChar), yOffset[0]);
g.drawString(info.bulletChar + " ", x - fm.stringWidth(" " + info.bulletChar), yOffset[0]);
}
g.drawString(pair.getFirst(), xOffset, yOffset[0]);
Color c = null;
if (info.underlined) {
Color c = null;
if (info.underlineColor != null) {
c = g.getColor();
g.setColor(info.underlineColor);
@@ -2322,7 +2325,6 @@ public class UIUtil {
g.drawLine(x - maxBulletWidth[0] - 10, yOffset[0] + fm.getDescent(), x + maxWidth[0] + 10, yOffset[0] + fm.getDescent());
if (c != null) {
g.setColor(c);
c = null;
}
if (myDrawMacShadow && UIUtil.isUnderAquaLookAndFeel()) {
@@ -2330,7 +2332,6 @@ public class UIUtil {
g.setColor(myMacShadowColor);
g.drawLine(x - maxBulletWidth[0] - 10, yOffset[0] + fm.getDescent() + 1, x + maxWidth[0] + 10, yOffset[0] + fm.getDescent() + 1);
g.setColor(c);
c = null;
}
}
@@ -44,18 +44,14 @@ public class MvcModuleBuilder extends GroovyAwareModuleBuilder {
}
private class GroovySdkWizardStep extends ModuleWizardStep {
private final LibraryOptionsPanel myPanel;
private LibraryOptionsPanel myPanel;
private final LibrariesContainer myLibrariesContainer;
private boolean myDownloaded;
private LibraryCompositionSettings myLibraryCompositionSettings;
public GroovySdkWizardStep(WizardContext wizardContext) {
final Project project = wizardContext.getProject();
final GroovyLibraryDescription libraryDescription = myFramework.createLibraryDescription();
final String contentEntryPath = getContentEntryPath();
final String basePath = contentEntryPath != null ? FileUtil.toSystemIndependentName(contentEntryPath) : "";
myLibrariesContainer = LibrariesContainerFactory.createContainer(project);
myPanel = new LibraryOptionsPanel(libraryDescription, basePath, null, myLibrariesContainer, false);
addModuleConfigurationUpdater(new ModuleConfigurationUpdater() {
@Override
public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
@@ -69,12 +65,14 @@ public class MvcModuleBuilder extends GroovyAwareModuleBuilder {
@Override
public void disposeUIResources() {
Disposer.dispose(myPanel);
if (myPanel != null) {
Disposer.dispose(myPanel);
}
}
@Override
public JComponent getComponent() {
final JComponent component = myPanel.getMainPanel();
final JComponent component = getPanel().getMainPanel();
final JPanel panel = new JPanel(new BorderLayout());
panel.add(component, BorderLayout.NORTH);
@@ -96,7 +94,7 @@ public class MvcModuleBuilder extends GroovyAwareModuleBuilder {
@Override
public void _commit(boolean finishChosen) throws CommitStepException {
if (finishChosen && !myDownloaded && myLibraryCompositionSettings != null) {
if (myLibraryCompositionSettings.downloadFiles(myPanel.getMainPanel())) {
if (myLibraryCompositionSettings.downloadFiles(getPanel().getMainPanel())) {
myDownloaded = true;
}
}
@@ -104,7 +102,17 @@ public class MvcModuleBuilder extends GroovyAwareModuleBuilder {
@Override
public void updateDataModel() {
myLibraryCompositionSettings = myPanel.apply();
myLibraryCompositionSettings = getPanel().apply();
}
private synchronized LibraryOptionsPanel getPanel() {
if (myPanel == null) {
final GroovyLibraryDescription libraryDescription = myFramework.createLibraryDescription();
final String contentEntryPath = getContentEntryPath();
final String basePath = contentEntryPath != null ? FileUtil.toSystemIndependentName(contentEntryPath) : "";
myPanel = new LibraryOptionsPanel(libraryDescription, basePath, null, myLibrariesContainer, false);
}
return myPanel;
}
}
}
@@ -19,6 +19,7 @@ package com.intellij.execution;
import com.intellij.execution.junit.JUnitUtil;
import com.intellij.execution.junit.TestClassFilter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
@@ -38,7 +39,8 @@ public class ConfigurationUtil {
public static boolean findAllTestClasses(final TestClassFilter testClassFilter, final Set<PsiClass> found) {
final PsiManager manager = testClassFilter.getPsiManager();
GlobalSearchScope projectScopeWithoutLibraries = GlobalSearchScope.projectScope(manager.getProject());
final Project project = manager.getProject();
GlobalSearchScope projectScopeWithoutLibraries = GlobalSearchScope.projectScope(project);
final GlobalSearchScope scope = projectScopeWithoutLibraries.intersectWith(testClassFilter.getScope());
ClassInheritorsSearch.search(testClassFilter.getBase(), scope, true).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
public boolean execute(final PsiClass aClass) {
@@ -51,7 +53,7 @@ public class ConfigurationUtil {
final PsiMethod[] suiteMethods = ApplicationManager.getApplication().runReadAction(
new Computable<PsiMethod[]>() {
public PsiMethod[] compute() {
return JavaPsiFacade.getInstance(manager.getProject()).getShortNamesCache().getMethodsByName(JUnitUtil.SUITE_METHOD_NAME, scope);
return JavaPsiFacade.getInstance(project).getShortNamesCache().getMethodsByName(JUnitUtil.SUITE_METHOD_NAME, scope);
}
}
);
@@ -67,7 +69,7 @@ public class ConfigurationUtil {
if (containingClass.getContainingClass() != null && !containingClass.hasModifierProperty(PsiModifier.STATIC)) continue;
if (ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
public Boolean compute() {
return JUnitUtil.isSuiteMethod(method);
return JUnitUtil.isSuiteMethod(method, project);
}
}).booleanValue()) {
found.add(containingClass);