com.android.tools.idea.editors.theme.ThemeEditorStyleTest
com.android.tools.idea.editors.theme.ThemeEditorUtilsTest
com.android.tools.idea.editors.theme.ConfiguredThemeEditorStyleTest
+com.android.tools.idea.editors.theme.ResolutionUtilsTest
com.android.tools.idea.editors.theme.qualifiers.QualifierUtilsTest
com.android.tools.idea.gradle.IdeaAndroidProjectTest
com.android.tools.idea.gradle.project.AndroidGradleProjectImportingTest
org.jetbrains.jps.android.AndroidBuilderTest
com.android.tools.idea.gradle.service.notification.hyperlink.CustomNotificationListenerTest
com.android.repository.impl.installer.BasicInstallerTest
+org.jetbrains.android.AndroidLintTest
[GRADLE_INTEGRATION_TESTS]
org.jetbrains.plugins.gradle.importing.*
EditorOptions editorOptions = options.getEditorOptions();
ZoomOptions zoomOptions = editorOptions.getZoomOptions();
if (zoomOptions.isWheelZooming() && e.isControlDown()) {
- if (e.getWheelRotation() < 0) {
+ int rotation = e.getWheelRotation();
+ if (rotation < 0) {
zoomModel.zoomOut();
- } else {
+ }
+ else if (rotation > 0) {
zoomModel.zoomIn();
}
e.consume();
import org.jetbrains.org.objectweb.asm.Opcodes;
import java.util.Collections;
+import java.util.Deque;
+import java.util.LinkedList;
import java.util.List;
-import java.util.Stack;
/**
* User: Alexander Podkhalyuzin
final Ref<TextRange> textRange = new Ref<>(lineRange);
final PsiElementVisitor methodCollector = new JavaRecursiveElementVisitor() {
- final Stack<PsiMethod> myContextStack = new Stack<>();
- final Stack<String> myParamNameStack = new Stack<>();
+ final Deque<PsiMethod> myContextStack = new LinkedList<>();
+ final Deque<String> myParamNameStack = new LinkedList<>();
private int myNextLambdaExpressionOrdinal = 0;
private boolean myInsideLambda = false;
@Nullable
private String getCurrentParamName() {
- return myParamNameStack.isEmpty() ? null : myParamNameStack.peek();
+ return myParamNameStack.peekFirst();
}
@Override
}
public void visitExpressionList(PsiExpressionList expressionList) {
- final PsiMethod psiMethod = myContextStack.isEmpty()? null : myContextStack.peek();
+ PsiMethod psiMethod = myContextStack.peekFirst();
if (psiMethod != null) {
final String methodName = psiMethod.getName();
final PsiExpression[] expressions = expressionList.getExpressions();
private final MultiMap<Integer, String> myNames;
private int myCurrentSlotIndex;
private final PsiElement myElement;
- private final Stack<Integer> myIndexStack;
+ private final Deque<Integer> myIndexStack = new LinkedList<>();
private boolean myReached = false;
public LocalVariableNameFinder(int startSlot, MultiMap<Integer, String> names, PsiElement element) {
myNames = names;
myCurrentSlotIndex = startSlot;
myElement = element;
- myIndexStack = new Stack<>();
-
}
private boolean shouldVisit(PsiElement scope) {
import com.intellij.util.EventDispatcher;
import com.intellij.util.IconUtil;
import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.TextTransferable;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NotNull;
};
setFixedColumnWidth(ClasspathTableModel.EXPORT_COLUMN, ClasspathTableModel.EXPORT_COLUMN_NAME);
setFixedColumnWidth(ClasspathTableModel.SCOPE_COLUMN, DependencyScope.COMPILE.toString() + " "); // leave space for combobox border
+ myEntryTable.getTableHeader().getColumnModel().getColumn(ClasspathTableModel.ITEM_COLUMN).setPreferredWidth(10000); // consume all available space
myEntryTable.registerKeyboardAction(
new ActionListener() {
private void setFixedColumnWidth(final int columnIndex, String sampleText) {
final TableColumn column = myEntryTable.getTableHeader().getColumnModel().getColumn(columnIndex);
final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
- final int width = fontMetrics.stringWidth(" " + sampleText + " ") + 4;
+ final int width = fontMetrics.stringWidth(" " + sampleText + " ") + JBUI.scale(4);
column.setPreferredWidth(width);
- column.setMaxWidth(width);
-
+ column.setMinWidth(width);
column.setResizable(false);
}
+++ /dev/null
-/*
- * Copyright 2000-2016 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.codeInsight.daemon.impl.analysis;
-
-import com.intellij.openapi.application.ReadAction;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.*;
-import com.intellij.psi.search.FilenameIndex;
-import com.intellij.psi.util.CachedValueProvider.Result;
-import com.intellij.psi.util.CachedValuesManager;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.MultiMap;
-import com.intellij.util.graph.DFSTBuilder;
-import com.intellij.util.graph.Graph;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import static com.intellij.psi.PsiJavaModule.MODULE_INFO_FILE;
-import static com.intellij.psi.SyntaxTraverser.psiTraverser;
-import static com.intellij.psi.util.PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT;
-
-public class JavaModuleGraphBuilder {
- private JavaModuleGraphBuilder() { }
-
- @Nullable
- public static Graph<PsiJavaModule> getOrBuild(@NotNull Project project) {
- return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
- Graph<PsiJavaModule> graph = ReadAction.compute(() -> build(project));
- return Result.create(graph, OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
- });
- }
-
- @Nullable
- public static Collection<PsiJavaModule> findCycle(@NotNull Graph<PsiJavaModule> graph, @NotNull PsiJavaModule module) {
- return ((JavaModuleGraph)graph).myCycles.stream().filter(set -> set.contains(module)).findFirst().orElse(null);
- }
-
- // Discovers relationships between Java modules in the project.
- // Library/JDK modules are excluded - in assumption there can't be any lib -> src dependencies.
- private static Graph<PsiJavaModule> build(Project project) {
- Set<PsiJavaModule> projectModules = ContainerUtil.newHashSet();
- for (Module module : ModuleManager.getInstance(project).getModules()) {
- Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope(false));
- if (files.size() > 1) return null; // aborts the process when there are incorrect modules in the project
- VirtualFile vFile = ContainerUtil.getFirstItem(files);
- if (vFile != null) {
- PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
- if (psiFile instanceof PsiJavaFile) {
- PsiJavaModule moduleDeclaration = ((PsiJavaFile)psiFile).getModuleDeclaration();
- if (moduleDeclaration != null) {
- projectModules.add(moduleDeclaration);
- }
- }
- }
- }
-
- MultiMap<PsiJavaModule, PsiJavaModule> relations = MultiMap.create();
- for (PsiJavaModule moduleDeclaration : projectModules) {
- for (PsiRequiresStatement statement : psiTraverser().children(moduleDeclaration).filter(PsiRequiresStatement.class)) {
- PsiJavaModule dependency = resolveDependency(statement);
- if (dependency != null && projectModules.contains(dependency)) {
- relations.putValue(moduleDeclaration, dependency);
- }
- }
- }
- return new JavaModuleGraph(relations);
- }
-
- private static PsiJavaModule resolveDependency(PsiRequiresStatement statement) {
- PsiJavaModuleReferenceElement refElement = statement.getReferenceElement();
- if (refElement != null) {
- PsiPolyVariantReference ref = refElement.getReference();
- if (ref != null) {
- ResolveResult[] results = ref.multiResolve(true);
- if (results.length == 1) {
- PsiElement target = results[0].getElement();
- if (target instanceof PsiJavaModule) {
- return (PsiJavaModule)target;
- }
- }
- }
- }
-
- return null;
- }
-
- private static class JavaModuleGraph implements Graph<PsiJavaModule> {
- private final MultiMap<PsiJavaModule, PsiJavaModule> myMap;
- private final List<Set<PsiJavaModule>> myCycles;
-
- public JavaModuleGraph(MultiMap<PsiJavaModule, PsiJavaModule> map) {
- myMap = map;
-
- DFSTBuilder<PsiJavaModule> builder = new DFSTBuilder<>(this);
- myCycles = builder.getComponents().stream()
- .map(ContainerUtil::newLinkedHashSet)
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection<PsiJavaModule> getNodes() {
- return myMap.keySet();
- }
-
- @Override
- public Iterator<PsiJavaModule> getIn(PsiJavaModule n) {
- return ContainerUtil.emptyIterator();
- }
-
- @Override
- public Iterator<PsiJavaModule> getOut(PsiJavaModule n) {
- return myMap.get(n).iterator();
- }
- }
-}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2000-2016 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.codeInsight.daemon.impl.analysis;
+
+import com.intellij.openapi.application.ReadAction;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.psi.search.FilenameIndex;
+import com.intellij.psi.util.CachedValueProvider.Result;
+import com.intellij.psi.util.CachedValuesManager;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.containers.MultiMap;
+import com.intellij.util.graph.DFSTBuilder;
+import com.intellij.util.graph.Graph;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.intellij.psi.PsiJavaModule.MODULE_INFO_FILE;
+import static com.intellij.psi.SyntaxTraverser.psiTraverser;
+import static com.intellij.psi.util.PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT;
+
+public class JavaModuleGraphUtil {
+ private JavaModuleGraphUtil() { }
+
+ @Nullable
+ public static Collection<PsiJavaModule> findCycle(@NotNull PsiJavaModule module) {
+ Project project = module.getProject();
+ List<Set<PsiJavaModule>> cycles = CachedValuesManager.getManager(project).getCachedValue(project, () ->
+ Result.create(ReadAction.compute(() -> findCycles(project)), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
+ return ContainerUtil.find(cycles, set -> set.contains(module));
+ }
+
+ // Looks for cycles between Java modules in the project sources.
+ // Library/JDK modules are excluded - in assumption there can't be any lib -> src dependencies.
+ // Module references are resolved "globally" (i.e., without taking project dependencies into account).
+ private static List<Set<PsiJavaModule>> findCycles(Project project) {
+ Set<PsiJavaModule> projectModules = ContainerUtil.newHashSet();
+ for (Module module : ModuleManager.getInstance(project).getModules()) {
+ Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope(false));
+ if (files.size() > 1) return Collections.emptyList(); // aborts the process when there are incorrect modules in the project
+ Optional.ofNullable(ContainerUtil.getFirstItem(files))
+ .map(PsiManager.getInstance(project)::findFile)
+ .map(f -> f instanceof PsiJavaFile ? ((PsiJavaFile)f).getModuleDeclaration() : null)
+ .ifPresent(projectModules::add);
+ }
+
+ if (!projectModules.isEmpty()) {
+ MultiMap<PsiJavaModule, PsiJavaModule> relations = MultiMap.create();
+ for (PsiJavaModule moduleDeclaration : projectModules) {
+ for (PsiRequiresStatement statement : psiTraverser().children(moduleDeclaration).filter(PsiRequiresStatement.class)) {
+ Optional.ofNullable(statement.getReferenceElement())
+ .map(PsiJavaModuleReferenceElement::getReference)
+ .map(ref -> ref.multiResolve(true))
+ .map(a -> a.length == 1 ? a[0].getElement() : null)
+ .map(e -> e instanceof PsiJavaModule ? (PsiJavaModule)e : null)
+ .filter(projectModules::contains)
+ .ifPresent(dependency -> relations.putValue(moduleDeclaration, dependency));
+ }
+ }
+
+ if (!relations.isEmpty()) {
+ Graph<PsiJavaModule> graph = new SourceSemiGraph(relations);
+ DFSTBuilder<PsiJavaModule> builder = new DFSTBuilder<>(graph);
+ Collection<Collection<PsiJavaModule>> components = builder.getComponents();
+ if (!components.isEmpty()) {
+ return components.stream().map(ContainerUtil::newLinkedHashSet).collect(Collectors.toList());
+ }
+ }
+ }
+
+ return Collections.emptyList();
+ }
+
+ private static class SourceSemiGraph implements Graph<PsiJavaModule> {
+ private final MultiMap<PsiJavaModule, PsiJavaModule> myMap;
+
+ public SourceSemiGraph(MultiMap<PsiJavaModule, PsiJavaModule> map) {
+ myMap = map;
+ }
+
+ @Override
+ public Collection<PsiJavaModule> getNodes() {
+ return myMap.keySet();
+ }
+
+ @Override
+ public Iterator<PsiJavaModule> getIn(PsiJavaModule n) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Iterator<PsiJavaModule> getOut(PsiJavaModule n) {
+ return myMap.get(n).iterator();
+ }
+ }
+}
\ No newline at end of file
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.JBIterable;
-import com.intellij.util.graph.Graph;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(refElement).description(message).create();
}
else {
- Graph<PsiJavaModule> graph = JavaModuleGraphBuilder.getOrBuild(target.getProject());
- if (graph != null) {
- Collection<PsiJavaModule> cycle = JavaModuleGraphBuilder.findCycle(graph, (PsiJavaModule)target);
- if (cycle != null && cycle.contains(container)) {
- Stream<String> stream = cycle.stream().map(PsiJavaModule::getModuleName);
- if (ApplicationManager.getApplication().isUnitTestMode()) stream = stream.sorted();
- String message = JavaErrorMessages.message("module.cyclic.dependence", stream.collect(Collectors.joining(", ")));
- return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(refElement).description(message).create();
- }
+ Collection<PsiJavaModule> cycle = JavaModuleGraphUtil.findCycle((PsiJavaModule)target);
+ if (cycle != null && cycle.contains(container)) {
+ Stream<String> stream = cycle.stream().map(PsiJavaModule::getModuleName);
+ if (ApplicationManager.getApplication().isUnitTestMode()) stream = stream.sorted();
+ String message = JavaErrorMessages.message("module.cyclic.dependence", stream.collect(Collectors.joining(", ")));
+ return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(refElement).description(message).create();
}
}
}
}
private static class ReplaceWithLambdaFix implements LocalQuickFix, HighPriorityAction {
- @NotNull
- @Override
- public String getName() {
- return "Replace with lambda";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Replace with lambda";
}
@Override
}
private static class ReplaceWithMethodRefFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return "Replace with method reference";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Replace with method reference";
}
- @Override
+ @Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (element instanceof PsiNewExpression) {
}
private static class ReplaceWithDiamondFix implements LocalQuickFix, HighPriorityAction {
- @NotNull
- @Override
- public String getName() {
- return "Replace with <>";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Replace with <>";
}
@Override
}
private static class ReplaceWithMethodRefFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return "Replace lambda with method reference";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Replace lambda with method reference";
}
@Override
}
private static class AnnotateAsSafeVarargsQuickFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return "Annotate as @SafeVarargs";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Annotate as @SafeVarargs";
}
@Override
}
private static class MakeFinalAndAnnotateQuickFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return "Make final and annotate as @SafeVarargs";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Make final and annotate as @SafeVarargs";
}
@Override
}
private static class ReplaceWithExprFix implements LocalQuickFix, HighPriorityAction {
- @NotNull
- @Override
- public String getName() {
- return "Replace with expression lambda";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Replace with expression lambda";
}
@Override
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return CodeInsightBundle.message("remove.annotation");
}
ExternalAnnotationsManager.getInstance(project).deannotate(myListOwner, myAnnotation.getQualifiedName());
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
\ No newline at end of file
myManager = manager;
}
- @Override
- @NotNull
- public String getName() {
- return QUICK_FIX_NAME;
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return QUICK_FIX_NAME;
}
@Override
if (returnType != null && !InferenceFromSourceUtil.isReturnTypeCompatible(returnType, contract.returnValue)) {
return "Method returns " + returnType.getPresentableText() + " but the contract specifies " + contract.returnValue;
}
+ if (method.isConstructor() && contract.returnValue != MethodContract.ValueConstraint.THROW_EXCEPTION) {
+ return "Invalid contract return value for a constructor: " + contract.returnValue;
+ }
}
return null;
}
PsiMethod constructor = pushConstructorArguments(expression);
addConditionalRuntimeThrow();
- addInstruction(new MethodCallInstruction(expression, null, Collections.emptyList()));
+ addInstruction(new MethodCallInstruction(expression, null, constructor == null ? Collections.emptyList() : getMethodContracts(constructor)));
if (!myCatchStack.isEmpty()) {
addMethodThrows(constructor, expression);
finishElement(expression);
}
+ @Nullable
private PsiMethod pushConstructorArguments(PsiConstructorCall call) {
PsiExpressionList args = call.getArgumentList();
PsiMethod ctr = call.resolveConstructor();
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.refactoring.extractMethod.ExtractMethodUtil;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.ArrayUtilRt;
-import com.intellij.util.IncorrectOperationException;
-import com.intellij.util.SmartList;
+import com.intellij.util.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
+import one.util.streamex.StreamEx;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
}
}
+ reportAlwaysFailingCalls(holder, visitor, reportedAnchors);
+
reportConstantPushes(runner, holder, visitor, reportedAnchors);
reportNullableArguments(visitor, holder, reportedAnchors);
}
}
+ private static void reportAlwaysFailingCalls(ProblemsHolder holder,
+ DataFlowInstructionVisitor visitor,
+ HashSet<PsiElement> reportedAnchors) {
+ for (PsiCall call : visitor.getAlwaysFailingCalls()) {
+ PsiMethod method = call.resolveMethod();
+ if (method != null && reportedAnchors.add(call)) {
+ holder.registerProblem(getElementToHighlight(call), "The call to #ref always fails, according to its method contracts");
+ }
+ }
+ }
+
+ @NotNull private static PsiElement getElementToHighlight(@NotNull PsiCall call) {
+ PsiJavaCodeReferenceElement ref;
+ if (call instanceof PsiNewExpression) {
+ ref = ((PsiNewExpression)call).getClassReference();
+ }
+ else if (call instanceof PsiMethodCallExpression) {
+ ref = ((PsiMethodCallExpression)call).getMethodExpression();
+ }
+ else {
+ return call;
+ }
+ if (ref != null) {
+ PsiElement name = ref.getReferenceNameElement();
+ return name != null ? name : ref;
+ }
+ return call;
+ }
+
private void reportConstantPushes(StandardDataFlowRunner runner,
ProblemsHolder holder,
DataFlowInstructionVisitor visitor,
List<LocalQuickFix> fixes = createNPEFixes(methodExpression.getQualifierExpression(), callExpression, onTheFly);
ContainerUtil.addIfNotNull(fixes, ReplaceWithObjectsEqualsFix.createFix(callExpression, methodExpression));
- PsiElement toHighlight = methodExpression.getReferenceNameElement();
- if (toHighlight == null) toHighlight = methodExpression;
+ PsiElement toHighlight = getElementToHighlight(callExpression);
holder.registerProblem(toHighlight,
InspectionsBundle.message("dataflow.message.npe.method.invocation"),
fixes.toArray(LocalQuickFix.EMPTY_ARRAY));
private static class RedundantInstanceofFix implements LocalQuickFix {
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.data.flow.redundant.instanceof.quickfix");
}
}
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
private final MultiMap<NullabilityProblem, PsiElement> myProblems = new MultiMap<>();
private final Map<Pair<NullabilityProblem, PsiElement>, StateInfo> myStateInfos = ContainerUtil.newHashMap();
private final Set<Instruction> myCCEInstructions = ContainerUtil.newHashSet();
+ private final Map<MethodCallInstruction, Boolean> myFailingCalls = new HashMap<>();
@Override
protected void onInstructionProducesCCE(TypeCastInstruction instruction) {
});
}
+ Collection<PsiCall> getAlwaysFailingCalls() {
+ return StreamEx.of(myFailingCalls.keySet()).filter(this::isAlwaysFailing).map(MethodCallInstruction::getCallExpression).toList();
+ }
+
+ @Override
+ public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction,
+ DataFlowRunner runner,
+ DfaMemoryState memState) {
+ DfaInstructionState[] states = super.visitMethodCall(instruction, runner, memState);
+ if (hasNonTrivialFailingContracts(instruction)) {
+ boolean allFail = Arrays.stream(states).allMatch(s -> s.getMemoryState().peek() == runner.getFactory().getConstFactory().getContractFail());
+ myFailingCalls.put(instruction, allFail && isAlwaysFailing(instruction));
+ }
+ return states;
+ }
+
+ private static boolean hasNonTrivialFailingContracts(MethodCallInstruction instruction) {
+ List<MethodContract> contracts = instruction.getContracts();
+ return !contracts.isEmpty() && contracts.stream().allMatch(DataFlowInstructionVisitor::isNonTrivialFailingContract);
+ }
+
+ private static boolean isNonTrivialFailingContract(MethodContract contract) {
+ return contract.returnValue == MethodContract.ValueConstraint.THROW_EXCEPTION &&
+ Arrays.stream(contract.arguments).anyMatch(v -> v != MethodContract.ValueConstraint.ANY_VALUE);
+ }
+
+ private boolean isAlwaysFailing(MethodCallInstruction instruction) {
+ return !Boolean.FALSE.equals(myFailingCalls.get(instruction));
+ }
+
@Override
protected boolean checkNotNullable(DfaMemoryState state, DfaValue value, NullabilityProblem problem, PsiElement anchor) {
boolean ok = super.checkNotNullable(state, value, problem, anchor);
private static class AcceptSuggested implements LocalQuickFix {
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.can.be.final.accept.quickfix");
}
LOG.error(e);
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
@Override
private static class MyQuickFixAction implements LocalQuickFix {
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.redundant.type.remove.quickfix");
}
LOG.error(e);
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
//separate quickfix is needed to invalidate initial method reference
private static class MyMethodReferenceFixAction implements LocalQuickFix {
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.redundant.type.remove.quickfix");
}
expression.replace(createMethodReference(expression, typeElement));
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
}
myNullableName = nullable;
}
- @NotNull
- @Override
- public String getName() {
- return "Make \"" + (myNotNullName != null ? myNotNullName : myNullableName) + "\" default annotation";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Make \"" + (myNotNullName != null ? myNotNullName : myNullableName) + "\" default annotation";
}
@Override
private static class AcceptSuggested implements LocalQuickFix {
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.redundant.cast.remove.quickfix");
}
RedundantCastUtil.removeCast(cast);
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
@Override
myDependency = dependency;
}
- @Override
- @NotNull
- public String getName() {
- return "Remove dependency";
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return "Remove dependency";
}
@Override
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.redundant.throws.remove.quickfix");
}
}
}
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
-
private void removeExcessiveThrows(@Nullable RefMethod refMethod, @Nullable final PsiModifierListOwner element, final CommonProblemDescriptor[] problems) {
try {
@Nullable final PsiMethod psiMethod;
myFiles = files;
}
- @Override
- @NotNull
- public String getName() {
- return myFiles == null ? InspectionsBundle.message("detach.library.quickfix.name") : InspectionsBundle.message("detach.library.roots.quickfix.name");
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return myFiles == null ? InspectionsBundle.message("detach.library.quickfix.name") : InspectionsBundle.message("detach.library.roots.quickfix.name");
}
@Override
import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer;
import com.intellij.codeInsight.template.*;
import com.intellij.codeInsight.template.impl.ConstantNode;
+import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
import com.intellij.codeInsight.template.impl.TemplateState;
import com.intellij.featureStatistics.FeatureUsageTracker;
+import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.event.DocumentAdapter;
+import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* @author peter
*/
TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState == null) return;
+ setupNonFilledArgumentRemoving(editor, templateState);
+
editor.putUserData(ARGUMENT_TEMPLATE_ACTIVE, this);
Disposer.register(templateState, () -> {
if (editor.getUserData(ARGUMENT_TEMPLATE_ACTIVE) == this) {
});
}
+ private static void setupNonFilledArgumentRemoving(final Editor editor, final TemplateState templateState) {
+ AtomicInteger maxEditedVariable = new AtomicInteger(-1);
+ editor.getDocument().addDocumentListener(new DocumentAdapter() {
+ @Override
+ public void documentChanged(DocumentEvent e) {
+ maxEditedVariable.set(Math.max(maxEditedVariable.get(), templateState.getCurrentVariableNumber()));
+ }
+ }, templateState);
+
+ templateState.addTemplateStateListener(new TemplateEditingAdapter() {
+ @Override
+ public void currentVariableChanged(TemplateState templateState, Template template, int oldIndex, int newIndex) {
+ maxEditedVariable.set(Math.max(maxEditedVariable.get(), oldIndex));
+ }
+
+ @Override
+ public void beforeTemplateFinished(TemplateState state, Template template, boolean brokenOff) {
+ if (brokenOff) {
+ removeUntouchedArguments((TemplateImpl)template);
+ }
+ }
+
+ private void removeUntouchedArguments(TemplateImpl template) {
+ int firstUnchangedVar = maxEditedVariable.get() + 1;
+ if (firstUnchangedVar >= template.getVariableCount()) return;
+
+ TextRange startRange = templateState.getVariableRange(template.getVariableNameAt(firstUnchangedVar));
+ TextRange endRange = templateState.getVariableRange(template.getVariableNameAt(template.getVariableCount() - 1));
+ if (startRange == null || endRange == null) return;
+
+ WriteCommandAction.runWriteCommandAction(editor.getProject(), () ->
+ editor.getDocument().deleteString(startRange.getStartOffset(), endRange.getEndOffset()));
+ }
+ });
+ }
+
private boolean shouldInsertTypeParameters() {
return myMayNeedExplicitTypeParameters && !getInferenceSubstitutor().equals(PsiSubstitutor.EMPTY) && myMethod.getParameterList().getParametersCount() == 0;
}
*/
package com.intellij.codeInsight.daemon.impl;
-import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
Couple.of("key", "value"),
Couple.of("min", "max")
);
+
+ private static final List<String> COMMON_METHODS = ContainerUtil.newArrayList(
+ "get", "set", "contains", "append",
+ "print", "println",
+ "charAt", "startsWith", "indexOf"
+ );
@NotNull
private final List<InlayInfo> myDescriptors;
public ParameterNameHintsManager(@NotNull PsiCallExpression callExpression) {
PsiExpression[] callArguments = getArguments(callExpression);
JavaResolveResult resolveResult = callExpression.resolveMethodGenerics();
-
- EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
+
List<InlayInfo> descriptors = Collections.emptyList();
- if (callArguments.length >= settings.getMinArgsToShow() &&
- hasLiteralExpression(callArguments) &&
- resolveResult.getElement() instanceof PsiMethod) {
+ if (resolveResult.getElement() instanceof PsiMethod
+ && isMethodToShowParams(resolveResult)
+ && hasUnclearExpressions(callArguments))
+ {
PsiMethod method = (PsiMethod)resolveResult.getElement();
PsiParameter[] parameters = method.getParameterList().getParameters();
descriptors = buildDescriptorsForLiteralArguments(callArguments, parameters, resolveResult);
myDescriptors = descriptors;
}
+ private static boolean isMethodToShowParams(JavaResolveResult resolveResult) {
+ PsiElement element = resolveResult.getElement();
+ if (element instanceof PsiMethod) {
+ PsiMethod method = (PsiMethod)element;
+ return !isSetter(method) && !isCommonMethod(method);
+ }
+ return false;
+ }
+
+ private static boolean isCommonMethod(PsiMethod method) {
+ String methodName = method.getName();
+ return COMMON_METHODS.stream().anyMatch((name) -> methodName.equals(name));
+ }
+
+ private static boolean isSetter(PsiMethod method) {
+ String methodName = method.getName();
+ if (method.getParameterList().getParametersCount() == 1
+ && methodName.startsWith("set")
+ && methodName.length() > 3 && Character.isUpperCase(methodName.charAt(3))) {
+ return true;
+ }
+ return false;
+ }
+
static boolean isUnclearExpression(@Nullable PsiElement callArgument) {
if (callArgument instanceof PsiLiteralExpression)
return true;
index++;
}
- if (ContainerUtil.find(descriptors, hint -> hasProperLength(hint.getText())) != null) {
- return descriptors;
- }
-
- return ContainerUtil.emptyList();
+ return descriptors;
}
@NotNull
private static InlayInfo createInlayInfo(@NotNull PsiExpression callArgument, @NotNull PsiParameter methodParam) {
- String paramName = methodParam.getName() + ((methodParam.getType() instanceof PsiEllipsisType) ? "..." : "");
+ String paramName = ((methodParam.getType() instanceof PsiEllipsisType) ? "..." : "") + methodParam.getName();
return new InlayInfo(paramName, callArgument.getTextRange().getStartOffset());
}
PsiType argType = argument.getType();
PsiType paramType = parameter.getType();
- if (isVarargParam(paramType, argType) && hasLiteralInVarargs(paramIndex, callArguments)) {
+ if (isVarargParam(paramType, argType) && hasUnclearExpression(paramIndex, callArguments)) {
return true;
}
return false;
}
-
- private static boolean hasProperLength(@Nullable String paramName) {
- final int minLength = EditorSettingsExternalizable.getInstance().getMinParamNameLengthToShow();
- return paramName != null && paramName.length() >= minLength;
- }
-
- private static boolean hasLiteralInVarargs(int index, PsiExpression[] callArguments) {
+
+ private static boolean hasUnclearExpression(int index, PsiExpression[] callArguments) {
for (int i = index; i < callArguments.length; i++) {
PsiExpression arg = callArguments[i];
if (isUnclearExpression(arg)) return true;
return param instanceof PsiEllipsisType && TypeConversionUtil.isAssignable(deepType, argument);
}
- private static boolean hasLiteralExpression(@NotNull PsiExpression[] arguments) {
+ private static boolean hasUnclearExpressions(@NotNull PsiExpression[] arguments) {
for (PsiExpression argument : arguments) {
if (isUnclearExpression(argument)) return true;
}
if (defaultValue == null) return;
if (areEqual(value, defaultValue)) {
holder.registerProblem(value, "Redundant default parameter value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new LocalQuickFix() {
- @Nls
- @NotNull
- @Override
- public String getName() {
- return "Remove redundant parameter";
- }
-
@Nls
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Remove redundant parameter";
}
@Override
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.unused.assignment.remove.quickfix");
}
LOG.error(e);
}
}
-
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
}
return myHint;
}
- @Override
- @NotNull
- public String getName() {
- return InspectionsBundle.message("inspection.unused.parameter.delete.quickfix");
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionsBundle.message("inspection.unused.parameter.delete.quickfix");
}
@Override
myReplaceTemplateFix = replaceTemplateFix;
}
- @Override
- @NotNull
- public String getName() {
- return InspectionsBundle.message("default.file.template.edit.template");
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionsBundle.message("default.file.template.edit.template");
}
@Override
* @author cdr
*/
public abstract class ReplaceWithFileTemplateFix implements LocalQuickFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionsBundle.message("default.file.template.replace.with.actual.file.template");
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionsBundle.message("default.file.template.replace.with.actual.file.template");
}
}
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return QUICK_FIX_NAME;
}
applyFix(project, new ProblemDescriptor[]{descriptor}, new ArrayList<>(), null);
}
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
-
private void deleteHierarchy(RefMethod refMethod, List<PsiElement> result) {
Collection<RefMethod> derivedMethods = refMethod.getDerivedMethods();
RefMethod[] refMethods = derivedMethods.toArray(new RefMethod[derivedMethods.size()]);
@NotNull
@Override
- public String getName() {
+ public String getFamilyName() {
return myHasEquals
? InspectionsBundle.message("inspection.equals.hashcode.generate.hashcode.quickfix")
: InspectionsBundle.message("inspection.equals.hashcode.generate.equals.quickfix");
}
- @NotNull
- @Override
- public String getFamilyName() {
- return getName();
- }
-
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
myUnboundParams = unboundParams;
}
- @Override
- @NotNull
- public String getName() {
- return "Change to ...";
- }
-
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return "Change to ...";
}
@Override
String text = "No IDEA annotations attached to the JDK " + finalJdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")")
+", some issues will not be found";
holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {
- @NotNull
- @Override
- public String getName() {
- return "Attach annotations";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Attach annotations";
}
@Override
@Override
@NotNull
public String getFamilyName() {
- return getName();
- }
-
- @Override
- @NotNull
- public String getName() {
return InspectionsBundle.message("inspection.redundant.array.creation.quickfix");
}
}
private static class RemoveSillyAssignmentFix implements LocalQuickFix {
- @Nls
- @NotNull
- @Override
- public String getName() {
- return InspectionsBundle.message("assignment.to.itself.quickfix.name");
- }
-
@Nls
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return InspectionsBundle.message("assignment.to.itself.quickfix.name");
}
@Override
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionsBundle.message("inspection.unused.return.value.make.void.quickfix");
}
return false;
}
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
-
private static void makeMethodHierarchyVoid(Project project, @NotNull PsiMethod psiMethod) {
replaceReturnStatements(psiMethod);
for (final PsiMethod oMethod : OverridingMethodsSearch.search(psiMethod)) {
@Override
@NotNull
- public final String getName() {
+ public final String getFamilyName() {
return InspectionsBundle.message("inspection.convert.to.local.quickfix");
}
}
}
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
-
@Nullable
private static PsiElement getAnchorElement(PsiCodeBlock anchorBlock, @NotNull PsiElement firstElement) {
PsiElement element = firstElement;
for (HierarchicalMethodSignature signature : signatures) {
boolean subsignature = true;
for (HierarchicalMethodSignature methodSignature : signatures) {
- if (!signature.equals(methodSignature)) {
- if (!MethodSignatureUtil.isSubsignature(signature, methodSignature) &&
- !skipMethod(signature, methodSignature)) {
- subsignature = false;
- break;
- }
+ if (!signature.equals(methodSignature) && !skipMethod(signature, methodSignature)) {
+ subsignature = false;
+ break;
}
}
if (subsignature) return Collections.singletonList(signature);
--- /dev/null
+import org.jetbrains.annotations.Contract;
+
+class Zoo {
+ @Contract(<warning descr="Invalid contract return value for a constructor: null">"null->null"</warning> )
+ Zoo(Object o) {}
+
+ @Contract("_->fail" )
+ <warning descr="Contract clause '_ -> fail' is violated: no exception is thrown">Zoo</warning>(int o) {}
+
+ @Contract("true->fail" )
+ Zoo(boolean o) {
+ if (o) throw new RuntimeException();
+ }
+
+}
\ No newline at end of file
--- /dev/null
+import org.jetbrains.annotations.*;
+
+class CandidateInfo<T> {
+ @Contract("null, true, _ -> fail")
+ private CandidateInfo(@Nullable Object candidate, boolean applicable, boolean fullySubstituted) {
+ assert !applicable || candidate != null;
+ }
+
+ static void test() {
+ new <warning descr="The call to CandidateInfo always fails, according to its method contracts">CandidateInfo</warning>(null, true, false);
+ new <warning descr="The call to CandidateInfo always fails, according to its method contracts">CandidateInfo</warning>(null, true, true);
+
+ new CandidateInfo(null, false, true);
+ new CandidateInfo(new Object(), true, true);
+ new CandidateInfo(new Object(), false, true);
+ }
+}
\ No newline at end of file
String a = notNull(getNullable());
@NotNull
- String b = notNull(null);
+ String b = <warning descr="The call to notNull always fails, according to its method contracts">notNull</warning>(null);
}
@Nullable
""")
onLineStartingWith("testBooleanVarargs")
- .assertInlays("test->13", "booleans...->false")
+ .assertInlays("test->13", "...booleans->false")
}
fun `test no hint if varargs null`() {
}
""")
- onLineStartingWith("testBooleanVarargs").assertNoInlays()
+ onLineStartingWith("testBooleanVarargs").assertInlays("test->13")
}
fun `test multiple vararg hint`() {
""")
onLineStartingWith("testBooleanVarargs")
- .assertInlays("test->13", "booleans...->false")
+ .assertInlays("test->13", "...booleans->false")
}
fun `test do not inline if parameter length is one or two`() {
}
""")
- onLineStartingWith("count").assertNoInlays()
+ onLineStartingWith("count").assertInlays("t->1", "fa->false")
}
fun `test do not inline known subsequent parameter names`() {
""")
onLineStartingWith("System")
- .assertInlays("""x->"AAA"""")
+ .assertNoInlays()
onLineStartingWith("main(t")
.assertInlays("isActive->true", "requestFocus->false", "xoo->2")
}
+
+ fun `test ignored methods`() {
+ setup("""
+public class Test {
+
+ public void main() {
+ println("A");
+ print("A");
+ get(1);
+ set(1, new Object());
+ setNewIndex(10);
+ "sss".contains("s");
+ append("sdfsdf");
+ "sfsdf".startWith("s");
+ "sss".charAt(3);
+
+ clearStatus(false);
+ }
+
+ void print(String s) {}
+ void println(String s) {}
+ void get(int index) {}
+ void set(int index, Object object) {}
+ void append(String s) {}
+ void clearStatus(boolean updatedRecently) {}
+
+}
+""")
+
+ val inlays = getInlays()
+ assertThat(inlays).hasSize(1)
+
+ assertThat(inlays[0].offset).isEqualTo(myFixture.editor.document.text.indexOf("false"))
+ }
+
fun `test hints for generic arguments`() {
val settings = EditorSettingsExternalizable.getInstance()
settings.minArgsToShow = 1
""")
onLineStartingWith("testBooleanVarargs")
- .assertInlays("booleans...->isCheck")
+ .assertInlays("...booleans->isCheck")
}
fun `test if any param matches inline all`() {
.assertInlays("test->this", "endIndex->1000")
}
+ private fun getInlays(): List<Inlay> {
+ val editor = myFixture.editor
+ return editor.inlayModel.getInlineElementsInRange(0, editor.document.textLength)
+ }
private fun onLineStartingWith(text: String): InlayAssert {
val range = getLineRangeStartingWith(text)
public void testVarargInferred() { doTest(); }
public void testDoubleParameter() { doTest(); }
public void testReturnPrimitiveArray() { doTest(); }
+ public void testCheckConstructorContracts() { doTest(); }
public void testPassingVarargsToDelegate() { doTest(); }
}
public void testContractPreservesUnknownMethodNullability() { doTest(); }
public void testContractSeveralClauses() { doTest(); }
public void testContractVarargs() { doTest(); }
+ public void testContractConstructor() { doTest(); }
public void testBoxingImpliesNotNull() { doTest(); }
public void testLargeIntegersAreNotEqualWhenBoxed() { doTest(); }
*/
package com.siyeh.ig;
+import com.intellij.codeHighlighting.HighlightDisplayLevel;
+import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfileEntry;
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
final InspectionProfileEntry inspection = getInspection();
if (inspection != null) {
myFixture.enableInspections(inspection);
+
+ final Project project = myFixture.getProject();
+ final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
+ final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstanceImpl(project).getCurrentProfile();
+ final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
+ if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
+ currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
+ }
}
Sdk sdk = ModuleRootManager.getInstance(ModuleManager.getInstance(getProject()).getModules()[0]).getSdk();
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.ERROR, "Cannot determine build data storage root for project " + myProjectPath));
return;
}
- if (!dataStorageRoot.exists()) {
+ final boolean storageFilesAbsent = !dataStorageRoot.exists() || !new File(dataStorageRoot, FS_STATE_FILE).exists();
+ if (storageFilesAbsent) {
// invoked the very first time for this project
myBuildRunner.setForceCleanCaches(true);
}
final ProjectDescriptor preloadedProject = myPreloadedData != null? myPreloadedData.getProjectDescriptor() : null;
final DataInputStream fsStateStream =
- preloadedProject != null || myInitialFSDelta == null /*this will force FS rescan*/? null : createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
+ storageFilesAbsent || preloadedProject != null || myInitialFSDelta == null /*this will force FS rescan*/? null : createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
if (fsStateStream != null || myPreloadedData != null) {
// optimization: check whether we can skip the build
}
private static class AddDoubleQuotesFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return JsonBundle.message("quickfix.add.double.quotes.desc");
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return JsonBundle.message("quickfix.add.double.quotes.desc");
}
@Override
*/
@Nls(capitalization = Nls.Capitalization.Sentence)
@NotNull
- String getName();
+ default String getName() {
+ return getFamilyName();
+ }
/**
* @return text to appear in "Apply Fix" popup when multiple Quick Fixes exist (in the results of batch code inspection). For example,
return;
}
- int change = Math.abs(e.getWheelRotation());
- boolean increase = e.getWheelRotation() <= 0;
+ int rotation = e.getWheelRotation();
+ if (rotation == 0) return;
+ int change = Math.abs(rotation);
+ boolean increase = rotation <= 0;
FontSize newFontSize = getQuickDocFontSize();
for (; change > 0; change--) {
if (increase) {
*/
public interface TemplateEditingListener {
void beforeTemplateFinished(TemplateState state, Template template);
+
+ default void beforeTemplateFinished(TemplateState state, Template template, boolean brokenOff) {
+ beforeTemplateFinished(state, template);
+ }
+
void templateFinished(Template template, boolean brokenOff);
void templateCancelled(Template template);
void currentVariableChanged(TemplateState templateState, Template template, int oldIndex, int newIndex);
private void cleanupTemplateState(boolean brokenOff) {
final Editor editor = myEditor;
- fireBeforeTemplateFinished();
+ fireBeforeTemplateFinished(brokenOff);
if (!isDisposed()) {
int oldVar = myCurrentVariableNumber;
setCurrentVariableNumber(-1);
}
}
- private void fireBeforeTemplateFinished() {
+ private void fireBeforeTemplateFinished(boolean brokenOff) {
for (TemplateEditingListener listener : myListeners) {
- listener.beforeTemplateFinished(this, myTemplate);
+ listener.beforeTemplateFinished(this, myTemplate, brokenOff);
}
}
}
private static class ChangeEncodingFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return "Change file encoding";
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return "Change file encoding";
}
@Override
private static class ShowWhitespaceFix implements LocalQuickFix {
- @NotNull
- @Override
- public String getName() {
- return InspectionsBundle.message("problematic.whitespace.show.whitespaces.quickfix");
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return InspectionsBundle.message("problematic.whitespace.show.whitespaces.quickfix");
}
@Override
// }
AlignmentImpl alignment = child.getAlignment();
if (alignment != null) {
- // Generally, we want to handle situation like the one below:
- // test("text", new Runnable() {
- // @Override
- // public void run() {
- // }
- // },
- // new Runnable() {
- // @Override
- // public void run() {
- // }
- // }
- // );
- // I.e. we want 'run()' method from the first anonymous class to be aligned with the 'run()' method of the second anonymous class.
-
- AbstractBlockWrapper anchorBlock = alignment.getOffsetRespBlockBefore(child);
- if (anchorBlock == null) {
- anchorBlock = this;
- if (anchorBlock instanceof CompositeBlockWrapper) {
- List<AbstractBlockWrapper> children = ((CompositeBlockWrapper)anchorBlock).getChildren();
- for (AbstractBlockWrapper c : children) {
- if (c.getStartOffset() != getStartOffset() && c.getStartOffset() < targetBlockStartOffset) {
- anchorBlock = c;
- break;
- }
- }
- }
- }
+ AbstractBlockWrapper anchorBlock = getAnchorBlock(child, targetBlockStartOffset, alignment);
return anchorBlock.getNumberOfSymbolsBeforeBlock();
}
childIndent = CoreFormatterUtil.getIndent(options, child, getStartOffset());
}
}
+ @NotNull
+ private AbstractBlockWrapper getAnchorBlock(AbstractBlockWrapper child, int targetBlockStartOffset, AlignmentImpl alignment) {
+ // Generally, we want to handle situation like the one below:
+ // test("text", new Runnable() {
+ // @Override
+ // public void run() {
+ // }
+ // },
+ // new Runnable() {
+ // @Override
+ // public void run() {
+ // }
+ // }
+ // );
+ // I.e. we want 'run()' method from the first anonymous class to be aligned with the 'run()' method of the second anonymous class.
+
+ AbstractBlockWrapper anchorBlock = alignment.getOffsetRespBlockBefore(child);
+ if (anchorBlock == null) {
+ anchorBlock = this;
+ if (anchorBlock instanceof CompositeBlockWrapper) {
+ List<AbstractBlockWrapper> children = ((CompositeBlockWrapper)anchorBlock).getChildren();
+ for (AbstractBlockWrapper c : children) {
+ if (c.getStartOffset() != getStartOffset() && c.getStartOffset() < targetBlockStartOffset) {
+ anchorBlock = c;
+ break;
+ }
+ }
+ }
+ }
+ return anchorBlock;
+ }
+
/**
* Allows to answer if current wrapped block has a child block that is located before given block and has line feed.
*
</properties>
<border type="none"/>
<children>
- <component id="db08a" class="javax.swing.JEditorPane" binding="myDescriptionTextArea">
+ <component id="db08a" class="javax.swing.JEditorPane" binding="myDescriptionTextArea" custom-create="true">
<constraints/>
<properties>
<contentType value="text/html"/>
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.PlatformColors;
+import com.intellij.util.ui.SwingHelper;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.update.UiNotifyConnector;
import org.jetbrains.annotations.NotNull;
private void createUIComponents() {
myFilter = new MyPackageFilter();
+ myDescriptionTextArea = SwingHelper.createHtmlViewer(true, null, null, null);
}
public void setOptionsText(@NotNull String optionsText) {
public static int getButton(MouseEvent event) {
if (event instanceof MouseWheelEvent) {
MouseWheelEvent wheel = (MouseWheelEvent)event;
- return 0 < wheel.getWheelRotation()
+ return 0 < wheel.getPreciseWheelRotation()
? BUTTON_WHEEL_DOWN
: BUTTON_WHEEL_UP;
}
public void processMouseWheelEvent(MouseWheelEvent e) {
if (!isShowing()) return;
+ int rotation = e.getWheelRotation();
+ if (rotation == 0) return;
if (e.getComponent() != this) {
e = (MouseWheelEvent)SwingUtilities.convertMouseEvent(e.getComponent(), e, this);
}
SwingUtilities.convertPointToScreen(p, this);
Point tPoint = getLocationOnScreen();
if (p.x >= tPoint.x && p.x <= tPoint.x + getWidth() && p.y >= tPoint.y && p.y <= tPoint.y + getHeight()) {
- myLayout.updateShift(e.getWheelRotation() * 10);
+ myLayout.updateShift(rotation * 10);
}
}
*/
default void init(ToolWindow window) {}
+ /**
+ * Check if toolwindow (and its stripe button) should be visible after startup.
+ * @see ToolWindow#isAvailable()
+ */
+ default boolean shouldBeAvailable(@NotNull Project project) { return true;}
+
/**
* Tool Window saves its state on project close and restore on when project opens
* In some cases, it is useful to postpone Tool Window activation until user explicitly activates it.
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
+ int units = e.getUnitsToScroll();
+ if (units == 0) return;
final Object source = e.getSource();
if (source instanceof JSpinner) {
final JSpinner spinner = (JSpinner)source;
final Number stepSize = numberModel.getStepSize();
final Comparable minimum = numberModel.getMinimum();
final Comparable maximum = numberModel.getMaximum();
- final Number newValue = calculateNewValue(value, stepSize, minimum, maximum, e.getUnitsToScroll());
+ final Number newValue = calculateNewValue(value, stepSize, minimum, maximum, units);
if (newValue != null) {
numberModel.setValue(newValue);
}
}
}
});
- addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- if (mySingleRowLayout.myLastSingRowLayout != null) {
- mySingleRowLayout.scroll(e.getUnitsToScroll() * mySingleRowLayout.getScrollUnitIncrement());
- revalidateAndRepaint(false);
- }
+ addMouseWheelListener(event -> {
+ int units = event.getUnitsToScroll();
+ if (units == 0) return;
+ if (mySingleRowLayout.myLastSingRowLayout != null) {
+ mySingleRowLayout.scroll(units * mySingleRowLayout.getScrollUnitIncrement());
+ revalidateAndRepaint(false);
}
});
}
void highlightHyperlinks(final Filter customFilter, final int startLine, final int endLine) {
+ if (endLine < 0) return;
+
Computable<FilterResults> bgComputation = highlightHyperlinksAsync(customFilter, startLine, endLine);
if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
bgComputation.compute().applyHighlights(myHyperlinks);
@NotNull
public static ModalityState getCurrentModalityState() {
+ ApplicationManager.getApplication().assertIsDispatchThread();
return ourModalityStack.peek();
}
}
public static boolean isChangeFontSize(@NotNull MouseWheelEvent e) {
+ if (e.getWheelRotation() == 0) return false;
return SystemInfo.isMac
? !e.isControlDown() && e.isMetaDown() && !e.isAltDown() && !e.isShiftDown()
: e.isControlDown() && !e.isMetaDown() && !e.isAltDown() && !e.isShiftDown();
@Override
public void mouseWheelMoved(@NotNull MouseWheelEvent e) {
if (myEditorPreviewHint == null) return;
- int inc = e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ? e.getUnitsToScroll() * e.getScrollAmount() :
- e.getWheelRotation() < 0 ? -e.getScrollAmount() : e.getScrollAmount();
+ int units = e.getUnitsToScroll();
+ if (units == 0) return;
// Stop accumulating when the last or the first line has been reached as 'adjusted' position to show lens.
- if (myLastVisualLine < myEditor.getVisibleLineCount() - 1 && inc > 0 || myLastVisualLine > 0 && inc < 0) {
- myWheelAccumulator += inc;
+ if (myLastVisualLine < myEditor.getVisibleLineCount() - 1 && units > 0 || myLastVisualLine > 0 && units < 0) {
+ myWheelAccumulator += units;
}
myRowAdjuster = myWheelAccumulator / myEditor.getLineHeight();
showToolTipByMouseMove(e);
JLabel label = createInitializingLabel();
ToolWindowAnchor toolWindowAnchor = ToolWindowAnchor.fromText(bean.anchor);
final ToolWindowFactory factory = bean.getToolWindowFactory();
- final ToolWindowImpl toolWindow =
- (ToolWindowImpl)registerToolWindow(bean.id, label, toolWindowAnchor, myProject, DumbService.isDumbAware(factory),
- bean.canCloseContents);
+ ToolWindow window = registerToolWindow(bean.id, label, toolWindowAnchor, false, bean.canCloseContents,
+ DumbService.isDumbAware(factory), factory.shouldBeAvailable(myProject));
+ final ToolWindowImpl toolWindow = (ToolWindowImpl)registerDisposable(bean.id, myProject, window);
toolWindow.setContentFactory(factory);
if (bean.icon != null && toolWindow.getIcon() == null) {
Icon icon = IconLoader.findIcon(bean.icon, factory.getClass());
@NotNull ToolWindowAnchor anchor,
@NotNull Disposable parentDisposable,
boolean canWorkInDumbMode, boolean canCloseContents) {
- return registerDisposable(id, parentDisposable, registerToolWindow(id, component, anchor, false, canCloseContents, canWorkInDumbMode));
+ return registerDisposable(id, parentDisposable, registerToolWindow(id, component, anchor, false, canCloseContents, canWorkInDumbMode, true));
}
@NotNull
@NotNull final JComponent component,
@NotNull final ToolWindowAnchor anchor,
boolean canWorkInDumbMode) {
- return registerToolWindow(id, component, anchor, false, false, canWorkInDumbMode);
+ return registerToolWindow(id, component, anchor, false, false, canWorkInDumbMode, true);
}
@NotNull
@Override
public ToolWindow registerToolWindow(@NotNull final String id, final boolean canCloseContent, @NotNull final ToolWindowAnchor anchor) {
- return registerToolWindow(id, null, anchor, false, canCloseContent, false);
+ return registerToolWindow(id, null, anchor, false, canCloseContent, false, true);
}
@NotNull
final boolean canCloseContent,
@NotNull final ToolWindowAnchor anchor,
final boolean secondary) {
- return registerToolWindow(id, null, anchor, secondary, canCloseContent, false);
+ return registerToolWindow(id, null, anchor, secondary, canCloseContent, false, true);
}
@NotNull Disposable parentDisposable,
boolean canWorkInDumbMode,
boolean secondary) {
- ToolWindow window = registerToolWindow(id, null, anchor, secondary, canCloseContent, canWorkInDumbMode);
+ ToolWindow window = registerToolWindow(id, null, anchor, secondary, canCloseContent, canWorkInDumbMode, true);
return registerDisposable(id, parentDisposable, window);
}
@NotNull final ToolWindowAnchor anchor,
boolean sideTool,
boolean canCloseContent,
- final boolean canWorkInDumbMode) {
+ final boolean canWorkInDumbMode,
+ boolean shouldBeAvailable) {
if (LOG.isDebugEnabled()) {
LOG.debug("enter: installToolWindow(" + id + "," + component + "," + anchor + "\")");
}
final boolean wasVisible = info.isVisible();
info.setActive(false);
info.setVisible(false);
+ info.setShowStripeButton(shouldBeAvailable);
// Create decorator
import com.intellij.openapi.extensions.ExtensionPointName;
public abstract class CredentialsLanguageContribution<T> {
+ public static final CredentialsLanguageContribution<Void> NOT_IMPLEMENTED = new CredentialsLanguageContribution<Void>() {
+ @Override
+ public CredentialsTypeEx getType() {
+ return null;
+ }
+
+ @Override
+ public Class<Void> getLanguageContributionClass() {
+ return null;
+ }
+
+ @Override
+ public Void getLanguageContribution() {
+ return null;
+ }
+ };
public static final ExtensionPointName<CredentialsLanguageContribution> EP_NAME
= ExtensionPointName.create("com.intellij.remote.credentialsLanguageContribution");
}
});
- addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- final int amount = e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ? e.getUnitsToScroll() * e.getScrollAmount() :
- e.getWheelRotation() < 0 ? -e.getScrollAmount() : e.getScrollAmount();
- int pointerValue = myPointerValue + amount;
- pointerValue = pointerValue < OFFSET ? OFFSET : pointerValue;
- int size = myVertical ? getHeight() : getWidth();
- pointerValue = pointerValue > (size - 12) ? size - 12 : pointerValue;
-
- myPointerValue = pointerValue;
- myValue = pointerValueToValue(myPointerValue);
-
- repaint();
- fireValueChanged();
- }
+ addMouseWheelListener(event -> {
+ int units = event.getUnitsToScroll();
+ if (units == 0) return;
+ int pointerValue = myPointerValue + units;
+ pointerValue = pointerValue < OFFSET ? OFFSET : pointerValue;
+ int size = myVertical ? getHeight() : getWidth();
+ pointerValue = pointerValue > (size - 12) ? size - 12 : pointerValue;
+
+ myPointerValue = pointerValue;
+ myValue = pointerValueToValue(myPointerValue);
+
+ repaint();
+ fireValueChanged();
});
addComponentListener(new ComponentAdapter() {
@Override
public void choose(@Nullable VirtualFile toSelect, @NotNull Consumer<List<VirtualFile>> callback) {
if (toSelect != null && toSelect.getParent() != null) {
- myFileDialog.setDirectory(toSelect.getParent().getCanonicalPath());
- myFileDialog.setFile(toSelect.getPath());
+
+ String directoryName;
+ String fileName = null;
+ if (toSelect.isDirectory()) {
+ directoryName = toSelect.getCanonicalPath();
+ } else {
+ directoryName = toSelect.getParent().getCanonicalPath();
+ fileName = toSelect.getPath();
+ }
+ myFileDialog.setDirectory(directoryName);
+ myFileDialog.setFile(fileName);
}
myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple());
textPane = new JEditorPane();
}
textPane.setFont(font != null ? font : UIUtil.getLabelFont());
- textPane.setContentType(UIUtil.HTML_MIME);
+ textPane.setEditorKit(UIUtil.getHTMLEditorKit());
textPane.setEditable(false);
if (background != null) {
textPane.setBackground(background);
import com.intellij.ui.TableUtil;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ui.AbstractTableCellEditor;
+import com.intellij.util.ui.MouseEventHandler;
import com.intellij.util.ui.UIUtil;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntObjectHashMap;
editor.setFocusCycleRoot(true);
editor.setFocusTraversalPolicy(new JBListTableFocusTraversalPolicy(editor));
- MouseSuppressor.install(editor);
+ editor.addMouseListener(MouseEventHandler.CONSUMER);
myCellEditor = new MyCellEditor(editor);
return myCellEditor;
+++ /dev/null
-/*
- * Copyright 2000-2011 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.util.ui.table;
-
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import java.awt.event.*;
-
-/**
-* @author Konstantin Bulenkov
-*/
-class MouseSuppressor implements MouseListener, MouseWheelListener, MouseMotionListener {
- private static void handle(InputEvent e) {
- e.consume();
- }
-
- public static void install(@NotNull JComponent component) {
- component.addMouseListener(new MouseSuppressor());
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {handle(e);}
-
- @Override
- public void mousePressed(MouseEvent e) {handle(e);}
-
- @Override
- public void mouseReleased(MouseEvent e) {handle(e);}
-
- @Override
- public void mouseEntered(MouseEvent e) {handle(e);}
-
- @Override
- public void mouseExited(MouseEvent e) {handle(e);}
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {handle(e);}
-
- @Override
- public void mouseDragged(MouseEvent e) {handle(e);}
-
- @Override
- public void mouseMoved(MouseEvent e) {handle(e);}
-}
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Conditions;
+import com.intellij.testFramework.LoggedErrorProcessor;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.SkipInHeadlessEnvironment;
import com.intellij.testFramework.UsefulTestCase;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
@SuppressWarnings({"SSBasedInspection", "SynchronizeOnThis"})
@SkipInHeadlessEnvironment
assertOrderedEquals(myOrder, "m12", "m2", "m1", "m1x");
});
}
+
+ public void testModalityStateCurrentAllowedOnlyFromEDT() throws Exception {
+ LoggedErrorProcessor.getInstance().disableStderrDumping(getTestRootDisposable());
+ Future<ModalityState> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ModalityState.current());
+ try {
+ future.get(1000, TimeUnit.MILLISECONDS);
+ fail("should fail");
+ }
+ catch (ExecutionException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Access is allowed from event dispatch thread only"));
+ }
+ }
}
testProxy.setTestFailed(localizedMessage, stackTrace, isTestError);
}
else {
+ testProxy.setTestFailed(localizedMessage, stackTrace, isTestError);
logProblem("Comparison failure actual and expected texts should be both null or not null.\n"
+ "Expected:\n"
+ comparisionFailureExpectedText + "\n"
assertFalse(proxy.isInProgress());
}
+ public void testOnTestTruncatedComparisonFailure() {
+ onTestStarted("some_test");
+ myEventsProcessor.onTestFailure(new TestFailedEvent("some_test", "", "", false, "actual", null));
+
+ final String fullName = myEventsProcessor.getFullTestName("some_test");
+ final SMTestProxy proxy = myEventsProcessor.getProxyByFullTestName(fullName);
+
+ assertNotNull(proxy);
+ assertTrue(proxy.isDefect());
+ assertFalse(proxy.isInProgress());
+ }
+
public void testOnTestFailure_Twice() {
myMockResettablePrinter.resetIfNecessary();
onTestStarted("some_test");
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.runners.ExecutionEnvironment;
+import com.intellij.execution.testframework.CompositePrintable;
import com.intellij.execution.testframework.Printable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.ui.TestsOutputConsolePrinter;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.util.Disposer;
+import com.intellij.psi.impl.DebugUtil;
+import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.NotNull;
/**
assertAllOutputs(myMockResettablePrinter, "preved", "","Empty test suite.\n");
}
+ public void testEnsureOrderedClearFlush() throws Exception {
+ StringBuffer buf = new StringBuffer();
+ String expected = "";
+ for(int i = 0; i < 100; i++) {
+ expected += "1" ;
+ expected += "2" ;
+ CompositePrintable.invokeInAlarm(() -> buf.append("1"), false);
+ CompositePrintable.invokeInAlarm(() -> buf.append("2"), false);
+ }
+ Semaphore s = new Semaphore();
+ s.down();
+ CompositePrintable.invokeInAlarm(s::up, false);
+ assertTrue(s.waitFor(1000));
+ assertEquals(expected, buf.toString());
+ }
+
@NotNull
private SMTestProxy startTestWithPrinter(final String testName) {
myEventsProcessor.onTestStarted(new TestStartedEvent(testName, null));
import java.io.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ExecutorService;
public class CompositePrintable implements Printable, Disposable {
public static final String NEW_LINE = "\n";
private int myCurrentSize = 0;
private String myOutputFile = null;
private String myFrameworkOutputFile;
+ private static final ExecutorService ourTestExecutorService = AppExecutorUtil.createBoundedApplicationPoolExecutor("tests", 1);
public void flush() {
synchronized (myNestedPrintables) {
if (sync) {
runnable.run();
} else {
- AppExecutorUtil.getAppExecutorService().execute(runnable);
+ ourTestExecutorService.execute(runnable);
}
}
public void setOutputFilePath(String outputFile) {
myOutputFile = outputFile;
}
-
+
public void setFrameworkOutputFile(String frameworkOutputFile) {
myFrameworkOutputFile = frameworkOutputFile;
}
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
if (myIndex < 0 || myIndex >= myRequests.size()) return NoDiffRequest.INSTANCE;
DiffHyperlink hyperlink = myRequests.get(myIndex);
try {
- String title = hyperlink.getDiffTitle();
+ String windowTitle = hyperlink.getDiffTitle();
- Pair<String, DiffContent> content1 = createContentWithTitle("diff.content.expected.title",
- hyperlink.getLeft(), hyperlink.getFilePath());
- Pair<String, DiffContent> content2 = createContentWithTitle("diff.content.actual.title",
- hyperlink.getRight(), hyperlink.getActualFilePath());
+ String text1 = hyperlink.getLeft();
+ String text2 = hyperlink.getRight();
+ VirtualFile file1 = findFile(hyperlink.getFilePath());
+ VirtualFile file2 = findFile(hyperlink.getActualFilePath());
- return new SimpleDiffRequest(title, content1.second, content2.second, content1.first, content2.first);
+ DiffContent content1 = createContentWithTitle(getProject(), text1, file1, file2);
+ DiffContent content2 = createContentWithTitle(getProject(), text2, file2, file1);
+
+ String title1 = getContentTitle("diff.content.expected.title", file1);
+ String title2 = getContentTitle("diff.content.actual.title", file2);
+
+ return new SimpleDiffRequest(windowTitle, content1, content2, title1, title2);
}
catch (Exception e) {
return new ErrorDiffRequest(e);
}
}
-
- private Pair<String, DiffContent> createContentWithTitle(String titleKey, String contentString, String contentFilePath) {
- String title;
- DiffContent content;
- VirtualFile vFile;
- if (contentFilePath != null && (vFile = LocalFileSystem.getInstance().findFileByPath(contentFilePath)) != null) {
- title = ExecutionBundle.message(titleKey) + " (" + vFile.getPresentableUrl() + ")";
- content = DiffContentFactory.getInstance().create(getProject(), vFile);
+
+ @Nullable
+ private static VirtualFile findFile(@Nullable String path) {
+ return path != null ? LocalFileSystem.getInstance().findFileByPath(path) : null;
+ }
+
+ @NotNull
+ private static DiffContent createContentWithTitle(@Nullable Project project,
+ @NotNull String content,
+ @Nullable VirtualFile contentFile,
+ @Nullable VirtualFile highlightFile) {
+ if (contentFile != null) {
+ return DiffContentFactory.getInstance().create(project, contentFile);
}
else {
- title = ExecutionBundle.message(titleKey);
- content = DiffContentFactory.getInstance().create(contentString);
+ return DiffContentFactory.getInstance().create(content, highlightFile);
+ }
+ }
+
+ @NotNull
+ private static String getContentTitle(@NotNull String titleKey, @Nullable VirtualFile file) {
+ String title = ExecutionBundle.message(titleKey);
+ if (file != null) {
+ title += " (" + file.getPresentableUrl() + ")";
}
- return Pair.create(title, content);
+ return title;
}
//
import javax.swing.SwingUtilities;
import javax.swing.event.MenuDragMouseEvent;
+import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.*;
/**
* @author Sergey.Malenkov
*/
-public class MouseEventAdapter<T> implements MouseListener, MouseMotionListener, MouseWheelListener {
+public class MouseEventAdapter<T> extends MouseAdapter implements MouseListener, MouseInputListener,
+ MouseMotionListener, MouseWheelListener {
private final T myAdapter;
public MouseEventAdapter(T adapter) {
public static MouseWheelEvent convert(MouseWheelEvent event, Component source, int id, long when, int modifiers, int x, int y) {
return new MouseWheelEvent(source, id, when, modifiers, x, y,
+ event.getXOnScreen(),
+ event.getYOnScreen(),
event.getClickCount(),
event.isPopupTrigger(),
event.getScrollType(),
*/
package com.intellij.util.ui;
+import javax.swing.event.MouseInputListener;
import java.awt.event.*;
/**
* @author Sergey.Malenkov
*/
-public abstract class MouseEventHandler implements MouseListener, MouseMotionListener, MouseWheelListener {
+public abstract class MouseEventHandler extends MouseAdapter implements MouseListener, MouseInputListener,
+ MouseMotionListener, MouseWheelListener {
protected abstract void handle(MouseEvent event);
@Override
public void mouseWheelMoved(MouseWheelEvent event) {
handle(event);
}
+
+ public static final MouseEventHandler CONSUMER = new MouseEventHandler() {
+ @Override
+ protected void handle(MouseEvent event) {
+ event.consume();
+ }
+ };
}
private void updateToolWindowAvailability() {
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(TOOLWINDOW_ID);
if (toolWindow != null) {
- toolWindow.setAvailable(isAvailable(), null);
+ boolean available = isAvailable();
+ toolWindow.setShowStripeButton(available);
+ toolWindow.setAvailable(available, null);
}
}
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ChangesViewContentManager.getInstance(project).setUp(toolWindow);
}
+
+ @Override
+ public boolean shouldBeAvailable(@NotNull Project project) {
+ return ChangesViewContentManager.getInstance(project).isAvailable();
+ }
}
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
XLineBreakpoint<P> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
if (breakpoint != null) {
- if (Registry.is("debugger.click.disable.breakpoints")) {
- breakpoint.setEnabled(!breakpoint.isEnabled());
- }
- else {
+ if (!temporary && !Registry.is("debugger.click.disable.breakpoints")) {
breakpointManager.removeBreakpoint(breakpoint);
}
}
import com.intellij.xdebugger.XDebuggerBundle;
import com.intellij.xdebugger.XDebuggerUtil;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+
class RemoveBreakpointGutterIconAction extends DumbAwareAction {
private final XBreakpointBase<?,?,?> myBreakpoint;
@Override
public void actionPerformed(final AnActionEvent e) {
- XDebuggerUtil.getInstance().removeBreakpoint(myBreakpoint.getProject(), myBreakpoint);
+ InputEvent event = e.getInputEvent();
+ // for mouse events check that no modifiers applied
+ if (!(event instanceof MouseEvent) || event.getModifiersEx() == 0) {
+ XDebuggerUtil.getInstance().removeBreakpoint(myBreakpoint.getProject(), myBreakpoint);
+ }
}
}
\ No newline at end of file
int maxPriority = 0;
for (XLineBreakpointType<?> type : lineTypes) {
maxPriority = Math.max(maxPriority, type.getPriority());
- final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
- if (breakpoint != null && temporary && !breakpoint.isTemporary()) {
- breakpoint.setTemporary(true);
- }
- else if (type.canPutAt(file, line, project) || breakpoint != null) {
- if (typeWinner == null || type.getPriority() > typeWinner.getPriority()) {
- typeWinner = type;
- lineWinner = line;
- }
+ XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
+ if ((type.canPutAt(file, line, project) || breakpoint != null) &&
+ (typeWinner == null || type.getPriority() > typeWinner.getPriority())) {
+ typeWinner = type;
+ lineWinner = line;
}
}
// already found max priority type - stop
key="class.initializer.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure"
enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.classlayout.ClassInitializerInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="ClassMayBeInterface" bundle="com.siyeh.InspectionGadgetsBundle" key="class.may.be.interface.display.name"
- groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure" enabledByDefault="false"
- level="WARNING" implementationClass="com.siyeh.ig.classlayout.ClassMayBeInterfaceInspection"/>
+ groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure" enabledByDefault="true"
+ level="INFORMATION" implementationClass="com.siyeh.ig.classlayout.ClassMayBeInterfaceInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="ClassNameDiffersFromFileName" bundle="com.siyeh.InspectionGadgetsBundle"
key="class.name.differs.from.file.name.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.class.structure" enabledByDefault="false" level="WARNING"
inner.class.field.hides.outer.problem.descriptor=Inner class field <code>#ref</code> hides outer class field #loc
local.variable.hides.member.variable.display.name=Local variable hides field
local.variable.hides.member.variable.problem.descriptor=Local variable <code>#ref</code> hides field in class ''{0}'' #loc
-local.variable.hides.member.variable.ignore.option=Ignore local variables in static methods
+local.variable.hides.member.variable.ignore.option=Ignore local variables in a static context
method.overloads.display.name=Method overloads method of superclass
method.overloads.problem.descriptor=Method <code>#ref()</code> overloads a compatible method of a superclass, when overriding might have been intended #loc
method.overloads.report.incompatible.option=Report even if parameter types are not compatible
array.creation.without.new.keyword.quickfix=Add ''new {0}''
array.creation.without.new.keyword.family.quickfix=Add 'new' expression
malformed.set.up.tear.down.display.name=Malformed 'setUp()' or 'tearDown()'
-malformed.set.up.tear.down.problem.descriptor='#ref()' has incorrect signature #loc
\ No newline at end of file
+malformed.set.up.tear.down.problem.descriptor='#ref()' has incorrect signature #loc
+method.missing.return.statement.display.name=Method contains logic but is missing a 'return' statement
+method.missing.return.statement.problem.descriptor=Method <code>#ref</code> contains logic but is missing a 'return' statement
\ No newline at end of file
}
private static class OverlyStrongCastFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message("overly.strong.type.cast.weaken.quickfix");
}
@Override
@NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("assignment.used.as.condition.replace.quickfix");
- }
-
- @NotNull
- @Override
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("assignment.used.as.condition.replace.quickfix");
}
@Override
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"pointless.bitwise.expression.simplify.quickfix");
}
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
public void doFix(Project project, ProblemDescriptor descriptor)
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"class.new.instance.quickfix");
}
- @NotNull
- @Override
- public String getFamilyName() {
- return getName();
- }
-
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
}
private static class EmptyInitializerFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"empty.class.initializer.delete.quickfix");
}
private static class InnerClassReferencedViaSubclassFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("inner.class.referenced.via.subclass.quickfix");
- }
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("inner.class.referenced.via.subclass.quickfix");
}
@Override
@Override
@NotNull
public String getFamilyName() {
- return getName();
- }
- @Override
- @NotNull
- public String getName() {
return InspectionGadgetsBundle.message("math.random.cast.to.int.quickfix");
}
private static class NewStringBufferWithCharArgumentFix
extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"new.string.buffer.with.char.argument.quickfix");
}
@Override
@NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("non.short.circuit.boolean.expression.replace.quickfix");
- }
-
- @NotNull
- @Override
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("non.short.circuit.boolean.expression.replace.quickfix");
}
@Override
private static class StaticCallOnSubclassFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("static.method.via.subclass.rationalize.quickfix");
- }
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("static.method.via.subclass.rationalize.quickfix");
}
@Override
}
private static class StaticFieldOnSubclassFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"static.field.via.subclass.rationalize.quickfix");
}
private static class MoveToConstructorFix extends InspectionGadgetsFix {
- @NotNull
- @Override
- public String getName() {
- return InspectionGadgetsBundle.message("class.initializer.move.code.to.constructor.quickfix");
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("class.initializer.move.code.to.constructor.quickfix");
}
@Override
private static class ClassMayBeInterfaceFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("class.may.be.interface.convert.quickfix");
- }
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("class.may.be.interface.convert.quickfix");
}
@Override
private static class UtilityClassCanBeEnumFix extends InspectionGadgetsFix {
@Nls
- @NotNull
- @Override
- public String getName() {
- return InspectionGadgetsBundle.message("utility.class.code.can.be.enum.quickfix");
- }
-
@NotNull
@Override
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("utility.class.code.can.be.enum.quickfix");
}
@Override
private static class CloneDeclaresCloneNotSupportedInspectionFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("clone.doesnt.declare.clonenotsupportedexception.declare.quickfix");
- }
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("clone.doesnt.declare.clonenotsupportedexception.declare.quickfix");
}
@Override
private static class CreateCloneMethodFix extends InspectionGadgetsFix {
@NotNull
@Override
- public String getName() {
- return InspectionGadgetsBundle.message("cloneable.class.without.clone.quickfix");
- }
- @Override
- @NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("cloneable.class.without.clone.quickfix");
}
@Override
@Override
@NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("if.may.be.conditional.quickfix");
- }
-
- @NotNull
- @Override
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("if.may.be.conditional.quickfix");
}
@Override
}
private static class ConfusingElseFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message("confusing.else.unwrap.quickfix");
}
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"constant.conditional.expression.simplify.quickfix");
}
- @NotNull
- @Override
- public String getFamilyName() {
- return getName();
- }
-
@Override
public void doFix(Project project, ProblemDescriptor descriptor)
throws IncorrectOperationException {
}
private static class ConstantIfStatementFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
@Override
@NotNull
- public String getName() {
+ public String getFamilyName() {
return InspectionGadgetsBundle.message(
"constant.conditional.expression.simplify.quickfix");
}
private static class DoubleNegationFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getName() {
- return InspectionGadgetsBundle.message("double.negation.quickfix");
- }
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("double.negation.quickfix");
}
@Override