binding.setVariable("commonJvmArgsForTests", {
def jdwp = "-Xrunjdwp:transport=dt_socket,server=y,suspend=$debugSuspend"
if (debugPort != null) jdwp += ",address=$debugPort"
+
return [
"-ea",
"-Dio.netty.leakDetectionLevel=PARANOID",
return pathname.isDirectory() && !TEMP_DIR_NAME.equals(pathname.getName());
}
});
- final Date now = new Date();
- for (File buildDataProjectDir : dirs) {
- final File usageFile = getUsageFile(buildDataProjectDir);
- if (usageFile.exists()) {
- final Pair<Date, File> usageData = readUsageFile(usageFile);
- if (usageData != null) {
- final File projectFile = usageData.second;
- if ((projectFile != null && !projectFile.exists()) || DateFormatUtil.getDifferenceInDays(usageData.first, now) > unusedThresholdDays) {
- LOG.info("Clearing project build data because the project does not exist or was not opened for more than " + unusedThresholdDays + " days: " + buildDataProjectDir.getPath());
- FileUtil.delete(buildDataProjectDir);
+ if (dirs != null) {
+ final Date now = new Date();
+ for (File buildDataProjectDir : dirs) {
+ final File usageFile = getUsageFile(buildDataProjectDir);
+ if (usageFile.exists()) {
+ final Pair<Date, File> usageData = readUsageFile(usageFile);
+ if (usageData != null) {
+ final File projectFile = usageData.second;
+ if ((projectFile != null && !projectFile.exists()) || DateFormatUtil.getDifferenceInDays(usageData.first, now) > unusedThresholdDays) {
+ LOG.info("Clearing project build data because the project does not exist or was not opened for more than " + unusedThresholdDays + " days: " + buildDataProjectDir.getPath());
+ FileUtil.delete(buildDataProjectDir);
+ }
}
}
- }
- else {
- updateUsageFile(null, buildDataProjectDir); // set usage stamp to start countdown
+ else {
+ updateUsageFile(null, buildDataProjectDir); // set usage stamp to start countdown
+ }
}
}
}
@Override
public void projectOpened(final Project project) {
+ if (ApplicationManager.getApplication().isUnitTestMode()) return;
final MessageBusConnection conn = project.getMessageBus().connect();
myConnections.put(project, conn);
conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.registry.Registry;
import com.intellij.util.xmlb.XmlSerializerUtil;
@State(
}
public boolean allowAutoMakeWhileRunningApplication() {
- return false;/*ALLOW_AUTOMAKE_WHILE_RUNNING_APPLICATION*/
+ return Registry.is("compiler.automake.allow.when.app.running", false);/*ALLOW_AUTOMAKE_WHILE_RUNNING_APPLICATION*/
}
}
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.debugger.engine.LambdaMethodFilter;
import com.intellij.debugger.engine.MethodFilter;
import com.intellij.debugger.impl.DebuggerSession;
-import com.intellij.openapi.actionSystem.ActionManager;
-import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.fileEditor.TextEditor;
-import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.ui.awt.RelativePoint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
-import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.List;
session.stepInto(true, createMethodFilter(chosenTarget));
}
});
- final ListPopup popup = new ListPopupImpl(popupStep) {
- @Override
- protected JComponent createContent() {
- registerExtraHandleShortcuts(XDebuggerActions.STEP_INTO);
- registerExtraHandleShortcuts(XDebuggerActions.SMART_STEP_INTO);
- return super.createContent();
- }
-
- private void registerExtraHandleShortcuts(String actionName) {
- AnAction action = ActionManager.getInstance().getAction(actionName);
- KeyStroke stroke = KeymapUtil.getKeyStroke(action.getShortcutSet());
- if (stroke != null) {
- registerAction("handleSelection " + stroke, stroke, new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- handleSelect(true);
- }
- });
- }
- }
- };
+ ListPopupImpl popup = new ListPopupImpl(popupStep);
+ DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO);
+ DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.SMART_STEP_INTO);
popup.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
popupStep.getScopeHighlighter().dropHighlight();
import com.intellij.execution.ui.layout.PlaceInGrid;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.editor.Document;
import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
}
}
- private void showAlternativeNotification(XStackFrame frame) {
- XSourcePosition position = frame.getSourcePosition();
- if (position != null) {
- VirtualFile file = position.getFile();
- if (!AlternativeSourceNotificationProvider.fileProcessed(file)) {
- EditorNotifications.getInstance(session.getProject()).updateNotifications(file);
+ private void showAlternativeNotification(@Nullable XStackFrame frame) {
+ if (frame != null) {
+ XSourcePosition position = frame.getSourcePosition();
+ if (position != null) {
+ VirtualFile file = position.getFile();
+ if (!AlternativeSourceNotificationProvider.fileProcessed(file)) {
+ EditorNotifications.getInstance(session.getProject()).updateNotifications(file);
+ }
}
}
}
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.impl.DocumentMarkupModel;
-import com.intellij.openapi.editor.markup.HighlighterTargetArea;
-import com.intellij.openapi.editor.markup.RangeHighlighter;
-import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.EmptyIterable;
import com.intellij.xdebugger.impl.ui.ExecutionPointHighlighter;
-import com.intellij.xdebugger.ui.DebuggerColors;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
@Nullable
@Override
- public RangeHighlighter createHighlighter(Document document, Project project, TextAttributes attributes) {
+ public TextRange getHighlightRange() {
PsiElement element = getElementAt();
NavigatablePsiElement method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiLambdaExpression.class);
if (method instanceof PsiLambdaExpression) {
- TextRange range = method.getTextRange();
- int startOffset = document.getLineStartOffset(getLine());
- int endOffset = document.getLineEndOffset(getLine());
- int hlStart = Math.max(startOffset, range.getStartOffset());
- int hlEnd = Math.min(endOffset, range.getEndOffset());
- if (hlStart != startOffset || hlEnd != endOffset) {
- return DocumentMarkupModel.forDocument(document, project, true).
- addRangeHighlighter(hlStart, hlEnd, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes,
- HighlighterTargetArea.EXACT_RANGE);
- }
+ return method.getTextRange();
}
return null;
}
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.markup.RangeHighlighter;
-import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.ui.content.Content;
import com.intellij.unscramble.ThreadDumpPanel;
import com.intellij.unscramble.ThreadState;
+import com.intellij.util.DocumentUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xdebugger.XSourcePosition;
@Nullable
@Override
- public RangeHighlighter createHighlighter(Document document, Project project, TextAttributes attributes) {
+ public TextRange getHighlightRange() {
if (mySourcePosition instanceof ExecutionPointHighlighter.HighlighterProvider) {
- return ((ExecutionPointHighlighter.HighlighterProvider)mySourcePosition).createHighlighter(document, project, attributes);
+ return ((ExecutionPointHighlighter.HighlighterProvider)mySourcePosition).getHighlightRange();
}
return null;
}
return null;
}
- public static List<PsiLambdaExpression> collectLambdas(SourcePosition position, final boolean onlyOnTheLine) {
+ public static List<PsiLambdaExpression> collectLambdas(@NotNull SourcePosition position, final boolean onlyOnTheLine) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFile file = position.getFile();
- int line = position.getLine();
- Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
+ final int line = position.getLine();
+ final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null || line >= document.getLineCount()) {
return Collections.emptyList();
}
PsiElement element = position.getElementAt();
- final TextRange lineRange = new TextRange(document.getLineStartOffset(line), document.getLineEndOffset(line));
+ final TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
do {
PsiElement parent = element.getParent();
if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) {
@Override
public void visitLambdaExpression(PsiLambdaExpression expression) {
super.visitLambdaExpression(expression);
- if (!onlyOnTheLine || lineRange.intersects(expression.getTextRange())) {
+ if (!onlyOnTheLine || getFirstElementOnTheLine(expression, document, line) != null) {
lambdas.add(expression);
}
}
lambdas.add((PsiLambdaExpression)method);
}
for (PsiElement sibling = getNextElement(element); sibling != null; sibling = getNextElement(sibling)) {
- if (!lineRange.intersects(sibling.getTextRange())) {
+ if (!intersects(lineRange, sibling)) {
break;
}
sibling.accept(lambdaCollector);
return lambdas;
}
+ public static boolean intersects(@NotNull TextRange range, @NotNull PsiElement elem) {
+ TextRange elemRange = elem.getTextRange();
+ return elemRange != null && elemRange.intersects(range);
+ }
+
@Nullable
public static PsiElement getFirstElementOnTheLine(PsiLambdaExpression lambda, Document document, int line) {
ApplicationManager.getApplication().assertReadAccessAllowed();
- TextRange lineRange = new TextRange(document.getLineStartOffset(line), document.getLineEndOffset(line));
- if (!lineRange.intersects(lambda.getTextRange())) return null;
+ TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
+ if (!intersects(lineRange, lambda)) return null;
PsiElement body = lambda.getBody();
+ if (body == null || !intersects(lineRange, body)) return null;
if (body instanceof PsiCodeBlock) {
for (PsiStatement statement : ((PsiCodeBlock)body).getStatements()) {
- if (lineRange.intersects(statement.getTextRange())) {
+ if (intersects(lineRange, statement)) {
return statement;
}
}
+ return null;
}
return body;
}
+ public static boolean inTheMethod(@NotNull SourcePosition pos, @NotNull PsiElement method) {
+ PsiElement elem = pos.getElementAt();
+ if (elem == null) return false;
+ NavigatablePsiElement elemMethod = PsiTreeUtil.getParentOfType(elem, PsiMethod.class, PsiLambdaExpression.class);
+ return Comparing.equal(elemMethod, method);
+ }
+
public static boolean inTheSameMethod(@NotNull SourcePosition pos1, @NotNull SourcePosition pos2) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiElement elem1 = pos1.getElementAt();
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule;
import com.intellij.xdebugger.impl.XSourcePositionImpl;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariant;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariantsProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties;
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
import javax.swing.*;
* Base class for java line-connected exceptions (line, method, field)
* @author egor
*/
-public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaBreakpointProperties>
- implements JavaBreakpointType, XLineBreakpointVariantsProvider<JavaLineBreakpointType.JavaBreakpointVariant> {
+public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineBreakpointProperties> implements JavaBreakpointType {
public JavaLineBreakpointType() {
super("java-line", DebuggerBundle.message("line.breakpoints.tab.title"));
}
}
@Override
- public List<XBreakpointGroupingRule<XLineBreakpoint<JavaBreakpointProperties>, ?>> getGroupingRules() {
+ public List<XBreakpointGroupingRule<XLineBreakpoint<JavaLineBreakpointProperties>, ?>> getGroupingRules() {
return XDebuggerUtil.getInstance().getGroupingByFileRuleAsList();
}
@NotNull
@Override
- public List<JavaBreakpointVariant> computeLineBreakpointVariants(@NotNull Project project, @NotNull XSourcePosition position) {
+ public List<JavaBreakpointVariant> computeVariants(@NotNull Project project, @NotNull XSourcePosition position) {
PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
if (file == null) {
return Collections.emptyList();
res.add(new JavaBreakpointVariant(position)); //all
if (startMethod instanceof PsiMethod) {
- res.add(new ExactJavaBreakpointVariant(position, startMethod)); // base method
+ res.add(new ExactJavaBreakpointVariant(position, startMethod, -1)); // base method
}
+ int ordinal = 0;
for (PsiLambdaExpression lambda : lambdas) { //lambdas
PsiElement firstElem = DebuggerUtilsEx.getFirstElementOnTheLine(lambda, document, position.getLine());
- res.add(new ExactJavaBreakpointVariant(XSourcePositionImpl.createByElement(firstElem), lambda));
+ res.add(new ExactJavaBreakpointVariant(XSourcePositionImpl.createByElement(firstElem), lambda, ordinal++));
}
return res;
private class ExactJavaBreakpointVariant extends JavaBreakpointVariant {
private final PsiElement myElement;
+ private final Integer myLambdaOrdinal;
- public ExactJavaBreakpointVariant(XSourcePosition position, PsiElement element) {
+ public ExactJavaBreakpointVariant(XSourcePosition position, PsiElement element, Integer lambdaOrdinal) {
super(position);
myElement = element;
+ myLambdaOrdinal = lambdaOrdinal;
}
@Override
@Override
public JavaLineBreakpointProperties createProperties() {
JavaLineBreakpointProperties properties = super.createProperties();
- properties.setOffset(mySourcePosition.getOffset());
+ properties.setLambdaOrdinal(myLambdaOrdinal);
return properties;
}
}
+
+ @Nullable
+ @Override
+ public TextRange getHighlightRange(XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
+ JavaLineBreakpointProperties properties = breakpoint.getProperties();
+ if (properties != null) {
+ Integer ordinal = properties.getLambdaOrdinal();
+ if (ordinal != null) {
+ Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
+ if (javaBreakpoint instanceof LineBreakpoint) {
+ PsiElement method = ((LineBreakpoint)javaBreakpoint).getContainingMethod();
+ if (method != null) {
+ return method.getTextRange();
+ }
+ }
+ }
+ }
+ return null;
+ }
}
@Override
public Boolean compute() {
if (getProperties() instanceof JavaLineBreakpointProperties) {
- Integer offset = ((JavaLineBreakpointProperties)getProperties()).getOffset();
- if (offset == null) return true;
- PsiFile file = getPsiFile();
- if (file != null) {
- SourcePosition exactPosition = SourcePosition.createFromOffset(file, offset);
- SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
- if (position == null) return false;
- return DebuggerUtilsEx.inTheSameMethod(exactPosition, position);
- }
+ Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
+ if (ordinal == null) return true;
+ PsiElement containingMethod = getContainingMethod();
+ if (containingMethod == null) return false;
+ SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
+ if (position == null) return false;
+ return DebuggerUtilsEx.inTheMethod(position, containingMethod);
}
return true;
}
});
}
+ @Nullable
+ public PsiElement getContainingMethod() {
+ SourcePosition position = getSourcePosition();
+ if (position == null) return null;
+ if (getProperties() instanceof JavaLineBreakpointProperties) {
+ Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
+ if (ordinal > -1) {
+ List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(position, true);
+ if (ordinal < lambdas.size()) {
+ return lambdas.get(ordinal);
+ }
+ }
+ }
+ return PsiTreeUtil.getParentOfType(position.getElementAt(), PsiMethod.class, PsiLambdaExpression.class);
+ }
+
private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
final SourcePosition position = getSourcePosition();
if (position != null) {
* @author egor
*/
public class JavaLineBreakpointProperties extends JavaBreakpointProperties<JavaLineBreakpointProperties> {
- private Integer myOffset = null;
+ // null - stop at all positions on the line
+ // -1 - stop only at the base position (first on the line)
+ // 0 or more - index of the lambda on the line to stop at
+ private Integer myLambdaOrdinal = null;
- @OptionTag("offset")
- public Integer getOffset() {
- return myOffset;
+ @OptionTag("lambda-ordinal")
+ public Integer getLambdaOrdinal() {
+ return myLambdaOrdinal;
}
- public void setOffset(Integer offset) {
- myOffset = offset;
+ public void setLambdaOrdinal(Integer lambdaOrdinal) {
+ myLambdaOrdinal = lambdaOrdinal;
}
}
return null;
}
getJavaParameters().getVMParametersList().addProperty("idea." + getFrameworkId() + ".sm_runner");
- getJavaParameters().getClassPath().addFirst(PathUtil.getJarPathForClass(ServiceMessageTypes.class));
final RunnerSettings runnerSettings = getRunnerSettings();
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ProjectFileIndex;
+import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.util.ClassUtil;
-import com.intellij.psi.util.PsiClassUtil;
-import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
return name == null || name.startsWith(ExecutionBundle.message("run.configuration.unnamed.name.prefix"));
}
+ @Nullable
public static Location stepIntoSingleClass(@NotNull final Location location) {
PsiElement element = location.getPsiElement();
if (!(element instanceof PsiClassOwner)) {
element = PsiTreeUtil.getParentOfType(element, PsiClassOwner.class);
if (element == null) return location;
}
+ final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
+ final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(location.getProject()).getFileIndex();
+ if (virtualFile == null || !fileIndex.isInSource(virtualFile)) {
+ return null;
+ }
final PsiClassOwner psiFile = (PsiClassOwner)element;
final PsiClass[] classes = psiFile.getClasses();
if (classes.length != 1) return location;
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
final JScrollPane pane = ScrollPaneFactory.createScrollPane(myContent, true);
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(pane);
- myAlarm = new Alarm(this);
+ myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this);
project.getMessageBus().connect(this).subscribe(ConfigurationErrors.TOPIC, this);
myContent.addHyperlinkListener(new HyperlinkAdapter() {
@Override
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
- String html = "<html>" +
- "<header><style type='text/css'>" +
- "body {" +
- " color: #" + ColorUtil.toHex(new JBColor(Gray.x33, UIUtil.getLabelForeground())) + ";" +
- " font-family: '" + UIUtil.getLabelFont().getName() + ",serif';" +
- " font-size: " + UIUtil.getLabelFont().getSize() + ";" +
- "}" +
- "li {" +
- " margin-bottom: 5;" +
- "}" +
- "ol {" +
- "}" +
- "a {" +
- " text-decoration: none;" +
- "}" +
- "</style>" +
- "</header>" +
- "<body>";
+ final String header = "<html>" +
+ "<header><style type='text/css'>" +
+ "body {" +
+ " color: #" + ColorUtil.toHex(new JBColor(Gray.x33, UIUtil.getLabelForeground())) + ";" +
+ " font-family: '" + UIUtil.getLabelFont().getName() + ",serif';" +
+ " font-size: " + UIUtil.getLabelFont().getSize() + ";" +
+ "}" +
+ "li {" +
+ " margin-bottom: 5;" +
+ "}" +
+ "ol {" +
+ "}" +
+ "a {" +
+ " text-decoration: none;" +
+ "}" +
+ "</style>" +
+ "</header>" +
+ "<body>";
+ final StringBuilder html = new StringBuilder(header);
int i = 0;
- html += "<ol>";
+ html.append("<ol>");
for (ConfigurationError error : myErrors) {
i++;
+ if (i > 100) break;
+ html.append("<li>");
String description = error.getDescription();
if (description.startsWith("<html>") && description.endsWith("</html>")) {
description = description.substring(6, description.length() - 7);
if (error.canBeFixed()) {
description += " <a href='http://fix/" + i + "'>[Fix]</a>";
}
- html+= "<li>" + description + "</li>";
+ html.append(description).append("</li>");
}
- html += "</ol></body></html>";
- myContent.setText(html);
+ html.append("</ol></body></html>");
+ //noinspection SSBasedInspection
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ if (!Disposer.isDisposed(ErrorPaneConfigurable.this)) {
+ myContent.setText(html.toString());
+ }
+ }
+ });
if (myOnErrorsChanged != null) {
myOnErrorsChanged.run();
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if ("Problems".equals(descriptor.getTextFor(value))) {
final ErrorPaneConfigurable errorPane = (ErrorPaneConfigurable)((Place)value).getPath("category");
- if (errorPane != null && errorPane.getErrorsCount() > 0) {
+ int errorsCount;
+ if (errorPane != null && (errorsCount = errorPane.getErrorsCount()) > 0) {
myCountLabel.setSelected(isSelected);
- myCountLabel.setText(String.valueOf(errorPane.getErrorsCount()));
+ myCountLabel.setText(errorsCount > 100 ? "100+" : String.valueOf(errorsCount));
}
}
if (UIUtil.getClientProperty(list, ExpandableItemsHandler.EXPANDED_RENDERER) == Boolean.TRUE) {
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
parent instanceof PsiPrefixExpression &&
((PsiPrefixExpression)parent).getOperationTokenType() == JavaTokenType.MINUS)) {
if (text.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
- final String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (text.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
- final String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (value == null || text.equals(PsiLiteralExpressionImpl._2_IN_31)) {
- final String message = JavaErrorMessages.message("integer.number.too.large");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("integer.number.too.large");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
else if (type == JavaTokenType.LONG_LITERAL) {
- final String mText = text.endsWith("l") ? text.substring(0, text.length() - 1) : text;
+ String mText = text.endsWith("l") ? text.substring(0, text.length() - 1) : text;
//literal 9223372036854775808L may appear only as the operand of the unary negation operator -.
if (!(mText.equals(PsiLiteralExpressionImpl._2_IN_63) &&
parent instanceof PsiPrefixExpression &&
((PsiPrefixExpression)parent).getOperationTokenType() == JavaTokenType.MINUS)) {
if (mText.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
- final String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (mText.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
- final String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (value == null || mText.equals(PsiLiteralExpressionImpl._2_IN_63)) {
- final String message = JavaErrorMessages.message("long.number.too.large");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("long.number.too.large");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
else if (isFP) {
if (value == null) {
- final String message = JavaErrorMessages.message("malformed.floating.point.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("malformed.floating.point.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
else if (type == JavaTokenType.CHARACTER_LITERAL) {
- // todo[r.sh] clean this mess up
if (value != null) {
if (!StringUtil.endsWithChar(text, '\'')) {
- final String message = JavaErrorMessages.message("unclosed.char.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("unclosed.char.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
else {
- if (!StringUtil.startsWithChar(text, '\'')) return null;
+ if (!StringUtil.startsWithChar(text, '\'')) {
+ return null;
+ }
if (StringUtil.endsWithChar(text, '\'')) {
if (text.length() == 1) {
- final String message = JavaErrorMessages.message("illegal.line.end.in.character.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.line.end.in.character.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
text = text.substring(1, text.length() - 1);
}
else {
- final String message = JavaErrorMessages.message("illegal.line.end.in.character.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.line.end.in.character.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
+
StringBuilder chars = new StringBuilder();
- final boolean success = PsiLiteralExpressionImpl.parseStringCharacters(text, chars, null);
+ boolean success = PsiLiteralExpressionImpl.parseStringCharacters(text, chars, null);
if (!success) {
- final String message = JavaErrorMessages.message("illegal.escape.character.in.character.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.escape.character.in.character.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
int length = chars.length();
if (length > 1) {
- final String message = JavaErrorMessages.message("too.many.characters.in.character.literal");
- final HighlightInfo info =
- HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("too.many.characters.in.character.literal");
+ HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createConvertToStringLiteralAction());
return info;
}
else if (length == 0) {
- final String message = JavaErrorMessages.message("empty.character.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("empty.character.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
else if (type == JavaTokenType.STRING_LITERAL) {
if (value == null) {
- for (final PsiElement element : expression.getChildren()) {
+ for (PsiElement element : expression.getChildren()) {
if (element instanceof OuterLanguageElement) {
return null;
}
if (!StringUtil.startsWithChar(text, '\"')) return null;
if (StringUtil.endsWithChar(text, '\"')) {
if (text.length() == 1) {
- final String message = JavaErrorMessages.message("illegal.line.end.in.string.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.line.end.in.string.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
text = text.substring(1, text.length() - 1);
}
else {
- final String message = JavaErrorMessages.message("illegal.line.end.in.string.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.line.end.in.string.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
+
StringBuilder chars = new StringBuilder();
boolean success = PsiLiteralExpressionImpl.parseStringCharacters(text, chars, null);
if (!success) {
- final String message = JavaErrorMessages.message("illegal.escape.character.in.string.literal");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("illegal.escape.character.in.string.literal");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
if (value instanceof Float) {
- final Float number = (Float)value;
+ Float number = (Float)value;
if (number.isInfinite()) {
- final String message = JavaErrorMessages.message("floating.point.number.too.large");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("floating.point.number.too.large");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (number.floatValue() == 0 && !TypeConversionUtil.isFPZero(text)) {
- final String message = JavaErrorMessages.message("floating.point.number.too.small");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("floating.point.number.too.small");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
else if (value instanceof Double) {
- final Double number = (Double)value;
+ Double number = (Double)value;
if (number.isInfinite()) {
- final String message = JavaErrorMessages.message("floating.point.number.too.large");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("floating.point.number.too.large");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (number.doubleValue() == 0 && !TypeConversionUtil.isFPZero(text)) {
- final String message = JavaErrorMessages.message("floating.point.number.too.small");
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
+ String message = JavaErrorMessages.message("floating.point.number.too.small");
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
@Nullable
- static HighlightInfo checkExpressionRequired(@NotNull PsiReferenceExpression expression,
- @NotNull JavaResolveResult resultForIncompleteCode) {
+ static HighlightInfo checkExpressionRequired(@NotNull PsiReferenceExpression expression, @NotNull JavaResolveResult resultForIncompleteCode) {
if (expression.getNextSibling() instanceof PsiErrorElement) return null;
+
PsiElement resolved = resultForIncompleteCode.getElement();
- if (resolved == null) return null;
+ if (resolved == null || resolved instanceof PsiVariable) return null;
+
PsiElement parent = expression.getParent();
// String.class or String() are both correct
if (parent instanceof PsiReferenceExpression || parent instanceof PsiMethodCallExpression) return null;
- if (resolved instanceof PsiVariable) return null;
+
String description = JavaErrorMessages.message("expression.expected");
- final HighlightInfo info =
- HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
+ HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(expression, new QuickFixActionRegistrarImpl(info));
return info;
}
-
@Nullable
static HighlightInfo checkArrayInitializerApplicable(@NotNull PsiArrayInitializerExpression expression) {
/*
}
String description = JavaErrorMessages.message("array.initializer.not.allowed");
- HighlightInfo info =
- HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
+ HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createAddNewArrayExpressionFix(expression));
return info;
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
PsiTryStatement tryStatement = (PsiTryStatement)element.getParent();
List<PsiClassType> unhandledExceptions = new ArrayList<PsiClassType>(ExceptionUtil.collectUnhandledExceptions(element, null));
+ if (unhandledExceptions.isEmpty()) return;
+
ExceptionUtil.sortExceptionsByHierarchy(unhandledExceptions);
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
return null;
}
}
- boolean hasNonStaticFields = false;
- for (PsiField field : aClass.getFields()) {
- if (!field.hasModifierProperty(PsiModifier.STATIC)) {
- hasNonStaticFields = true;
- break;
- }
- }
+ boolean hasNonStaticFields = hasNonStaticFields(aClass);
if (!hasNonStaticFields) {
HintManager.getInstance().showErrorHint(editor, "No fields to include in equals/hashCode have been found");
return null;
return DUMMY_RESULT;
}
+ private static boolean hasNonStaticFields(PsiClass aClass) {
+ for (PsiField field : aClass.getFields()) {
+ if (!field.hasModifierProperty(PsiModifier.STATIC)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean hasMembers(@NotNull PsiClass aClass) {
+ return hasNonStaticFields(aClass);
+ }
+
@Override
@NotNull
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] originalMembers) throws IncorrectOperationException {
super(chooserTitle);
}
+ @Override
+ protected boolean hasMembers(@NotNull PsiClass aClass) {
+ return !GenerateAccessorProviderRegistrar.getEncapsulatableClassMembers(aClass).isEmpty();
+ }
+
@Override
protected String getHelpId() {
return "Getter and Setter Templates Dialog";
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
import com.intellij.ide.util.MemberChooser;
+import com.intellij.lang.ContextAwareActionHandler;
+import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import java.util.ArrayList;
import java.util.List;
-public abstract class GenerateMembersHandlerBase implements CodeInsightActionHandler {
+public abstract class GenerateMembersHandlerBase implements CodeInsightActionHandler, ContextAwareActionHandler {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.generation.GenerateMembersHandlerBase");
private final String myChooserTitle;
myChooserTitle = chooserTitle;
}
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiClass aClass = OverrideImplementUtil.getContextClass(file.getProject(), editor, file, false);
+ return aClass != null && hasMembers(aClass);
+ }
+
+ protected boolean hasMembers(@NotNull PsiClass aClass) {
+ return true;
+ }
+
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
package com.intellij.codeInsight.generation;
import com.intellij.codeInsight.hint.HintManager;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.lang.LanguageCodeInsightActionHandler;
+import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
/**
* @author yole
*/
-public class JavaImplementMethodsHandler implements LanguageCodeInsightActionHandler {
+public class JavaImplementMethodsHandler implements ContextAwareActionHandler, LanguageCodeInsightActionHandler {
@Override
public boolean isValidFor(final Editor editor, final PsiFile file) {
if (!(file instanceof PsiJavaFile) && !(file instanceof PsiCodeFragment)) {
return false;
}
- PsiClass aClass = OverrideImplementUtil.getContextClass(file.getProject(), editor, file, PsiUtil.isLanguageLevel8OrHigher(file));
- return aClass != null && !OverrideImplementUtil.getMethodSignaturesToImplement(aClass).isEmpty();
+ return OverrideImplementUtil.getContextClass(file.getProject(), editor, file, PsiUtil.isLanguageLevel8OrHigher(file)) != null;
}
@Override
public boolean startInWriteAction() {
return false;
}
+
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ PsiClass aClass = OverrideImplementUtil.getContextClass(file.getProject(), editor, file, PsiUtil.isLanguageLevel8OrHigher(file));
+ return aClass != null && !OverrideImplementUtil.getMethodSignaturesToImplement(aClass).isEmpty();
+ }
}
package com.intellij.codeInsight.generation;
import com.intellij.codeInsight.hint.HintManager;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.lang.LanguageCodeInsightActionHandler;
+import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
/**
* @author yole
*/
-public class JavaOverrideMethodsHandler implements LanguageCodeInsightActionHandler {
+public class JavaOverrideMethodsHandler implements ContextAwareActionHandler, LanguageCodeInsightActionHandler {
@Override
public boolean isValidFor(final Editor editor, final PsiFile file) {
if (!(file instanceof PsiJavaFile) && !(file instanceof PsiCodeFragment)) {
return false;
}
- PsiClass aClass = OverrideImplementUtil.getContextClass(file.getProject(), editor, file, true);
- return aClass != null && !OverrideImplementUtil.getMethodSignaturesToOverride(aClass).isEmpty();
+ return OverrideImplementUtil.getContextClass(file.getProject(), editor, file, true) != null;
}
@Override
public boolean startInWriteAction() {
return false;
}
+
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ PsiClass aClass = OverrideImplementUtil.getContextClass(file.getProject(), editor, file, true);
+ return aClass != null && !OverrideImplementUtil.getMethodSignaturesToOverride(aClass).isEmpty();
+ }
}
*/
package com.intellij.refactoring;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
/**
* @author dsl
*/
-public abstract class IntroduceHandlerBase implements RefactoringActionHandler {
+public abstract class IntroduceHandlerBase implements RefactoringActionHandler, ContextAwareActionHandler {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.IntroduceHandlerBase");
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiElement[] elements = ExtractMethodHandler.getElements(file.getProject(), editor, file);
+ return elements != null && elements.length > 0;
+ }
+
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
LOG.assertTrue(elements.length >= 1 && elements[0] instanceof PsiExpression, "incorrect invoke() parameters");
final PsiElement tempExpr = elements[0];
return true;
}
- public List<PsiVariable> getInputVariables(final PsiElement codeFragment, PsiElement[] elements) {
+ public List<PsiVariable> getInputVariables(final PsiElement codeFragment, PsiElement[] elements, PsiVariable[] outputVariables) {
final List<PsiVariable> inputVariables = ControlFlowUtil.getInputVariables(myControlFlow, myFlowStart, myFlowEnd);
List<PsiVariable> myInputVariables;
- if (myGenerateConditionalExit) {
+ if (skipVariablesFromExitStatements(outputVariables)) {
List<PsiVariable> inputVariableList = new ArrayList<PsiVariable>(inputVariables);
removeParametersUsedInExitsOnly(codeFragment, inputVariableList);
myInputVariables = inputVariableList;
return getUsedVariables(myFlowEnd);
}
- public List<PsiVariable> getUsedVariablesInBody() {
- return getUsedVariables(myFlowStart, myFlowEnd);
+ public List<PsiVariable> getUsedVariablesInBody(PsiElement codeFragment, PsiVariable[] outputVariables) {
+ final List<PsiVariable> variables = getUsedVariables(myFlowStart, myFlowEnd);
+ if (skipVariablesFromExitStatements(outputVariables)) {
+ removeParametersUsedInExitsOnly(codeFragment, variables);
+ }
+ return variables;
+ }
+
+ private boolean skipVariablesFromExitStatements(PsiVariable[] outputVariables) {
+ return myGenerateConditionalExit && outputVariables.length == 0;
}
public Collection<ControlFlowUtil.VariableInfo> getInitializedTwice() {
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.highlighting.HighlightManager;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import java.util.List;
-public class ExtractMethodHandler implements RefactoringActionHandler {
+public class ExtractMethodHandler implements RefactoringActionHandler, ContextAwareActionHandler {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.extractMethod.ExtractMethodHandler");
public static final String REFACTORING_NAME = RefactoringBundle.message("extract.method.title");
}
}
+ PsiDocumentManager.getInstance(project).commitAllDocuments();
+
+ callback.pass(getElements(project, editor, file));
+ }
+
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiElement[] elements = getElements(file.getProject(), editor, file);
+ return elements != null && elements.length > 0;
+ }
+
+ public static PsiElement[] getElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
- PsiDocumentManager.getInstance(project).commitAllDocuments();
PsiElement[] elements;
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
}
}
}
- callback.pass(elements);
+ return elements;
}
private static void invokeOnElements(final Project project, final Editor editor, PsiFile file, PsiElement[] elements) {
}
private boolean chooseTargetClass(PsiElement codeFragment, final Pass<ExtractMethodProcessor> extractPass) throws PrepareFailedException {
- final List<PsiVariable> inputVariables = myControlFlowWrapper.getInputVariables(codeFragment, myElements);
+ final List<PsiVariable> inputVariables = myControlFlowWrapper.getInputVariables(codeFragment, myElements, myOutputVariables);
myNeedChangeContext = false;
myTargetClass = myCodeFragmentMember instanceof PsiMember
}
private void declareNecessaryVariablesInsideBody(PsiCodeBlock body) throws IncorrectOperationException {
- List<PsiVariable> usedVariables = myControlFlowWrapper.getUsedVariablesInBody();
+ List<PsiVariable> usedVariables = myControlFlowWrapper.getUsedVariablesInBody(ControlFlowUtil.findCodeFragment(myElements[0]), myOutputVariables);
for (PsiVariable variable : usedVariables) {
boolean toDeclare = !isDeclaredInside(variable) && myInputVariables.toDeclareInsideBody(variable);
if (toDeclare) {
*/
package com.intellij.refactoring.extractMethodObject;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
-public class ExtractMethodObjectHandler implements RefactoringActionHandler {
+public class ExtractMethodObjectHandler implements RefactoringActionHandler, ContextAwareActionHandler {
private static final Logger LOG = Logger.getInstance("#" + ExtractMethodObjectHandler.class.getName());
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, final DataContext dataContext) {
});
}
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiElement[] elements = ExtractMethodHandler.getElements(file.getProject(), editor, file);
+ return elements != null && elements.length > 0;
+ }
+
private static void invokeOnElements(@NotNull final Project project,
@NotNull final Editor editor,
@NotNull PsiFile file,
package com.intellij.refactoring.introduceparameterobject;
import com.intellij.ide.util.SuperMethodWarningUtil;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.LangDataKeys;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import org.jetbrains.annotations.NotNull;
-public class IntroduceParameterObjectHandler implements RefactoringActionHandler {
+public class IntroduceParameterObjectHandler implements RefactoringActionHandler, ContextAwareActionHandler {
private static final String REFACTORING_NAME = RefactorJBundle.message("introduce.parameter.object");
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiMethod selectedMethod = getSelectedMethod(editor, file, dataContext);
+ if (selectedMethod != null) {
+ final PsiMethod[] deepestSuperMethods = selectedMethod.findDeepestSuperMethods();
+ return deepestSuperMethods.length > 0 || getErrorMessage(selectedMethod) == null;
+ }
+ return false;
+ }
+
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
final ScrollingModel scrollingModel = editor.getScrollingModel();
scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
+ PsiMethod selectedMethod = getSelectedMethod(editor, file, dataContext);
+ if (selectedMethod == null) {
+ final String message = RefactorJBundle.message("cannot.perform.the.refactoring") +
+ RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
+ CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
+ return;
+ }
+ invoke(project, selectedMethod, editor);
+ }
+
+ private static PsiMethod getSelectedMethod(Editor editor, PsiFile file, DataContext dataContext) {
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
PsiMethod selectedMethod = null;
if (element instanceof PsiMethod) {
}
}
}
- if (selectedMethod == null) {
- final String message = RefactorJBundle.message("cannot.perform.the.refactoring") +
- RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
- CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
- return;
- }
- invoke(project, selectedMethod, editor);
+ return selectedMethod;
}
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
private static void invoke(final Project project, final PsiMethod selectedMethod, Editor editor) {
PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(selectedMethod, RefactoringBundle.message("to.refactor"));
if (newMethod == null) return;
+ final String message = getErrorMessage(newMethod);
+ if (message != null) {
+ CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
+ return;
+ }
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, newMethod)) return;
+ new IntroduceParameterObjectDialog(newMethod).show();
+ }
+
+ private static String getErrorMessage(PsiMethod newMethod) {
final PsiParameter[] parameters = newMethod.getParameterList().getParameters();
if (parameters.length == 0) {
- final String message =
- RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("method.selected.has.no.parameters");
- CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
- return;
+ return RefactorJBundle.message("cannot.perform.the.refactoring") +
+ RefactorJBundle.message("method.selected.has.no.parameters");
}
if (newMethod instanceof PsiCompiledElement) {
- CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
- "the.selected.method.cannot.be.wrapped.because.it.is.defined.in.a.non.project.class"), REFACTORING_NAME, HelpID.IntroduceParameterObject);
- return;
+ return RefactorJBundle.message("cannot.perform.the.refactoring") +
+ RefactorJBundle.message("the.selected.method.cannot.be.wrapped.because.it.is.defined.in.a.non.project.class");
}
- new IntroduceParameterObjectDialog(newMethod).show();
+ return null;
}
}
import com.intellij.analysis.BaseAnalysisActionDialog;
import com.intellij.history.LocalHistory;
import com.intellij.history.LocalHistoryAction;
+import com.intellij.lang.ContextAwareActionHandler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
/**
* @author dsl
*/
-public class MethodDuplicatesHandler implements RefactoringActionHandler {
+public class MethodDuplicatesHandler implements RefactoringActionHandler, ContextAwareActionHandler {
public static final String REFACTORING_NAME = RefactoringBundle.message("replace.method.code.duplicates.title");
private static final Logger LOG = Logger.getInstance("#" + MethodDuplicatesHandler.class.getName());
+ @Override
+ public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
+ final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
+ return getCannotRefactorMessage(PsiTreeUtil.getParentOfType(element, PsiMember.class)) == null;
+ }
+
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
final int offset = editor.getCaretModel().getOffset();
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.execution.junit;
+package com.intellij.testIntegration;
+import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
-import com.intellij.execution.PsiLocation;
import com.intellij.execution.lineMarker.RunLineMarkerInfo;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.PsiMethod;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Dmitry Avdeev
*/
-public class JUnitRunLineMarkerProvider implements LineMarkerProvider {
+public class TestRunLineMarkerProvider implements LineMarkerProvider {
private static final Function<PsiElement, String> TOOLTIP_PROVIDER = new Function<PsiElement, String>() {
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement e) {
if (e instanceof PsiIdentifier) {
PsiElement element = e.getParent();
- if (element instanceof PsiClass && JUnitUtil.isTestClass((PsiClass)element, false, true)) {
- return new RunLineMarkerInfo(e, JUnitConfigurationType.getInstance().getIcon(), TOOLTIP_PROVIDER);
+ if (element instanceof PsiClass) {
+ TestFramework framework = TestFrameworks.detectFramework((PsiClass)element);
+ if (framework != null && framework.isTestClass(element)) {
+ return new RunLineMarkerInfo(e, framework.getIcon(), TOOLTIP_PROVIDER);
+ }
}
- if (element instanceof PsiMethod && JUnitUtil.isTestMethod(new PsiLocation<PsiMethod>((PsiMethod)element))) {
- return new RunLineMarkerInfo(e, JUnitConfigurationType.getInstance().getIcon(), TOOLTIP_PROVIDER);
+ if (element instanceof PsiMethod) {
+ TestFramework framework = TestFrameworks.detectFramework(PsiTreeUtil.getParentOfType(element, PsiClass.class));
+ if (framework != null && framework.isTestMethod(element)) {
+ return new RunLineMarkerInfo(e, framework.getIcon(), TOOLTIP_PROVIDER);
+ }
}
}
return null;
}
if (errorMessage != null) {
- Messages.showMessageDialog(myProject, errorMessage, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
+ final int result = Messages
+ .showOkCancelDialog(myProject, errorMessage + ". Update existing class?", CommonBundle.getErrorTitle(), Messages.getErrorIcon());
+ if (result == Messages.CANCEL) {
+ super.close(CANCEL_EXIT_CODE);
+ return;
+ }
}
saveDefaultLibraryName();
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
@NotNull
@Override
public PsiExpression[] create(final int count) {
- return count == 0 ? PsiExpression.EMPTY_ARRAY : new PsiExpression[count];
+ return count == 0 ? EMPTY_ARRAY : new PsiExpression[count];
}
};
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import org.jetbrains.annotations.Nullable;
/**
- * Represents a Java <code>super</code> expression in a super method call. Note that the qualifier of
- * a super constructor call is represented as a {@link PsiKeyword} rather than a <code>PsiSuperExpression</code>.
+ * Represents a Java {@code super} expression in a superclass member reference (but not in a super constructor call,
+ * where the {@code super} qualifier is represented as a {@link PsiKeyword} wrapped in a {@link PsiReferenceExpression}).
*/
public interface PsiSuperExpression extends PsiQualifiedExpression {
/**
- * Returns the expression representing the class name qualifying the <code>super</code>
- * expression.
- *
- * @return the qualifier, or null if the expression has no qualifier.
+ * Returns an expression representing a type name qualifying the {@code super} expression.
*/
@Override
@Nullable
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import org.jetbrains.annotations.Nullable;
/**
- * Represents a Java <code>this</code> expression.
+ * Represents a Java {@code this} expression.
*/
public interface PsiThisExpression extends PsiQualifiedExpression {
/**
- * Returns the expression representing the class name qualifying the <code>this</code>
- * expression.
- *
- * @return the qualifier, or null if the expression has no qualifier.
+ * Returns an expression representing a type name qualifying the {@code this} expression.
*/
@Override
@Nullable
return operand;
}
- private enum BreakPoint {P1, P2, P3, P4}
+ private enum BreakPoint {P1, P2, P4}
- // todo[r.sh] make 'this', 'super' and 'class' reference expressions
@Nullable
- private PsiBuilder.Marker parsePrimary(final PsiBuilder builder, @Nullable final BreakPoint breakPoint, final int breakOffset) {
+ private PsiBuilder.Marker parsePrimary(PsiBuilder builder, @Nullable BreakPoint breakPoint, int breakOffset) {
PsiBuilder.Marker startMarker = builder.mark();
PsiBuilder.Marker expr = parsePrimaryExpressionStart(builder);
dotPos.drop();
expr = parseNew(builder, expr);
}
+ else if (dotTokenType == JavaTokenType.SUPER_KEYWORD && builder.lookAhead(1) == JavaTokenType.LPARENTH) {
+ dotPos.drop();
+ PsiBuilder.Marker refExpr = expr.precede();
+ builder.mark().done(JavaElementType.REFERENCE_PARAMETER_LIST);
+ builder.advanceLexer();
+ refExpr.done(JavaElementType.REFERENCE_EXPRESSION);
+ expr = refExpr;
+ }
else if (THIS_OR_SUPER.contains(dotTokenType) && exprType(expr) == JavaElementType.REFERENCE_EXPRESSION) {
if (breakPoint == BreakPoint.P2 && builder.getCurrentOffset() == breakOffset) {
dotPos.rollbackTo();
return expr;
}
- final PsiBuilder.Marker copy = startMarker.precede();
- final int offset = builder.getCurrentOffset();
+ PsiBuilder.Marker copy = startMarker.precede();
+ int offset = builder.getCurrentOffset();
startMarker.rollbackTo();
- final PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, false, true, false, false);
+ PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, false, true, false, false);
if (ref == null || builder.getTokenType() != JavaTokenType.DOT || builder.getCurrentOffset() != dotOffset) {
copy.rollbackTo();
return parsePrimary(builder, BreakPoint.P2, offset);
expr = ref.precede();
expr.done(dotTokenType == JavaTokenType.THIS_KEYWORD ? JavaElementType.THIS_EXPRESSION : JavaElementType.SUPER_EXPRESSION);
}
- else if (dotTokenType == JavaTokenType.SUPER_KEYWORD) {
- dotPos.drop();
- final PsiBuilder.Marker refExpr = expr.precede();
- builder.mark().done(JavaElementType.REFERENCE_PARAMETER_LIST);
- builder.advanceLexer();
- refExpr.done(JavaElementType.REFERENCE_EXPRESSION);
- expr = refExpr;
- }
else {
dotPos.drop();
- final PsiBuilder.Marker refExpr = expr.precede();
+ PsiBuilder.Marker refExpr = expr.precede();
+
myParser.getReferenceParser().parseReferenceParameterList(builder, false, false);
if (!expectOrError(builder, ID_OR_SUPER, "expected.identifier")) {
}
else if (tokenType == JavaTokenType.LPARENTH) {
if (exprType(expr) != JavaElementType.REFERENCE_EXPRESSION) {
- if (exprType(expr) == JavaElementType.SUPER_EXPRESSION) {
- if (breakPoint == BreakPoint.P3) {
- startMarker.drop();
- return expr;
- }
-
- final PsiBuilder.Marker copy = startMarker.precede();
- startMarker.rollbackTo();
-
- final PsiBuilder.Marker qualifier = parsePrimaryExpressionStart(builder);
- if (qualifier != null) {
- final PsiBuilder.Marker refExpr = qualifier.precede();
- if (builder.getTokenType() == JavaTokenType.DOT) {
- builder.advanceLexer();
- if (builder.getTokenType() == JavaTokenType.SUPER_KEYWORD) {
- builder.advanceLexer();
- refExpr.done(JavaElementType.REFERENCE_EXPRESSION);
- expr = refExpr;
- startMarker = copy;
- continue;
- }
- }
- }
-
- copy.rollbackTo();
- return parsePrimary(builder, BreakPoint.P3, -1);
- }
- else {
- startMarker.drop();
- return expr;
- }
+ startMarker.drop();
+ return expr;
}
- final PsiBuilder.Marker callExpr = expr.precede();
+ PsiBuilder.Marker callExpr = expr.precede();
parseArgumentList(builder);
callExpr.done(JavaElementType.METHOD_CALL_EXPRESSION);
expr = callExpr;
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
return TargetType.UNKNOWN;
}
- // todo[r.sh] cache?
@Nullable
public static Set<TargetType> getAnnotationTargets(@NotNull PsiClass annotationType) {
if (!annotationType.isAnnotationType()) return null;
PsiUtilCore.ensureValid(expression);
PsiUtil.ensureValidType(type);
- PsiExpression toplevel = expression;
- while (toplevel.getParent() instanceof PsiArrayAccessExpression &&
- ((PsiArrayAccessExpression)toplevel.getParent()).getArrayExpression() == toplevel) {
- toplevel = (PsiExpression)toplevel.getParent();
+ PsiExpression topLevel = expression;
+ while (topLevel.getParent() instanceof PsiArrayAccessExpression &&
+ ((PsiArrayAccessExpression)topLevel.getParent()).getArrayExpression() == topLevel) {
+ topLevel = (PsiExpression)topLevel.getParent();
}
- if (toplevel instanceof PsiArrayAccessExpression && !PsiUtil.isAccessedForWriting(toplevel)) {
+ if (topLevel instanceof PsiArrayAccessExpression && !PsiUtil.isAccessedForWriting(topLevel)) {
return PsiUtil.captureToplevelWildcards(type, expression);
}
- final PsiType normalized = doNormalizeWildcardByPosition(type, expression, toplevel);
+ final PsiType normalized = doNormalizeWildcardByPosition(type, expression, topLevel);
LOG.assertTrue(normalized.isValid(), type);
- if (normalized instanceof PsiClassType && !PsiUtil.isAccessedForWriting(toplevel)) {
+ if (normalized instanceof PsiClassType && !PsiUtil.isAccessedForWriting(topLevel)) {
return PsiUtil.captureToplevelWildcards(normalized, expression);
}
return normalized;
}
- private static PsiType doNormalizeWildcardByPosition(final PsiType type, @NotNull PsiExpression expression, final PsiExpression toplevel) {
+ private static PsiType doNormalizeWildcardByPosition(PsiType type, @NotNull PsiExpression expression, PsiExpression topLevel) {
if (type instanceof PsiCapturedWildcardType) {
final PsiWildcardType wildcardType = ((PsiCapturedWildcardType)type).getWildcard();
if (expression instanceof PsiReferenceExpression && LambdaUtil.isLambdaReturnExpression(expression)) {
return type;
}
- if (PsiUtil.isAccessedForWriting(toplevel)) {
+ if (PsiUtil.isAccessedForWriting(topLevel)) {
return wildcardType.isSuper() ? wildcardType.getBound() : PsiCapturedWildcardType.create(wildcardType, expression);
}
else {
final PsiType upperBound = ((PsiCapturedWildcardType)type).getUpperBound();
- return upperBound instanceof PsiWildcardType ? doNormalizeWildcardByPosition(upperBound, expression, toplevel) : upperBound;
+ return upperBound instanceof PsiWildcardType ? doNormalizeWildcardByPosition(upperBound, expression, topLevel) : upperBound;
}
}
if (type instanceof PsiWildcardType) {
final PsiWildcardType wildcardType = (PsiWildcardType)type;
- if (PsiUtil.isAccessedForWriting(toplevel)) {
+ if (PsiUtil.isAccessedForWriting(topLevel)) {
return wildcardType.isSuper() ? wildcardType.getBound() : PsiCapturedWildcardType.create(wildcardType, expression);
}
else {
}
else if (type instanceof PsiArrayType) {
final PsiType componentType = ((PsiArrayType)type).getComponentType();
- final PsiType normalizedComponentType = doNormalizeWildcardByPosition(componentType, expression, toplevel);
+ final PsiType normalizedComponentType = doNormalizeWildcardByPosition(componentType, expression, topLevel);
if (normalizedComponentType != componentType) {
return normalizedComponentType.createArrayType();
}
@Nullable String attributeName,
@Nullable PsiAnnotationMemberValue value,
@NotNull PairFunction<Project, String, PsiAnnotation> annotationCreator) {
- final PsiAnnotationMemberValue existing = psiAnnotation.findDeclaredAttributeValue(attributeName);
+ PsiAnnotationMemberValue existing = psiAnnotation.findDeclaredAttributeValue(attributeName);
if (value == null) {
if (existing == null) {
return null;
}
existing.getParent().delete();
- } else {
+ }
+ else {
if (existing != null) {
((PsiNameValuePair)existing.getParent()).setValue(value);
- } else {
- final PsiNameValuePair[] attributes = psiAnnotation.getParameterList().getAttributes();
- if (attributes.length == 1 && attributes[0].getName() == null) {
- attributes[0].replace(createNameValuePair(attributes[0].getValue(), PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME + "=", annotationCreator));
+ }
+ else {
+ PsiNameValuePair[] attributes = psiAnnotation.getParameterList().getAttributes();
+ if (attributes.length == 1) {
+ PsiNameValuePair attribute = attributes[0];
+ if (attribute.getName() == null) {
+ PsiAnnotationMemberValue defValue = attribute.getValue();
+ assert defValue != null : attribute;
+ attribute.replace(createNameValuePair(defValue, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME + "=", annotationCreator));
+ }
}
boolean allowNoName = attributes.length == 0 && ("value".equals(attributeName) || null == attributeName);
final String namePrefix;
if (allowNoName) {
namePrefix = "";
- } else {
+ }
+ else {
namePrefix = attributeName + "=";
}
psiAnnotation.getParameterList().addBefore(createNameValuePair(value, namePrefix, annotationCreator), null);
if (typeName.indexOf('<') != -1 || typeName.indexOf('[') != -1 || typeName.indexOf('.') == -1) {
try {
return JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createTypeFromText(typeName, context);
- } catch(Exception ex) {} // invalid syntax will produce unresolved class type
+ }
+ catch(Exception ignored) { } // invalid syntax will produce unresolved class type
}
PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(typeName, context.getResolveScope());
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
return myTypeElement;
}
+ @NotNull
@Override
public PsiType getType() {
return PsiImplUtil.getType(this);
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
}
}
+ @Override
public String toString() {
- return getElementType() == JavaElementType.EXTENDS_BOUND_LIST ? "PsiElement(EXTENDS_BOUND_LIST)"
- : "PsiReferenceList"; // todo[r.sh] fix test data
+ return "PsiReferenceList";
}
}
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiModifierList:@EJB
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiTypeParameter:F
PsiIdentifier:F('F')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:@Existing File
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiReferenceList
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
<empty list>
PsiWhiteSpace(' ')
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiIdentifier:E('E')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiReferenceList
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:caret
PsiIdentifier:caret('caret')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiErrorElement:'class' or 'interface' expected
PsiJavaToken:LT('<')
PsiTypeParameter:caret
PsiIdentifier:caret('caret')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiReferenceList
PsiJavaToken:LT('<')
PsiTypeParameter:caret
PsiIdentifier:caret('caret')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace('\n')
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:java.util.List
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:List<String>
PsiJavaToken:LT('<')
PsiTypeParameter:X
PsiIdentifier:X('X')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiErrorElement:Unexpected identifier
PsiJavaToken:LT('<')
PsiTypeParameter:X
PsiIdentifier:X('X')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:caret
PsiIdentifier:caret('caret')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiIdentifier:Configuration('Configuration')
PsiJavaToken:LT('<')
PsiTypeParameter:E
PsiIdentifier:E('E')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:E
PsiIdentifier:E('E')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiTypeParameter:E1
PsiIdentifier:E1('E1')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:Integer
PsiTypeParameter:E2
PsiIdentifier:E2('E2')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:Runnable
PsiJavaToken:LT('<')
PsiTypeParameter:Error
PsiIdentifier:Error('Error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
<empty list>
PsiIdentifier:d('d')
PsiJavaToken:DOT('.')
+ PsiReferenceParameterList
+ <empty list>
PsiKeyword:super('super')
PsiExpressionList
PsiJavaToken:LPARENTH('(')
PsiJavaToken:LT('<')
PsiTypeParameter:V
PsiIdentifier:V('V')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiReferenceList
PsiJavaToken:LT('<')
PsiTypeParameter:X
PsiIdentifier:X('X')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiErrorElement:Unexpected identifier
PsiJavaToken:LT('<')
PsiTypeParameter:X
PsiIdentifier:X('X')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:error
PsiIdentifier:error('error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiJavaToken:LT('<')
PsiTypeParameter:E
PsiIdentifier:E('E')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiJavaToken:LT('<')
PsiTypeParameter:E
PsiIdentifier:E('E')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiTypeParameter:E1
PsiIdentifier:E1('E1')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:Integer
PsiTypeParameter:E2
PsiIdentifier:E2('E2')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:Runnable
PsiJavaToken:LT('<')
PsiTypeParameter:Error
PsiIdentifier:Error('Error')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:java.util.List
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
PsiWhiteSpace(' ')
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:List<String>
PsiWhiteSpace(' ')
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:@F Object
<empty list>
PsiIdentifier:d('d')
PsiJavaToken:DOT('.')
+ PsiReferenceParameterList
+ <empty list>
PsiKeyword:super('super')
PsiExpressionList
PsiJavaToken:LPARENTH('(')
PsiLiteralExpression:0
PsiJavaToken:INTEGER_LITERAL('0')
- PsiJavaToken:RPARENTH(')')
+ PsiJavaToken:RPARENTH(')')
\ No newline at end of file
--- /dev/null
+PsiJavaFile:QualifiedSuperMethodCall3.java
+ PsiMethodCallExpression:C.A.super()
+ PsiReferenceExpression:C.A.super
+ PsiReferenceExpression:C.A
+ PsiReferenceExpression:C
+ PsiReferenceParameterList
+ <empty list>
+ PsiIdentifier:C('C')
+ PsiJavaToken:DOT('.')
+ PsiReferenceParameterList
+ <empty list>
+ PsiIdentifier:A('A')
+ PsiJavaToken:DOT('.')
+ PsiReferenceParameterList
+ <empty list>
+ PsiKeyword:super('super')
+ PsiExpressionList
+ PsiJavaToken:LPARENTH('(')
+ PsiJavaToken:RPARENTH(')')
\ No newline at end of file
PsiIdentifier:any('any')
PsiWhiteSpace(' ')
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
\ No newline at end of file
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
\ No newline at end of file
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:COMMA(',')
PsiWhiteSpace(' ')
PsiTypeParameter:U
PsiIdentifier:U('U')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
\ No newline at end of file
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
\ No newline at end of file
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiWhiteSpace(' ')
PsiErrorElement:Unexpected identifier
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:X
PsiJavaToken:LT('<')
PsiTypeParameter:T
PsiIdentifier:T('T')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiErrorElement:'>' expected.
<empty list>
PsiTypeParameter:T
PsiIdentifier:T('T')
PsiWhiteSpace(' ')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
PsiKeyword:extends('extends')
PsiWhiteSpace(' ')
PsiJavaCodeReferenceElement:X
PsiWhiteSpace(' ')
PsiTypeParameter:Y
PsiIdentifier:Y('Y')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
\ No newline at end of file
PsiJavaToken:LT('<')
PsiErrorElement:Unexpected wildcard
PsiJavaToken:QUEST('?')
- PsiElement(EXTENDS_BOUND_LIST)
+ PsiReferenceList
<empty list>
PsiJavaToken:GT('>')
--- /dev/null
+class X {
+ static String guessTestDataName(String method, String testName, String[] methods) {
+ for (String psiMethod : methods) {
+ <selection>String strings = method;
+ if (strings != null && !strings.isEmpty()) {
+ return strings.substring(0) + testName;
+ }
+ </selection>
+ }
+ return null;
+ }
+}
--- /dev/null
+import org.jetbrains.annotations.Nullable;
+
+class X {
+ static String guessTestDataName(String method, String testName, String[] methods) {
+ for (String psiMethod : methods) {
+ String strings = newMethod(method, testName);
+ if (strings != null) return strings;
+
+ }
+ return null;
+ }
+
+ @Nullable
+ private static String newMethod(String method, String testName) {
+ String strings = method;
+ if (strings != null && !strings.isEmpty()) {
+ return strings.substring(0) + testName;
+ }
+ return null;
+ }
+}
}
private boolean newMethod() {
- Object result;
if (test1()) return true;
if (test2()) return true;
return false;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler;
import com.intellij.lang.java.JavaLanguage;
+import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
+import com.intellij.testFramework.MapDataContext;
import com.intellij.util.FunctionUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nullable;
PsiElement context = getFile().findElementAt(offset);
final PsiClass aClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
assertTrue(aClass != null && aClass.isAnnotationType());
- assertFalse(new JavaOverrideMethodsHandler().isValidFor(getEditor(), getFile()));
+ final JavaOverrideMethodsHandler handler = new JavaOverrideMethodsHandler();
+ assertTrue(handler.isValidFor(getEditor(), getFile()));
+ assertFalse(handler.isAvailableForQuickList(getEditor(), getFile(), new MapDataContext()));
}
private void doTest(boolean copyJavadoc) { doTest(copyJavadoc, null); }
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
import com.intellij.lang.CodeInsightActions;
import com.intellij.lang.java.JavaLanguage;
+import com.intellij.openapi.actionSystem.ActionManager;
+import com.intellij.openapi.actionSystem.Shortcut;
import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.keymap.KeymapUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, getProject());
for (LineMarkerInfo info : markers) {
if (info.endOffset >= offset && info.startOffset <= offset) {
+ Shortcut shortcut = ActionManager.getInstance().getAction("GotoSuperMethod").getShortcutSet().getShortcuts()[0];
assertEquals(
- "<html><body>Overrides method in <a href=\"#javaClass/I\">I</a><br><div style='margin-top: 5px'><font size='2'>Click or press Ctrl+U to navigate</font></div></body></html>",
+ "<html><body>Overrides method in <a href=\"#javaClass/I\">I</a><br><div style='margin-top: 5px'><font size='2'>Click or press " +
+ KeymapUtil.getShortcutText(shortcut) +
+ " to navigate</font></div></body></html>",
info.getLineMarkerTooltip());
return;
}
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.java.parser.JavaParser;
import com.intellij.lang.java.parser.JavaParsingTestCase;
-import org.jetbrains.annotations.NonNls;
public class ExpressionParserTest extends JavaParsingTestCase {
public ExpressionParserTest() {
public void testQualifiedSuperMethodCall0() { doParserTest("new D().super(0)"); }
public void testQualifiedSuperMethodCall1() { doParserTest("d.super(0)"); }
public void testQualifiedSuperMethodCall2() { doParserTest("(new O()).<T>super()"); }
+ public void testQualifiedSuperMethodCall3() { doParserTest("C.A.super()"); }
public void testSuperMethodCallTypeParameterList() { doParserTest("super()"); }
public void testPrimitiveClassObjectAccess() { doParserTest("int.class"); }
public void testPrimitiveFieldAccess() { doParserTest("int.x"); }
public void testLambdaExpression19() { doParserTest("(@A T t) -> (null)"); }
public void testAmbiguousLambdaExpression() { doParserTest("f( (x) < y , z > (w) -> v )"); }
- private void doParserTest(@NonNls final String text) {
+ private void doParserTest(String text) {
doParserTest(text, new MyTestParser());
}
+
private static class MyTestParser implements TestParser {
@Override
public void parse(final PsiBuilder builder) {
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.codeInsight.navigation.MethodImplementationsSearch;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.module.impl.ModuleManagerImpl;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
VirtualFile projectFile = vfsRoot.findChild("test.ipr");
myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
- simulateProjectOpen();
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
UIUtil.dispatchAllInvocationEvents(); // startup activities
}
- @Override
- protected void tearDown() throws Exception {
- ((ModuleManagerImpl)ModuleManager.getInstance(myProject)).projectClosed();
- super.tearDown();
- }
-
public void test() throws Exception {
-
ModuleManager moduleManager = ModuleManager.getInstance(getProject());
Module[] modules = moduleManager.getModules();
assertEquals(3, modules.length);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.psi.autodetect;
+package com.intellij.psi.codeStyle.autodetect;
import com.intellij.formatting.Block;
import com.intellij.formatting.FormattingModel;
--- /dev/null
+/*
+ * Copyright 2000-2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.codeStyle.autodetect;
+
+import com.intellij.ide.highlighter.JavaFileType;
+import com.intellij.lang.java.JavaLanguage;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
+import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
+import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
+import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
+
+public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTestCase {
+
+ private CodeStyleSettings mySettings;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings());
+ mySettings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
+ mySettings.AUTODETECT_INDENTS = true;
+ DetectableIndentOptionsProvider optionsProvider = DetectableIndentOptionsProvider.getInstance();
+ if (optionsProvider != null) {
+ optionsProvider.setEnabledInTest(true);
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
+ DetectableIndentOptionsProvider optionsProvider = DetectableIndentOptionsProvider.getInstance();
+ if (optionsProvider != null) {
+ optionsProvider.setEnabledInTest(false);
+ }
+ super.tearDown();
+ }
+
+ public void testWhenTabsDetected_SetIndentSizeToTabSize() {
+ CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE);
+ CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions();
+
+ assert indentOptions != null;
+
+ indentOptions.INDENT_SIZE = 1;
+ indentOptions.TAB_SIZE = 2;
+
+ myFixture.configureByText(JavaFileType.INSTANCE,
+ "public class T {\n" +
+ "\tvoid run() {\n" +
+ "\t\tint a = 2;<caret>\n" +
+ "\t}\n" +
+ "}\n");
+ myFixture.type('\n');
+ myFixture.checkResult("public class T {\n" +
+ "\tvoid run() {\n" +
+ "\t\tint a = 2;\n" +
+ "\t\t<caret>\n" +
+ "\t}\n" +
+ "}\n");
+ }
+
+ public void testWhenTabsDetected_SetContinuationIndentSizeToDoubleTabSize() {
+ CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE);
+ CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions();
+
+ assert indentOptions != null;
+
+ indentOptions.INDENT_SIZE = 1;
+ indentOptions.TAB_SIZE = 2;
+ indentOptions.CONTINUATION_INDENT_SIZE = 8;
+
+ myFixture.configureByText(JavaFileType.INSTANCE,
+ "public class T {\n" +
+ "\tvoid run() {\n" +
+ "\t\tint a = 2 <caret>+ 2;\n" +
+ "\t}\n" +
+ "}\n");
+ myFixture.type('\n');
+ myFixture.checkResult("public class T {\n" +
+ "\tvoid run() {\n" +
+ "\t\tint a = 2 \n" +
+ "\t\t\t\t<caret>+ 2;\n" +
+ "\t}\n" +
+ "}\n");
+ }
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.psi.autodetect;
+package com.intellij.psi.codeStyle.autodetect;
import com.intellij.JavaTestUtil;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
+import com.intellij.psi.autodetect.AbstractIndentAutoDetectionTest;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.autodetect.LineIndentInfo;
import com.intellij.psi.codeStyle.autodetect.LineIndentInfoBuilder;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.psi.autodetect;
+package com.intellij.psi.codeStyle.autodetect;
import com.intellij.JavaTestUtil;
import org.jetbrains.annotations.NotNull;
}
}
+ public void testConditionalExitCombinedWithNullabilityShouldPreserveVarsUsedInExitStatements() throws Exception {
+ doTest();
+ }
+
private void doTestDisabledParam() throws PrepareFailedException {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.ELSE_ON_NEW_LINE = true;
package com.intellij.roots;
import com.intellij.ProjectTopics;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.ModuleTestCase;
import com.intellij.util.messages.MessageBusConnection;
+import com.intellij.util.ui.UIUtil;
import java.io.File;
import java.io.IOException;
* @author dsl
*/
public class RootsChangedTest extends ModuleTestCase {
- private MessageBusConnection myConnection;
private MyModuleRootListener myModuleRootListener;
@Override
protected void setUp() throws Exception {
super.setUp();
- myConnection = myProject.getMessageBus().connect();
+ MessageBusConnection connection = myProject.getMessageBus().connect(myTestRootDisposable);
myModuleRootListener = new MyModuleRootListener();
- myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener);
+ connection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener);
}
@Override
- protected void tearDown() throws Exception {
- myConnection.disconnect();
- super.tearDown();
+ protected boolean isRunInWriteAction() {
+ return false;
}
public void testEventsAfterFileModifications() throws Exception {
myModuleRootListener.reset();
ModuleRootModificationUtil.addContentRoot(moduleA, vDir1.getPath());
+ UIUtil.dispatchAllInvocationEvents();
assertEventsCount(1);
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir1);
- vDir1.delete(null);
+ delete(vDir1);
assertEventsCount(1);
assertEmpty(ModuleRootManager.getInstance(moduleA).getContentRoots());
VirtualFile vDir2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir2);
assertNotNull(vDir2);
- vDir2.rename(null, "dir1");
+ rename(vDir2, "dir1");
assertEventsCount(1);
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
// when the existing root is renamed, it remains a root
- vDir2.rename(null, "dir2");
+ rename(vDir2, "dir2");
assertEventsCount(0);
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
VirtualFile vSubdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(subdir);
assertNotNull(vSubdir);
- vDir2.move(null, vSubdir);
+ move(vDir2, vSubdir);
assertEventsCount(0);
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
}
}
public void testEditLibraryForModuleLoadFromXml() throws IOException {
- File moduleFile = PathManagerEx.findFileUnderProjectHome("java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml", getClass());
- Module a = loadModule(moduleFile, true);
- assertEventsCount(1);
-
- final Sdk jdk = IdeaTestUtil.getMockJdk17();
- ProjectJdkTable.getInstance().addJdk(jdk);
- assertEventsCount(0);
-
- ModuleRootModificationUtil.setModuleSdk(a, jdk);
- assertEventsCount(1);
+ final File tempDirectory = createTempDirectory();
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ File moduleFile =
+ PathManagerEx.findFileUnderProjectHome("java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml", RootsChangedTest.this.getClass());
+ Module a = loadModule(moduleFile, true);
+ assertEventsCount(1);
+
+ final Sdk jdk = IdeaTestUtil.getMockJdk17();
+ ProjectJdkTable.getInstance().addJdk(jdk);
+ assertEventsCount(0);
+
+ ModuleRootModificationUtil.setModuleSdk(a, jdk);
+ assertEventsCount(1);
+
+ final SdkModificator sdkModificator = jdk.getSdkModificator();
+ sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
+ sdkModificator.commitChanges();
+ }
+ });
- final SdkModificator sdkModificator = jdk.getSdkModificator();
- sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
- sdkModificator.commitChanges();
assertEventsCount(1);
}
public void testModuleJdkEditing() throws Exception {
- final Module moduleA = createModule("a.iml");
- final Module moduleB = createModule("b.iml");
- assertEventsCount(2);
-
- final Sdk jdk = IdeaTestUtil.getMockJdk17();
- ProjectJdkTable.getInstance().addJdk(jdk);
- assertEventsCount(0);
-
- final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
- final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
- rootModelA.setSdk(jdk);
- rootModelB.setSdk(jdk);
- ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
- ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
- assertEventsCount(1);
-
- final SdkModificator sdkModificator = jdk.getSdkModificator();
- sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
- sdkModificator.commitChanges();
- assertEventsCount(1);
-
- ProjectJdkTable.getInstance().removeJdk(jdk);
- assertEventsCount(1);
+ final File tempDirectory = createTempDirectory();
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ final Module moduleA = createModule("a.iml");
+ final Module moduleB = createModule("b.iml");
+ assertEventsCount(2);
+
+ final Sdk jdk = IdeaTestUtil.getMockJdk17();
+ ProjectJdkTable.getInstance().addJdk(jdk);
+ assertEventsCount(0);
+
+ final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
+ final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
+ rootModelA.setSdk(jdk);
+ rootModelB.setSdk(jdk);
+ ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
+ ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
+ assertEventsCount(1);
+
+ final SdkModificator sdkModificator = jdk.getSdkModificator();
+ sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
+ sdkModificator.commitChanges();
+ assertEventsCount(1);
+
+ ProjectJdkTable.getInstance().removeJdk(jdk);
+ assertEventsCount(1);
+ }
+ });
}
public void testInheritedJdkEditing() throws Exception {
- final Module moduleA = createModule("a.iml");
- final Module moduleB = createModule("b.iml");
- assertEventsCount(2);
-
- final Sdk jdk = IdeaTestUtil.getMockJdk17("AAA");
- ProjectJdkTable.getInstance().addJdk(jdk);
- assertEventsCount(0);
-
- final Sdk jdkBBB = IdeaTestUtil.getMockJdk17("BBB");
- ProjectJdkTable.getInstance().addJdk(jdk);
- assertEventsCount(0);
-
- ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB);
- assertEventsCount(0);
-
- final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
- final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
- rootModelA.inheritSdk();
- rootModelB.inheritSdk();
- ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
- if (rootModels.length > 0) {
- ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
- }
- assertEventsCount(1);
-
- ProjectRootManager.getInstance(myProject).setProjectSdk(jdk);
- assertEventsCount(1);
-
- final SdkModificator sdkModificator = jdk.getSdkModificator();
- sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
- sdkModificator.commitChanges();
- assertEventsCount(1);
-
- ProjectJdkTable.getInstance().removeJdk(jdk);
- assertEventsCount(1);
+ final File tempDirectory = createTempDirectory();
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ final Module moduleA = createModule("a.iml");
+ final Module moduleB = createModule("b.iml");
+ assertEventsCount(2);
+
+ final Sdk jdk = IdeaTestUtil.getMockJdk17("AAA");
+ ProjectJdkTable.getInstance().addJdk(jdk);
+ assertEventsCount(0);
+
+ final Sdk jdkBBB = IdeaTestUtil.getMockJdk17("BBB");
+ ProjectJdkTable.getInstance().addJdk(jdk);
+ assertEventsCount(0);
+
+ ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB);
+ assertEventsCount(0);
+
+ final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
+ final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
+ rootModelA.inheritSdk();
+ rootModelB.inheritSdk();
+ ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
+ if (rootModels.length > 0) {
+ ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
+ }
+ assertEventsCount(1);
+
+ ProjectRootManager.getInstance(myProject).setProjectSdk(jdk);
+ assertEventsCount(1);
+
+ final SdkModificator sdkModificator = jdk.getSdkModificator();
+ sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
+ sdkModificator.commitChanges();
+ assertEventsCount(1);
+
+ ProjectJdkTable.getInstance().removeJdk(jdk);
+ assertEventsCount(1);
+ }
+ });
}
private void verifyLibraryTableEditing(final LibraryTable libraryTable) throws IOException {
final Module moduleB = createModule("b.iml");
assertEventsCount(2);
- final Library libraryA = libraryTable.createLibrary("A");
- final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
- libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
- libraryModifiableModel.commit();
- assertEventsCount(0);
-
- final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
- final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
- rootModelA.addLibraryEntry(libraryA);
- rootModelB.addLibraryEntry(libraryA);
- rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
- rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
- ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
- if (rootModels.length > 0) {
- ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
- }
- assertEventsCount(1);
-
- final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
- final File tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
- try {
- final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
- assertNotNull(file);
-
- libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
- libraryModifiableModel2.commit();
- assertEventsCount(1);
- }
- finally {
- FileUtil.delete(tmpDir);
- }
-
- libraryTable.removeLibrary(libraryA);
- assertEventsCount(1);
-
- final Library libraryQ = libraryTable.createLibrary("Q");
- assertEventsCount(1);
-
- libraryTable.removeLibrary(libraryQ);
- assertEventsCount(1);
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ final Library libraryA = libraryTable.createLibrary("A");
+ final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
+ libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
+ libraryModifiableModel.commit();
+ assertEventsCount(0);
+
+ final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
+ final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
+ rootModelA.addLibraryEntry(libraryA);
+ rootModelB.addLibraryEntry(libraryA);
+ rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
+ rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
+ ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
+ if (rootModels.length > 0) {
+ ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
+ }
+ assertEventsCount(1);
+
+ final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
+ final File tmpDir;
+ try {
+ tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ try {
+ final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
+ assertNotNull(file);
+
+ libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
+ libraryModifiableModel2.commit();
+ assertEventsCount(1);
+ }
+ finally {
+ FileUtil.delete(tmpDir);
+ }
+
+ libraryTable.removeLibrary(libraryA);
+ assertEventsCount(1);
+
+ final Library libraryQ = libraryTable.createLibrary("Q");
+ assertEventsCount(1);
+
+ libraryTable.removeLibrary(libraryQ);
+ assertEventsCount(1);
+ }
+ });
}
private void verifyLibraryTableEditingInUncommittedModel(final LibraryTable libraryTable) {
- final Module moduleA = createModule("a.iml");
- final Module moduleB = createModule("b.iml");
- assertEventsCount(2);
-
- final Library libraryA = libraryTable.createLibrary("A");
- final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
- libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
- libraryModifiableModel.commit();
- assertEventsCount(0);
-
- final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
- final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
- rootModelA.addLibraryEntry(libraryA);
- rootModelB.addLibraryEntry(libraryA);
- final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
- libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
- libraryModifiableModel2.commit();
- assertEventsCount(0);
-
- libraryTable.removeLibrary(libraryA);
- assertEventsCount(0);
-
- rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
- rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
- assertEventsCount(0);
-
- final Library libraryQ = libraryTable.createLibrary("Q");
- assertEventsCount(0);
-
- ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
- if (rootModels.length > 0) {
- ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
- }
- assertEventsCount(1);
-
- libraryTable.removeLibrary(libraryQ);
- assertEventsCount(1);
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ final Module moduleA = createModule("a.iml");
+ final Module moduleB = createModule("b.iml");
+ assertEventsCount(2);
+
+ final Library libraryA = libraryTable.createLibrary("A");
+ final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
+ libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
+ libraryModifiableModel.commit();
+ assertEventsCount(0);
+
+ final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
+ final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
+ rootModelA.addLibraryEntry(libraryA);
+ rootModelB.addLibraryEntry(libraryA);
+ final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
+ libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
+ libraryModifiableModel2.commit();
+ assertEventsCount(0);
+
+ libraryTable.removeLibrary(libraryA);
+ assertEventsCount(0);
+
+ rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
+ rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
+ assertEventsCount(0);
+
+ final Library libraryQ = libraryTable.createLibrary("Q");
+ assertEventsCount(0);
+
+ ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
+ if (rootModels.length > 0) {
+ ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
+ }
+ assertEventsCount(1);
+
+ libraryTable.removeLibrary(libraryQ);
+ assertEventsCount(1);
+ }
+ });
}
private void assertEventsCount(int count) {
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
* Date: 4/9/12
*/
public class UnscrambleDialogTest extends JavaCodeInsightFixtureTestCase {
+ private RunContentDescriptor myContent;
+
+ @Override
+ protected void tearDown() throws Exception {
+ Disposer.dispose(myContent);
+ super.tearDown();
+ }
public void testStacktrace() throws Exception {
- RunContentDescriptor content = showText("");
- Icon icon = content.getIcon();
- String name = content.getDisplayName();
+ showText("");
+ Icon icon = myContent.getIcon();
+ String name = myContent.getDisplayName();
assertEquals(null, icon);
assertEquals("<Stacktrace>", name);
}
public void testException() throws Exception {
- RunContentDescriptor content = showText("java.lang.NullPointerException\n" +
+ showText("java.lang.NullPointerException\n" +
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.findOneStyleSheet(XhtmlFileInfo.java:291)\n" +
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.getStylesheets(XhtmlFileInfo.java:174)\n" +
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.initStylesheets(XhtmlFileInfo.java:119)");
- assertIcon("exception.png", content.getIcon());
- assertEquals("NPE", content.getDisplayName());
+ assertIcon("exception.png", myContent.getIcon());
+ assertEquals("NPE", myContent.getDisplayName());
}
public void testThreadDump() throws Exception {
File file = new File(getTestDataPath() + "threaddump.txt");
String s = FileUtil.loadFile(file);
- RunContentDescriptor content = showText(s);
- assertIcon("threaddump.png", content.getIcon());
- assertEquals("<Threads>", content.getDisplayName());
+ showText(s);
+ assertIcon("threaddump.png", myContent.getIcon());
+ assertEquals("<Threads>", myContent.getDisplayName());
}
public void testDeadlock() throws Exception {
File file = new File(getTestDataPath() + "deadlock.txt");
String s = FileUtil.loadFile(file);
- RunContentDescriptor content = showText(s);
- assertIcon("killProcess.png", content.getIcon());
- assertEquals("<Deadlock>", content.getDisplayName());
+ showText(s);
+ assertIcon("killProcess.png", myContent.getIcon());
+ assertEquals("<Deadlock>", myContent.getDisplayName());
}
- private RunContentDescriptor showText(String unscramble) {
+ private void showText(String unscramble) {
RunContentDescriptor descriptor = UnscrambleDialog.showUnscrambledText(null, "foo", getProject(), unscramble);
assertNotNull(descriptor);
- Disposer.register(myModule, descriptor);
- return descriptor;
+ Disposer.register(getTestRootDisposable(), descriptor);
+ myContent = descriptor;
}
private static void assertIcon(String s, Icon icon) {