mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
+1
-1
@@ -176,7 +176,7 @@ public class BackendCompilerWrapper {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (fileToDelete != null) {
|
||||
if (fileToDelete != null && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) {
|
||||
FileUtil.asyncDelete(fileToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -17,9 +17,7 @@ package com.intellij.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.roots.SourceFolder;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.openapi.util.MultiValuesMap;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -90,13 +88,8 @@ public class ArtifactBySourceFileFinderImpl extends ArtifactBySourceFileFinder {
|
||||
final Module module = ((ModuleOutputPackagingElement)element).findModule(context);
|
||||
if (module != null) {
|
||||
final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
|
||||
for (ContentEntry contentEntry : rootModel.getContentEntries()) {
|
||||
for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
|
||||
final VirtualFile sourceRoot = sourceFolder.getFile();
|
||||
if (sourceRoot != null && !sourceFolder.isTestSource()) {
|
||||
result.put(sourceRoot, artifact);
|
||||
}
|
||||
}
|
||||
for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
|
||||
result.put(sourceRoot, artifact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@ import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.roots.SourceFolder;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
@@ -365,12 +363,9 @@ public class ArtifactUtil {
|
||||
final Module module = moduleElement.findModule(context);
|
||||
if (module != null) {
|
||||
final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
|
||||
for (ContentEntry entry : rootModel.getContentEntries()) {
|
||||
for (SourceFolder folder : entry.getSourceFolders()) {
|
||||
final VirtualFile sourceRoot = folder.getFile();
|
||||
if (!folder.isTestSource() && sourceRoot != null && VfsUtil.isAncestor(sourceRoot, file, true)) {
|
||||
return VfsUtil.getRelativePath(file, sourceRoot, '/');
|
||||
}
|
||||
for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
|
||||
if (VfsUtil.isAncestor(sourceRoot, file, true)) {
|
||||
return VfsUtil.getRelativePath(file, sourceRoot, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,16 +423,11 @@ public class ArtifactUtil {
|
||||
final Module module = ((ModuleOutputPackagingElement)element).findModule(context);
|
||||
if (module != null) {
|
||||
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject());
|
||||
final ContentEntry[] contentEntries = context.getModulesProvider().getRootModel(module).getContentEntries();
|
||||
for (ContentEntry contentEntry : contentEntries) {
|
||||
for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
|
||||
final VirtualFile sourceRoot = sourceFolder.getFile();
|
||||
if (!sourceFolder.isTestSource() && sourceRoot != null) {
|
||||
final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
|
||||
if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
|
||||
result.add(sourceFile);
|
||||
}
|
||||
}
|
||||
final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
|
||||
for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
|
||||
final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
|
||||
if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
|
||||
result.add(sourceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-25
@@ -25,12 +25,9 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcodes {
|
||||
private boolean myIsModification = false;
|
||||
private boolean myIsNotStaticInner = false;
|
||||
private String myClassName;
|
||||
private String mySuperName;
|
||||
public static final String NOT_NULL = "org/jetbrains/annotations/NotNull";
|
||||
public static final String NOT_NULL_ANNO = "L"+ NOT_NULL + ";";
|
||||
private static final String ENUM_CLASS_NAME = "java/lang/Enum";
|
||||
public static final String IAE_CLASS_NAME = "java/lang/IllegalArgumentException";
|
||||
public static final String ISE_CLASS_NAME = "java/lang/IllegalStateException";
|
||||
private static final String CONSTRUCTOR_NAME = "<init>";
|
||||
@@ -51,14 +48,6 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode
|
||||
final String[] interfaces) {
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
myClassName = name;
|
||||
mySuperName = superName;
|
||||
}
|
||||
|
||||
public void visitInnerClass(final String name, final String outerName, final String innerName, final int access) {
|
||||
super.visitInnerClass(name, outerName, innerName, access);
|
||||
if (myClassName.equals(name)) {
|
||||
myIsNotStaticInner = (access & ACC_STATIC) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public MethodVisitor visitMethod(
|
||||
@@ -69,7 +58,6 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode
|
||||
final String[] exceptions) {
|
||||
final Type[] args = Type.getArgumentTypes(desc);
|
||||
final Type returnType = Type.getReturnType(desc);
|
||||
final int startParameter = getStartParameterIndex(name);
|
||||
MethodVisitor v = cv.visitMethod(access,
|
||||
name,
|
||||
desc,
|
||||
@@ -122,8 +110,8 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode
|
||||
}
|
||||
for (int p = 0; p < myNotNullParams.size(); ++p) {
|
||||
int var = ((access & ACC_STATIC) == 0) ? 1 : 0;
|
||||
int param = ((Integer)myNotNullParams.get(p)).intValue() - mySyntheticCount;
|
||||
for (int i = 0; i < param + startParameter; ++i) {
|
||||
int param = ((Integer)myNotNullParams.get(p)).intValue();
|
||||
for (int i = 0; i < param; ++i) {
|
||||
var += args[i].getSize();
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, var);
|
||||
@@ -132,7 +120,7 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode
|
||||
mv.visitJumpInsn(IFNONNULL, end);
|
||||
|
||||
generateThrow(IAE_CLASS_NAME,
|
||||
"Argument " + param + " for @NotNull parameter of " + myClassName + "." + name + " must not be null", end);
|
||||
"Argument " + (param - mySyntheticCount) + " for @NotNull parameter of " + myClassName + "." + name + " must not be null", end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,16 +180,6 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode
|
||||
};
|
||||
}
|
||||
|
||||
private int getStartParameterIndex(final String name) {
|
||||
int result = 0;
|
||||
if (CONSTRUCTOR_NAME.equals(name)) {
|
||||
if (myIsNotStaticInner) {
|
||||
result += 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isReferenceType(final Type type) {
|
||||
return type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class NewProjectUtil {
|
||||
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
|
||||
if (openProjects.length > 0) {
|
||||
int exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.new.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe")}, 1,
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe")}, 1, 0,
|
||||
Messages.getQuestionIcon());
|
||||
if (exitCode == 1) { // "No" option
|
||||
ProjectUtil.closeProject(projectToClose != null ? projectToClose : openProjects[openProjects.length - 1]);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class CreateClassDialog extends DialogWrapper {
|
||||
gbConstraints.weightx = 0;
|
||||
gbConstraints.gridwidth = 1;
|
||||
panel.add(myInformationLabel, gbConstraints);
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
gbConstraints.insets = new Insets(4, 8, 4, 8);
|
||||
gbConstraints.gridx = 1;
|
||||
gbConstraints.weightx = 1;
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public abstract class CallerChooser extends DialogWrapper {
|
||||
final JComponent calleeComponent = myCalleeEditor.getComponent();
|
||||
calleeComponent.setBorder(IdeBorderFactory.createTitledBorder(RefactoringBundle.message("caller.chooser.callee.method")));
|
||||
splitter.setSecondComponent(calleeComponent);
|
||||
splitter.setBorder(IdeBorderFactory.createBorder());
|
||||
splitter.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
return splitter;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class CopyClassDialog extends DialogWrapper{
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
gbConstraints.insets = new Insets(4,8,4,8);
|
||||
gbConstraints.weightx = 1;
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class EnclosingMethodSelectionDialog extends DialogWrapper {
|
||||
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
+1
-1
@@ -353,7 +353,7 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
private JPanel createReplaceFieldsWithGettersPanel() {
|
||||
JPanel radioButtonPanel = new JPanel(new GridBagLayout());
|
||||
|
||||
radioButtonPanel.setBorder(IdeBorderFactory.createBorder());
|
||||
radioButtonPanel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.insets = new Insets(4, 8, 4, 8);
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class MakeParameterizedStaticDialog extends AbstractMakeStaticDialog {
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
gbConstraints.insets = new Insets(4, 8, 4, 8);
|
||||
gbConstraints.weighty = 0;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SimpleMakeStaticDialog extends AbstractMakeStaticDialog {
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
gbConstraints.insets = new Insets(4, 8, 4, 8);
|
||||
gbConstraints.weighty = 1;
|
||||
|
||||
@@ -27,7 +27,6 @@ package com.intellij.refactoring.memberPullUp;
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.JavaRefactoringSettings;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
@@ -118,7 +117,7 @@ public class PullUpDialog extends RefactoringDialog {
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
@@ -130,7 +130,7 @@ public class EditMigrationDialog extends DialogWrapper{
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel tablePanel = new JPanel(new BorderLayout());
|
||||
tablePanel.setBorder(IdeBorderFactory.createBorder());
|
||||
tablePanel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
tablePanel.add(createTable(), BorderLayout.CENTER);
|
||||
|
||||
JPanel tableButtonsPanel = new JPanel();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class EditMigrationEntryDialog extends DialogWrapper{
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
gbConstraints.insets = new Insets(4, 4, 4, 4);
|
||||
gbConstraints.weighty = 1;
|
||||
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class TurnRefsToSuperDialog extends RefactoringDialog {
|
||||
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class TypeCookDialog extends RefactoringDialog {
|
||||
JPanel optionsPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
optionsPanel.setBorder(IdeBorderFactory.createBorder());
|
||||
optionsPanel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
if (myCbDropCasts.isEnabled()) {
|
||||
myCbDropCasts.setSelected(JavaRefactoringSettings.getInstance().TYPE_COOK_DROP_CASTS);
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider,
|
||||
}
|
||||
|
||||
public void stateChanged() {
|
||||
if (project.isDisposed()) return;
|
||||
if (!project.isOpen()) return;
|
||||
if (toolWindow.getAnchor() != myAnchor) {
|
||||
myAnchor = myToolWindow.getAnchor();
|
||||
layoutPanel();
|
||||
@@ -135,17 +135,24 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider,
|
||||
Disposer.dispose(myUsagePreviewPanel);
|
||||
}
|
||||
removeAll();
|
||||
JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
|
||||
|
||||
if (isPreview()) {
|
||||
pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.RIGHT));
|
||||
|
||||
boolean vertical = myToolWindow.getAnchor() == ToolWindowAnchor.LEFT || myToolWindow.getAnchor() == ToolWindowAnchor.RIGHT;
|
||||
Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS);
|
||||
splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree));
|
||||
splitter.setFirstComponent(pane);
|
||||
myUsagePreviewPanel = new UsagePreviewPanel(myProject);
|
||||
myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
|
||||
|
||||
Disposer.register(this, myUsagePreviewPanel);
|
||||
splitter.setSecondComponent(myUsagePreviewPanel);
|
||||
add(splitter, BorderLayout.CENTER);
|
||||
}
|
||||
else {
|
||||
add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
|
||||
pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
|
||||
add(pane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
add(createToolbar().getComponent(), BorderLayout.WEST);
|
||||
|
||||
@@ -271,7 +271,7 @@ public class CreateTestDialog extends DialogWrapper {
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
GridBagConstraints constr = new GridBagConstraints();
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
*/
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum EnumConstructorSecondParam {
|
||||
Value("1", "2");
|
||||
|
||||
EnumConstructorSecondParam(String s1, @NotNull String s2) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NonStaticInnerClass {
|
||||
public NonStaticInnerClass() {
|
||||
new Inner("");
|
||||
}
|
||||
|
||||
public class Inner {
|
||||
public Inner(@NotNull String s) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StaticInnerClass {
|
||||
public StaticInnerClass() {
|
||||
new Inner("");
|
||||
}
|
||||
|
||||
public static class Inner {
|
||||
public Inner(@NotNull String s) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-15
@@ -63,6 +63,22 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
assertNotNull(field);
|
||||
}
|
||||
|
||||
public void testEnumConstructorSecondParam() throws Exception {
|
||||
Class testClass = prepareTest();
|
||||
Object field = testClass.getField("Value");
|
||||
assertNotNull(field);
|
||||
}
|
||||
|
||||
public void testStaticInnerClass() throws Exception {
|
||||
final Class aClass = prepareTest();
|
||||
assertNotNull(aClass.newInstance());
|
||||
}
|
||||
|
||||
public void testNonStaticInnerClass() throws Exception {
|
||||
final Class aClass = prepareTest();
|
||||
assertNotNull(aClass.newInstance());
|
||||
}
|
||||
|
||||
private static void verifyCallThrowsException(final String expectedError, final Object instance, final Method method, final Object... args) throws IllegalAccessException {
|
||||
String exceptionText = null;
|
||||
try {
|
||||
@@ -79,27 +95,48 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
|
||||
private Class prepareTest() throws IOException {
|
||||
String base = JavaTestUtil.getJavaTestDataPath() + "/compiler/notNullVerification/";
|
||||
String path = base + getTestName(false);
|
||||
final String baseClassName = getTestName(false);
|
||||
String path = base + baseClassName;
|
||||
String javaPath = path + ".java";
|
||||
String classPath = path + ".class";
|
||||
File classesDir = FileUtil.createTempDirectory(baseClassName, "output");
|
||||
|
||||
try {
|
||||
com.sun.tools.javac.Main.compile(new String[] { "-classpath", base+"annotations.jar", javaPath } );
|
||||
FileInputStream stream = new FileInputStream(classPath);
|
||||
byte[] content = FileUtil.adaptiveLoadBytes(stream);
|
||||
stream.close();
|
||||
|
||||
ClassReader reader = new ClassReader(content, 0, content.length);
|
||||
ClassWriter writer = new PsiClassWriter(myFixture.getProject(), false);
|
||||
final NotNullVerifyingInstrumenter instrumenter = new NotNullVerifyingInstrumenter(writer);
|
||||
reader.accept(instrumenter, 0);
|
||||
assertTrue(instrumenter.isModification());
|
||||
com.sun.tools.javac.Main.compile(new String[] { "-classpath", base+"annotations.jar", "-d", classesDir.getAbsolutePath(), javaPath } );
|
||||
|
||||
Class mainClass = null;
|
||||
final File[] files = classesDir.listFiles();
|
||||
boolean modified = false;
|
||||
MyClassLoader classLoader = new MyClassLoader(getClass().getClassLoader());
|
||||
byte[] instrumented = writer.toByteArray();
|
||||
return classLoader.doDefineClass(getTestName(false), instrumented);
|
||||
for (File file : files) {
|
||||
final String fileName = file.getName();
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
byte[] content;
|
||||
try {
|
||||
content = FileUtil.adaptiveLoadBytes(stream);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
ClassReader reader = new ClassReader(content, 0, content.length);
|
||||
ClassWriter writer = new PsiClassWriter(myFixture.getProject(), false);
|
||||
final NotNullVerifyingInstrumenter instrumenter = new NotNullVerifyingInstrumenter(writer);
|
||||
reader.accept(instrumenter, 0);
|
||||
modified |= instrumenter.isModification();
|
||||
|
||||
byte[] instrumented = writer.toByteArray();
|
||||
final String className = FileUtil.getNameWithoutExtension(fileName);
|
||||
final Class aClass = classLoader.doDefineClass(className, instrumented);
|
||||
if (className.equals(baseClassName)) {
|
||||
mainClass = aClass;
|
||||
}
|
||||
}
|
||||
assertTrue(modified);
|
||||
assertNotNull("Class " + baseClassName + " not found!", mainClass);
|
||||
return mainClass;
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(new File(classPath));
|
||||
FileUtil.delete(classesDir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +145,7 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
public Class doDefineClass(String name, byte[] data) {
|
||||
return defineClass(name, data, 0, data.length);
|
||||
}
|
||||
|
||||
@@ -677,13 +677,7 @@ public class AnalysisScope {
|
||||
}
|
||||
|
||||
private static boolean isTestOnly(Module module) {
|
||||
final ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries();
|
||||
for (ContentEntry contentEntry : contentEntries) {
|
||||
for (SourceFolder folder : contentEntry.getSourceFolders()) {
|
||||
if (!folder.isTestSource()) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return ModuleRootManager.getInstance(module).getSourceRootUrls(false).length == 0;
|
||||
}
|
||||
|
||||
public boolean isIncludeTestSource() {
|
||||
|
||||
@@ -110,17 +110,41 @@ public interface ModuleRootModel {
|
||||
*
|
||||
* @return the array of source roots.
|
||||
* @see #getContentEntries()
|
||||
* @see #getSourceRoots(boolean)
|
||||
*/
|
||||
@NotNull VirtualFile[] getSourceRoots();
|
||||
@NotNull
|
||||
VirtualFile[] getSourceRoots();
|
||||
|
||||
/**
|
||||
* Returns an array of source roots from all content entries. A helper method.
|
||||
*
|
||||
* @param includingTests determines whether test source roots should be included in the result
|
||||
* @return the array of source roots.
|
||||
* @see #getContentEntries()
|
||||
* @since 10.0
|
||||
*/
|
||||
@NotNull
|
||||
VirtualFile[] getSourceRoots(boolean includingTests);
|
||||
|
||||
/**
|
||||
* Returns an array of source root urls from all content entries. A helper method.
|
||||
*
|
||||
* @return the array of source root URLs.
|
||||
* @see #getContentEntries()
|
||||
* @see #getSourceRootUrls(boolean)
|
||||
*/
|
||||
@NotNull String[] getSourceRootUrls();
|
||||
|
||||
/**
|
||||
* Returns an array of source root urls from all content entries. A helper method.
|
||||
*
|
||||
* @param includingTests determines whether test source root urls should be included in the result
|
||||
* @return the array of source root URLs.
|
||||
* @see #getContentEntries()
|
||||
* @since 10.0
|
||||
*/
|
||||
@NotNull String[] getSourceRootUrls(boolean includingTests);
|
||||
|
||||
/**
|
||||
* Returns an exploded directory path of the module, if it is valid.
|
||||
*
|
||||
|
||||
@@ -252,20 +252,7 @@ public class ProjectRootsTraversing {
|
||||
}
|
||||
|
||||
public void visit(ModuleSourceOrderEntry orderEntry, TraverseState state, RootPolicy<TraverseState> policy) {
|
||||
if (myExcludeTests) {
|
||||
ContentEntry[] contentEntries = ModuleRootManager.getInstance(orderEntry.getOwnerModule()).getContentEntries();
|
||||
for (ContentEntry contentEntry : contentEntries) {
|
||||
for (SourceFolder folder : contentEntry.getSourceFolders()) {
|
||||
VirtualFile root = folder.getFile();
|
||||
if (root != null && !folder.isTestSource()) {
|
||||
state.add(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
state.addAll(orderEntry.getFiles(OrderRootType.SOURCES));
|
||||
}
|
||||
state.addAll(ModuleRootManager.getInstance(orderEntry.getOwnerModule()).getSourceRoots(!myExcludeTests));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1095,6 +1095,11 @@ public class CodeStyleSettings implements Cloneable, JDOMExternalizable {
|
||||
|
||||
|
||||
// ---------------------------------- XML formatting options -------------------------
|
||||
|
||||
public final static int WS_AROUND_CDATA_PRESERVE = 0;
|
||||
public final static int WS_AROUND_CDATA_NONE = 1;
|
||||
public final static int WS_AROUND_CDATA_NEW_LINES = 2;
|
||||
|
||||
public boolean XML_KEEP_WHITESPACES = false;
|
||||
public int XML_ATTRIBUTE_WRAP = WRAP_AS_NEEDED;
|
||||
public int XML_TEXT_WRAP = WRAP_AS_NEEDED;
|
||||
@@ -1110,6 +1115,9 @@ public class CodeStyleSettings implements Cloneable, JDOMExternalizable {
|
||||
public boolean XML_SPACE_AFTER_TAG_NAME = false;
|
||||
public boolean XML_SPACE_INSIDE_EMPTY_TAG = false;
|
||||
|
||||
public boolean XML_KEEP_WHITE_SPACES_INSIDE_CDATA = false;
|
||||
public int XML_WHITE_SPACE_AROUND_CDATA = WS_AROUND_CDATA_PRESERVE;
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
// ---------------------------------- HTML formatting options -------------------------
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ public class ImplementationViewComponent extends JPanel {
|
||||
label.setIcon(file.getIcon());
|
||||
label.setForeground(FileStatusManager.getInstance(project).getStatus(file).getColor());
|
||||
label.setText(file.getPresentableName());
|
||||
label.setBorder(new CompoundBorder(IdeBorderFactory.createBorder(), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5)));
|
||||
label.setBorder(new CompoundBorder(IdeBorderFactory.createRoundedBorder(), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5)));
|
||||
}
|
||||
toolbarPanel.add(label);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
@@ -62,6 +63,11 @@ class LazyEditor extends UserDataHolderBase implements Editor {
|
||||
return getEditor().getContentComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBorder(@Nullable Border border) {
|
||||
getEditor().setBorder(border);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SelectionModel getSelectionModel() {
|
||||
return getEditor().getSelectionModel();
|
||||
|
||||
@@ -228,7 +228,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
|
||||
editor.setHorizontalScrollbarVisible(false);
|
||||
editor.setVerticalScrollbarVisible(true);
|
||||
editor.getColorsScheme().setColor(EditorColors.CARET_ROW_COLOR, null);
|
||||
editor.getScrollPane().setBorder(null);
|
||||
editor.setBorder(null);
|
||||
editor.getContentComponent().setFocusCycleRoot(false);
|
||||
|
||||
final EditorSettings editorSettings = editor.getSettings();
|
||||
|
||||
@@ -51,7 +51,9 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.ListScrollingUtil;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.SpeedSearchBase;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -219,6 +221,7 @@ public class FileStructureDialog extends DialogWrapper {
|
||||
addFilterCheckbox(panel, filter);
|
||||
}
|
||||
|
||||
myCommanderPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
|
||||
panel.add(myCommanderPanel,
|
||||
new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -429,6 +430,11 @@ public class EditorWindow implements EditorEx, UserDataHolderEx {
|
||||
return myDelegate.getScrollPane();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBorder(Border border) {
|
||||
myDelegate.setBorder(border);
|
||||
}
|
||||
|
||||
public int logicalPositionToOffset(@NotNull final LogicalPosition pos) {
|
||||
int lineStartOffset = myDocumentWindow.getLineStartOffset(pos.line);
|
||||
return calcOffset(pos.column, pos.line, lineStartOffset);
|
||||
|
||||
@@ -359,14 +359,25 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements ModuleCo
|
||||
|
||||
@NotNull
|
||||
public String[] getSourceRootUrls() {
|
||||
return getSourceRootUrls(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getSourceRootUrls(boolean includingTests) {
|
||||
LOG.assertTrue(!myIsDisposed);
|
||||
return myRootModel.getSourceRootUrls();
|
||||
return myRootModel.getSourceRootUrls(includingTests);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getSourceRoots() {
|
||||
return getSourceRoots(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getSourceRoots(final boolean includingTests) {
|
||||
LOG.assertTrue(!myIsDisposed);
|
||||
return myRootModel.getSourceRoots();
|
||||
return myRootModel.getSourceRoots(includingTests);
|
||||
}
|
||||
|
||||
public void projectOpened() {
|
||||
|
||||
+2
-25
@@ -171,19 +171,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
|
||||
private void collectModuleRoots(ModuleRootModel rootModel, Collection<VirtualFile> result) {
|
||||
if (myRootType.equals(OrderRootType.SOURCES)) {
|
||||
if (myOrderEnumerator.isProductionOnly()) {
|
||||
for (ContentEntry contentEntry : rootModel.getContentEntries()) {
|
||||
for (SourceFolder folder : contentEntry.getSourceFolders()) {
|
||||
VirtualFile root = folder.getFile();
|
||||
if (root != null && !folder.isTestSource()) {
|
||||
result.add(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(result, rootModel.getSourceRoots());
|
||||
}
|
||||
Collections.addAll(result, rootModel.getSourceRoots(!myOrderEnumerator.isProductionOnly()));
|
||||
}
|
||||
else if (myRootType.equals(OrderRootType.CLASSES)) {
|
||||
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
|
||||
@@ -195,18 +183,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
|
||||
private void collectModuleRootsUrls(ModuleRootModel rootModel, Collection<String> result) {
|
||||
if (myRootType.equals(OrderRootType.SOURCES)) {
|
||||
if (myOrderEnumerator.isProductionOnly()) {
|
||||
for (ContentEntry contentEntry : rootModel.getContentEntries()) {
|
||||
for (SourceFolder folder : contentEntry.getSourceFolders()) {
|
||||
if (!folder.isTestSource()) {
|
||||
result.add(folder.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(result, rootModel.getSourceRootUrls());
|
||||
}
|
||||
Collections.addAll(result, rootModel.getSourceRootUrls(!myOrderEnumerator.isProductionOnly()));
|
||||
}
|
||||
else if (myRootType.equals(OrderRootType.CLASSES)) {
|
||||
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
|
||||
|
||||
@@ -325,11 +325,18 @@ public class RootModelImpl implements ModifiableRootModel {
|
||||
|
||||
@NotNull
|
||||
public String[] getSourceRootUrls() {
|
||||
return getSourceRootUrls(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[] getSourceRootUrls(boolean includingTests) {
|
||||
List<String> result = new SmartList<String>();
|
||||
for (ContentEntry contentEntry : myContent) {
|
||||
final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
|
||||
for (SourceFolder sourceFolder : sourceFolders) {
|
||||
result.add(sourceFolder.getUrl());
|
||||
if (includingTests || !sourceFolder.isTestSource()) {
|
||||
result.add(sourceFolder.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ContainerUtil.toArray(result, new String[result.size()]);
|
||||
@@ -337,12 +344,17 @@ public class RootModelImpl implements ModifiableRootModel {
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getSourceRoots() {
|
||||
return getSourceRoots(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getSourceRoots(final boolean includingTests) {
|
||||
List<VirtualFile> result = new SmartList<VirtualFile>();
|
||||
for (ContentEntry contentEntry : myContent) {
|
||||
final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
|
||||
for (SourceFolder sourceFolder : sourceFolders) {
|
||||
final VirtualFile file = sourceFolder.getFile();
|
||||
if (file != null) {
|
||||
if (file != null && (includingTests || !sourceFolder.isTestSource())) {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
@@ -1061,4 +1073,3 @@ public class RootModelImpl implements ModifiableRootModel {
|
||||
Disposer.register(myDisposable, disposable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ class CopyFilesOrDirectoriesDialog extends DialogWrapper{
|
||||
protected JComponent createNorthPanel() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
myInformationLabel = new JLabel();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ExtractIncludeDialog extends DialogWrapper {
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel panel = new JPanel(new VerticalFlowLayout());
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
JLabel nameLabel = new JLabel();
|
||||
panel.add(nameLabel);
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class MoveFilesOrDirectoriesDialog extends DialogWrapper{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
myNameLabel = new JLabel();
|
||||
panel.add(myNameLabel, new GridBagConstraints(0,0,2,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(4,8,4,8),0,0));
|
||||
|
||||
@@ -186,7 +186,7 @@ public class RenameDialog extends RefactoringDialog {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
panel.setBorder(IdeBorderFactory.createBorder());
|
||||
panel.setBorder(IdeBorderFactory.createRoundedBorder());
|
||||
|
||||
gbConstraints.insets = new Insets(4, 8, 4, 8);
|
||||
gbConstraints.weighty = 0;
|
||||
|
||||
@@ -21,10 +21,9 @@ import com.intellij.history.core.changes.Change;
|
||||
import com.intellij.history.core.changes.ChangeSet;
|
||||
import com.intellij.history.core.changes.ChangeVisitor;
|
||||
import com.intellij.history.core.storage.Content;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.history.utils.LocalHistoryLog;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,24 +33,23 @@ import java.util.List;
|
||||
public class ChangeList {
|
||||
private final ChangeListStorage myStorage;
|
||||
|
||||
private ChangeSetBlock myCurrentBlock;
|
||||
|
||||
private ChangeSet myCurrentChangeSet;
|
||||
private int myChangeSetDepth;
|
||||
private ChangeSet myCurrentChangeSet;
|
||||
|
||||
private int myIntervalBetweenActivities = 12 * 60 * 60 * 1000; // one day
|
||||
|
||||
public ChangeList(ChangeListStorage storage) {
|
||||
myStorage = storage;
|
||||
myCurrentBlock = storage.createNewBlock();
|
||||
}
|
||||
|
||||
public synchronized void save() {
|
||||
flushChanges(true);
|
||||
myStorage.flush();
|
||||
}
|
||||
|
||||
public synchronized void close() {
|
||||
flushChanges(true);
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
LocalHistoryLog.LOG.assertTrue(myCurrentChangeSet == null, "current changes won't be saved: " + myCurrentChangeSet);
|
||||
}
|
||||
myStorage.close();
|
||||
}
|
||||
|
||||
@@ -73,7 +71,6 @@ public class ChangeList {
|
||||
|
||||
private void doBeginChangeSet() {
|
||||
myCurrentChangeSet = new ChangeSet(myStorage.nextId(), Clock.getCurrentTimestamp());
|
||||
myCurrentBlock.add(myCurrentChangeSet);
|
||||
}
|
||||
|
||||
public synchronized boolean forceBeginChangeSet() {
|
||||
@@ -86,7 +83,7 @@ public class ChangeList {
|
||||
}
|
||||
|
||||
public synchronized boolean endChangeSet(String name) {
|
||||
assert myChangeSetDepth > 0;
|
||||
LocalHistoryLog.LOG.assertTrue(myChangeSetDepth > 0, "not balanced 'begin/end-change set' calls");
|
||||
|
||||
myChangeSetDepth--;
|
||||
if (myChangeSetDepth > 0) return false;
|
||||
@@ -96,14 +93,14 @@ public class ChangeList {
|
||||
|
||||
private boolean doEndChangeSet(String name) {
|
||||
if (myCurrentChangeSet.getChanges().isEmpty()) {
|
||||
myCurrentBlock.removeLast();
|
||||
myCurrentChangeSet = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
myCurrentChangeSet.setName(name);
|
||||
myStorage.writeNextSet(myCurrentChangeSet);
|
||||
myCurrentChangeSet = null;
|
||||
|
||||
flushChanges(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,13 +113,12 @@ public class ChangeList {
|
||||
return result;
|
||||
}
|
||||
|
||||
// todo synchronization issue: changeset may me modified while being iterated
|
||||
public synchronized Iterable<ChangeSet> iterChanges() {
|
||||
return new Iterable<ChangeSet>() {
|
||||
public Iterator<ChangeSet> iterator() {
|
||||
return new Iterator<ChangeSet>() {
|
||||
private ChangeSetBlock currentBlock;
|
||||
private Iterator<ChangeSet> currentIter;
|
||||
|
||||
private ChangeSetHolder currentBlock;
|
||||
private ChangeSet next = fetchNext();
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -138,19 +134,21 @@ public class ChangeList {
|
||||
private ChangeSet fetchNext() {
|
||||
if (currentBlock == null) {
|
||||
synchronized (ChangeList.this) {
|
||||
currentBlock = myCurrentBlock;
|
||||
List<ChangeSet> copy = new ArrayList<ChangeSet>(currentBlock.changes);
|
||||
currentIter = ContainerUtil.iterateBackward(copy).iterator();
|
||||
if (myCurrentChangeSet != null) {
|
||||
currentBlock = new ChangeSetHolder(-1, myCurrentChangeSet);
|
||||
}
|
||||
else {
|
||||
currentBlock = myStorage.readPrevious(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!currentIter.hasNext()) {
|
||||
else {
|
||||
synchronized (ChangeList.this) {
|
||||
currentBlock = myStorage.readPrevious(currentBlock);
|
||||
currentBlock = myStorage.readPrevious(currentBlock.id);
|
||||
}
|
||||
if (currentBlock == null) return null;
|
||||
currentIter = ContainerUtil.iterateBackward(currentBlock.changes).iterator();
|
||||
}
|
||||
return currentIter.next();
|
||||
if (currentBlock == null) return null;
|
||||
return currentBlock.changeSet;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
@@ -161,20 +159,6 @@ public class ChangeList {
|
||||
};
|
||||
}
|
||||
|
||||
private void flushChanges(boolean force) {
|
||||
if (myChangeSetDepth > 0) return;
|
||||
if (myCurrentBlock.shouldFlush(force) || flushEveryChangeSetInTests()) {
|
||||
myStorage.writeNextBlock(myCurrentBlock);
|
||||
myCurrentBlock = myStorage.createNewBlock();
|
||||
}
|
||||
myStorage.flush();
|
||||
}
|
||||
|
||||
private boolean flushEveryChangeSetInTests() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
return app == null || app.isUnitTestMode();
|
||||
}
|
||||
|
||||
public void accept(ChangeVisitor v) {
|
||||
try {
|
||||
for (ChangeSet change : iterChanges()) {
|
||||
|
||||
@@ -20,21 +20,17 @@ import com.intellij.history.core.changes.ChangeSet;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChangeListStorage {
|
||||
void close();
|
||||
|
||||
long nextId();
|
||||
|
||||
ChangeSetBlock createNewBlock();
|
||||
|
||||
@Nullable
|
||||
ChangeSetBlock readPrevious(ChangeSetBlock block);
|
||||
ChangeSetHolder readPrevious(int id);
|
||||
|
||||
void purge(long period, int intervalBetweenActivities, Consumer<ChangeSet> processor);
|
||||
|
||||
void writeNextBlock(ChangeSetBlock block);
|
||||
void writeNextSet(ChangeSet changeSet);
|
||||
|
||||
void flush();
|
||||
}
|
||||
@@ -27,21 +27,16 @@ import com.intellij.util.io.storage.AbstractStorage;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeListStorageImpl implements ChangeListStorage {
|
||||
private static final int VERSION = 3;
|
||||
|
||||
private static final int VERSION = 4;
|
||||
private static final String STORAGE_FILE = "changes";
|
||||
|
||||
private final File myStorageDir;
|
||||
|
||||
private final LinkedStorage myStorage;
|
||||
|
||||
public ChangeListStorageImpl(File storageDir) {
|
||||
myStorageDir = storageDir;
|
||||
try {
|
||||
myStorage = createStorage(myStorageDir);
|
||||
myStorage = createStorage(storageDir);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw handleError(e);
|
||||
@@ -90,27 +85,18 @@ public class ChangeListStorageImpl implements ChangeListStorage {
|
||||
return myStorage.nextId();
|
||||
}
|
||||
|
||||
public synchronized ChangeSetBlock createNewBlock() {
|
||||
return new ChangeSetBlock(0);
|
||||
}
|
||||
|
||||
public synchronized ChangeSetBlock readPrevious(ChangeSetBlock block) {
|
||||
int prevId = block.id == 0 ? myStorage.getLastRecord() : myStorage.getPrevRecord(block.id);
|
||||
public synchronized ChangeSetHolder readPrevious(int id) {
|
||||
int prevId = id == -1 ? myStorage.getLastRecord() : myStorage.getPrevRecord(id);
|
||||
if (prevId == 0) return null;
|
||||
assert prevId != block.id;
|
||||
|
||||
return doReadBlock(prevId);
|
||||
}
|
||||
|
||||
private ChangeSetBlock doReadBlock(int id) {
|
||||
private ChangeSetHolder doReadBlock(int id) {
|
||||
try {
|
||||
DataInputStream in = myStorage.readStream(id);
|
||||
try {
|
||||
int size = in.readInt();
|
||||
List<ChangeSet> changes = new ArrayList<ChangeSet>(size);
|
||||
while (size-- > 0) {
|
||||
changes.add(new ChangeSet(in));
|
||||
}
|
||||
return new ChangeSetBlock(id, changes);
|
||||
return new ChangeSetHolder(id, new ChangeSet(in));
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
@@ -121,15 +107,12 @@ public class ChangeListStorageImpl implements ChangeListStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void writeNextBlock(ChangeSetBlock block) {
|
||||
public synchronized void writeNextSet(ChangeSet changeSet) {
|
||||
try {
|
||||
block.id = myStorage.createNextRecord();
|
||||
AbstractStorage.StorageDataOutput out = myStorage.writeStream(block.id);
|
||||
int id = myStorage.createNextRecord();
|
||||
AbstractStorage.StorageDataOutput out = myStorage.writeStream(id);
|
||||
try {
|
||||
out.writeInt(block.changes.size());
|
||||
for (ChangeSet each : block.changes) {
|
||||
each.write(out);
|
||||
}
|
||||
changeSet.write(out);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
@@ -143,10 +126,8 @@ public class ChangeListStorageImpl implements ChangeListStorage {
|
||||
public synchronized void purge(long period, int intervalBetweenActivities, Consumer<ChangeSet> processor) {
|
||||
int eachBlockId = findFirstObsoleteBlock(period, intervalBetweenActivities);
|
||||
try {
|
||||
while(eachBlockId != 0) {
|
||||
for (ChangeSet eachChangeSet : doReadBlock(eachBlockId).changes) {
|
||||
processor.consume(eachChangeSet);
|
||||
}
|
||||
while (eachBlockId != 0) {
|
||||
processor.consume(doReadBlock(eachBlockId).changeSet);
|
||||
myStorage.deleteRecord(eachBlockId);
|
||||
eachBlockId = myStorage.getPrevRecord(eachBlockId);
|
||||
}
|
||||
|
||||
+5
-30
@@ -20,37 +20,12 @@ import com.intellij.history.core.changes.ChangeSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeSetBlock {
|
||||
private static final int BLOCK_SIZE = 1000;
|
||||
public int id;
|
||||
public final List<ChangeSet> changes;
|
||||
public class ChangeSetHolder {
|
||||
public final int id;
|
||||
public final ChangeSet changeSet;
|
||||
|
||||
public ChangeSetBlock(int id) {
|
||||
public ChangeSetHolder(int id, ChangeSet changeSet) {
|
||||
this.id = id;
|
||||
this.changes = new ArrayList<ChangeSet>(BLOCK_SIZE);
|
||||
}
|
||||
|
||||
ChangeSetBlock(int id, List<ChangeSet> changes) {
|
||||
this.id = id;
|
||||
this.changes = changes;
|
||||
}
|
||||
|
||||
public void add(ChangeSet changeSet) {
|
||||
changes.add(changeSet);
|
||||
}
|
||||
|
||||
public void removeLast() {
|
||||
changes.remove(changes.size() - 1);
|
||||
}
|
||||
|
||||
public boolean shouldFlush(boolean force) {
|
||||
int count = 0;
|
||||
for (ChangeSet each : changes) {
|
||||
count += each.getChanges().size();
|
||||
|
||||
if (count >= BLOCK_SIZE) return true;
|
||||
if (force && count > 0) return true;
|
||||
}
|
||||
return false;
|
||||
this.changeSet = changeSet;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import com.intellij.openapi.vfs.ex.VirtualFileManagerEx;
|
||||
import com.intellij.util.io.storage.HeavyProcessLatch;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.io.File;
|
||||
@@ -58,6 +59,8 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode() && ApplicationManager.getApplication().isHeadlessEnvironment()) return;
|
||||
|
||||
myShutdownTask = new Runnable() {
|
||||
public void run() {
|
||||
disposeComponent();
|
||||
@@ -193,10 +196,12 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone
|
||||
return "Local History";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LocalHistoryFacade getFacade() {
|
||||
return myVcs;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IdeaGateway getGateway() {
|
||||
return myGateway;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.patch.CreatePatchConfigurationPanel;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.ExcludingTraversalPolicy;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.PopupHandler;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ImageLoader;
|
||||
@@ -165,10 +162,10 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
|
||||
restoreSplitterProportion();
|
||||
|
||||
root.add(mySplitter);
|
||||
setDiffBorder(IdeBorderFactory.createSimpleBorder(1, 1, 0, 0));
|
||||
setDiffBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.LEFT));
|
||||
}
|
||||
else {
|
||||
setDiffBorder(IdeBorderFactory.createSimpleBorder(1, 0, 1, 0));
|
||||
setDiffBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.BOTTOM));
|
||||
root.add(myDiffView);
|
||||
}
|
||||
|
||||
@@ -209,7 +206,7 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
|
||||
}
|
||||
result.add(toolBarPanel, BorderLayout.NORTH);
|
||||
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myRevisionsList.getComponent());
|
||||
scrollPane.setBorder(IdeBorderFactory.createSimpleBorder(1, 0, 0, 1));
|
||||
scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.RIGHT));
|
||||
result.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
return result;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.history.core.changes.ContentChange;
|
||||
import com.intellij.history.core.changes.StructuralChange;
|
||||
import com.intellij.history.integration.IdeaGateway;
|
||||
import com.intellij.history.integration.LocalHistoryImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.undo.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -50,11 +51,12 @@ public class FileUndoProvider extends VirtualFileAdapter implements UndoProvider
|
||||
}
|
||||
|
||||
public FileUndoProvider(Project project) {
|
||||
myProject = project;
|
||||
myProject = project;
|
||||
if (myProject == null) return;
|
||||
|
||||
myLocalHistory = LocalHistoryImpl.getInstanceImpl().getFacade();
|
||||
myGateway = LocalHistoryImpl.getInstanceImpl().getGateway();
|
||||
if (myLocalHistory == null || myGateway == null) return; // local history was not initialized (e.g. in headless environment)
|
||||
|
||||
getFileManager().addVirtualFileListener(this, project);
|
||||
myLocalHistory.addListener(new LocalHistoryFacade.Listener() {
|
||||
|
||||
+7
-13
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
public class InMemoryChangeListStorage implements ChangeListStorage {
|
||||
private int myCurrentId;
|
||||
private List<ChangeSetBlock> myBlocks = new ArrayList<ChangeSetBlock>();
|
||||
private List<ChangeSet> mySets = new ArrayList<ChangeSet>();
|
||||
|
||||
public void close() {
|
||||
}
|
||||
@@ -32,20 +32,14 @@ public class InMemoryChangeListStorage implements ChangeListStorage {
|
||||
return myCurrentId++;
|
||||
}
|
||||
|
||||
public ChangeSetBlock createNewBlock() {
|
||||
return new ChangeSetBlock(-1);
|
||||
public ChangeSetHolder readPrevious(int id) {
|
||||
if (mySets.isEmpty()) return null;
|
||||
if (id == -1) return new ChangeSetHolder(mySets.size() - 1, mySets.get(mySets.size() - 1));
|
||||
return id == 0 ? null : new ChangeSetHolder(id -1, mySets.get(id - 1));
|
||||
}
|
||||
|
||||
public ChangeSetBlock readPrevious(ChangeSetBlock block) {
|
||||
if (myBlocks.isEmpty()) return null;
|
||||
if (block.id == 0) return null;
|
||||
if (block.id == -1) return myBlocks.get(myBlocks.size() - 1);
|
||||
return myBlocks.get(block.id - 1);
|
||||
}
|
||||
|
||||
public void writeNextBlock(ChangeSetBlock block) {
|
||||
myBlocks.add(block);
|
||||
block.id = myBlocks.size() - 1;
|
||||
public void writeNextSet(ChangeSet changeSet) {
|
||||
mySets.add(changeSet);
|
||||
}
|
||||
|
||||
public void purge(long period, int intervalBetweenActivities, Consumer<ChangeSet> processor) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
@@ -69,6 +70,8 @@ public interface Editor extends UserDataHolder {
|
||||
*/
|
||||
@NotNull JComponent getContentComponent();
|
||||
|
||||
void setBorder(@Nullable Border border);
|
||||
|
||||
/**
|
||||
* Returns the selection model for the editor, which can be used to select ranges of text in
|
||||
* the document and retrieve information about the selection.
|
||||
|
||||
@@ -74,6 +74,8 @@ public abstract class DialogWrapper {
|
||||
*/
|
||||
@NonNls public static final String DEFAULT_ACTION = "DefaultAction";
|
||||
|
||||
@NonNls public static final String FOCUSED_ACTION = "FocusedAction";
|
||||
|
||||
private final DialogWrapperPeer myPeer;
|
||||
private int myExitCode = CANCEL_EXIT_CODE;
|
||||
|
||||
@@ -107,6 +109,8 @@ public abstract class DialogWrapper {
|
||||
@Nullable
|
||||
private DoNotAskOption myDoNotAsk;
|
||||
|
||||
private JComponent myPreferredFocusedComponent;
|
||||
|
||||
protected String getDoNotShowMessage() {
|
||||
return CommonBundle.message("dialog.options.do.not.show");
|
||||
}
|
||||
@@ -370,6 +374,10 @@ public abstract class DialogWrapper {
|
||||
button.setMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
if (action.getValue(FOCUSED_ACTION) != null) {
|
||||
myPreferredFocusedComponent = button;
|
||||
}
|
||||
|
||||
buttons.add(button);
|
||||
buttonsPanel.add(button);
|
||||
}
|
||||
@@ -706,7 +714,7 @@ public abstract class DialogWrapper {
|
||||
*/
|
||||
@Nullable
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return null;
|
||||
return SystemInfo.isMac ? myPreferredFocusedComponent : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,11 +90,15 @@ public class Messages {
|
||||
}
|
||||
|
||||
public static int showDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(project, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
MessageDialog dialog = new MessageDialog(project, message, title, options, defaultOptionIndex, icon);
|
||||
MessageDialog dialog = new MessageDialog(project, message, title, options, defaultOptionIndex, focusedOptionIndex, icon);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
@@ -106,11 +110,27 @@ public class Messages {
|
||||
}
|
||||
|
||||
public static int showDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(parent, message, title, options, defaultOptionIndex, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
MessageDialog dialog = new MessageDialog(parent, message, title, options, defaultOptionIndex, icon);
|
||||
MessageDialog dialog = new MessageDialog(parent, message, title, options, defaultOptionIndex, focusedOptionIndex, icon);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
//what's it? if (application.isUnitTestMode()) throw new RuntimeException(message);
|
||||
MessageDialog dialog = new MessageDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
@@ -123,19 +143,15 @@ public class Messages {
|
||||
* @see #showDialog(Component, String, String, String[], int, Icon)
|
||||
*/
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
//what's it? if (application.isUnitTestMode()) throw new RuntimeException(message);
|
||||
MessageDialog dialog = new MessageDialog(message, title, options, defaultOptionIndex, icon, doNotAskOption);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
return showDialog(message, title, options, defaultOptionIndex, -1, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(message, title, options, defaultOptionIndex, icon, null);
|
||||
return showDialog(message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
return showDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,33 +502,47 @@ public class Messages {
|
||||
protected String myMessage;
|
||||
protected String[] myOptions;
|
||||
protected int myDefaultOptionIndex;
|
||||
protected int myFocusedOptionIndex;
|
||||
protected Icon myIcon;
|
||||
|
||||
public MessageDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
this(project, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public MessageDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
super(project, false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
this(parent, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
super(parent, false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, -1, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, doNotAskOption);
|
||||
this(message, title, options, defaultOptionIndex, -1, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
private void _init(String title, String message, String[] options, int defaultOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
private void _init(String title, String message, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
setTitle(title);
|
||||
myMessage = message;
|
||||
myOptions = options;
|
||||
myDefaultOptionIndex = defaultOptionIndex;
|
||||
myFocusedOptionIndex = focusedOptionIndex;
|
||||
myIcon = icon;
|
||||
setButtonsAlignment(SwingUtilities.CENTER);
|
||||
setDoNotAskOption(doNotAskOption);
|
||||
@@ -529,9 +559,15 @@ public class Messages {
|
||||
close(exitCode, true);
|
||||
}
|
||||
};
|
||||
|
||||
if (i == myDefaultOptionIndex) {
|
||||
actions[i].putValue(DEFAULT_ACTION, Boolean.TRUE);
|
||||
}
|
||||
|
||||
if (i == myFocusedOptionIndex) {
|
||||
actions[i].putValue(FOCUSED_ACTION, Boolean.TRUE);
|
||||
}
|
||||
|
||||
assignMnemonic(option, actions[i]);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,6 +49,29 @@ public class SimpleToolWindowPanel extends JPanel implements QuickActionProvider
|
||||
myBorderless = borderless;
|
||||
myVertical = vertical;
|
||||
setProvideQuickActions(true);
|
||||
|
||||
addContainerListener(new ContainerAdapter() {
|
||||
@Override
|
||||
public void componentAdded(ContainerEvent e) {
|
||||
Component child = e.getChild();
|
||||
|
||||
if (child instanceof Container) {
|
||||
((Container)child).addContainerListener(this);
|
||||
}
|
||||
if (myBorderless) {
|
||||
UIUtil.removeScrollBorder(SimpleToolWindowPanel.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentRemoved(ContainerEvent e) {
|
||||
Component child = e.getChild();
|
||||
|
||||
if (child instanceof Container) {
|
||||
((Container)child).removeContainerListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setToolbar(JComponent c) {
|
||||
@@ -59,10 +83,6 @@ public class SimpleToolWindowPanel extends JPanel implements QuickActionProvider
|
||||
add(c, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
if (myBorderless) {
|
||||
UIUtil.removeScrollBorder(c);
|
||||
}
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
public class ExcludingTraversalPolicy extends FocusTraversalPolicy {
|
||||
private final FocusTraversalPolicy myWrappee;
|
||||
private final Set<Component> myExcludes = new THashSet<Component>();
|
||||
private final Set<String> myRecursionGuard = new THashSet<String>();
|
||||
|
||||
public ExcludingTraversalPolicy(Component... excludes) {
|
||||
this(KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy(), excludes);
|
||||
@@ -43,26 +44,40 @@ public class ExcludingTraversalPolicy extends FocusTraversalPolicy {
|
||||
|
||||
@Override
|
||||
public Component getComponentAfter(Container aContainer, Component aComponent) {
|
||||
return traverse(aContainer, aComponent, new Function<Pair<Container, Component>, Component>() {
|
||||
public Component fun(Pair<Container, Component> param) {
|
||||
return myWrappee.getComponentAfter(param.first, param.second);
|
||||
}
|
||||
});
|
||||
try {
|
||||
if (!myRecursionGuard.add("getComponentAfter")) return null;
|
||||
|
||||
return traverse(aContainer, aComponent, new Function<Pair<Container, Component>, Component>() {
|
||||
public Component fun(Pair<Container, Component> param) {
|
||||
return myWrappee.getComponentAfter(param.first, param.second);
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
myRecursionGuard.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponentBefore(Container aContainer, Component aComponent) {
|
||||
return traverse(aContainer, aComponent, new Function<Pair<Container, Component>, Component>() {
|
||||
public Component fun(Pair<Container, Component> param) {
|
||||
return myWrappee.getComponentBefore(param.first, param.second);
|
||||
}
|
||||
});
|
||||
try {
|
||||
if (!myRecursionGuard.add("getComponentBefore")) return null;
|
||||
|
||||
return traverse(aContainer, aComponent, new Function<Pair<Container, Component>, Component>() {
|
||||
public Component fun(Pair<Container, Component> param) {
|
||||
return myWrappee.getComponentBefore(param.first, param.second);
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
myRecursionGuard.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private Component traverse(Container aContainer, Component aComponent, Function<Pair<Container, Component>, Component> func) {
|
||||
Set<Component> guard = new THashSet<Component>();
|
||||
Set<Component> loopGuard = new THashSet<Component>();
|
||||
do {
|
||||
if (!guard.add(aComponent)) return null;
|
||||
if (!loopGuard.add(aComponent)) return null;
|
||||
aComponent = func.fun(Pair.create(aContainer, aComponent));
|
||||
}
|
||||
while (aComponent != null && myExcludes.contains(aComponent));
|
||||
@@ -71,20 +86,41 @@ public class ExcludingTraversalPolicy extends FocusTraversalPolicy {
|
||||
|
||||
@Override
|
||||
public Component getFirstComponent(Container aContainer) {
|
||||
Component result = myWrappee.getFirstComponent(aContainer);
|
||||
if (result == null) return null;
|
||||
return myExcludes.contains(result) ? getComponentAfter(aContainer, result) : result;
|
||||
try {
|
||||
if (!myRecursionGuard.add("getFirstComponent")) return null;
|
||||
|
||||
Component result = myWrappee.getFirstComponent(aContainer);
|
||||
if (result == null) return null;
|
||||
return myExcludes.contains(result) ? getComponentAfter(aContainer, result) : result;
|
||||
}
|
||||
finally {
|
||||
myRecursionGuard.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getLastComponent(Container aContainer) {
|
||||
Component result = myWrappee.getLastComponent(aContainer);
|
||||
if (result == null) return null;
|
||||
return myExcludes.contains(result) ? getComponentBefore(aContainer, result) : result;
|
||||
try {
|
||||
if (!myRecursionGuard.add("getLastComponent")) return null;
|
||||
|
||||
Component result = myWrappee.getLastComponent(aContainer);
|
||||
if (result == null) return null;
|
||||
return myExcludes.contains(result) ? getComponentBefore(aContainer, result) : result;
|
||||
}
|
||||
finally {
|
||||
myRecursionGuard.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getDefaultComponent(Container aContainer) {
|
||||
return getFirstComponent(aContainer);
|
||||
try {
|
||||
if (!myRecursionGuard.add("getDefaultComponent")) return null;
|
||||
|
||||
return getFirstComponent(aContainer);
|
||||
}
|
||||
finally {
|
||||
myRecursionGuard.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class GuiUtils {
|
||||
|
||||
public static JPanel makeDialogPanel(JPanel aPanel) {
|
||||
JPanel emptyBordered = makePaddedPanel(aPanel, paddingFromDialogBoundaries);
|
||||
return wrapWithBorder(emptyBordered, IdeBorderFactory.createBorder());
|
||||
return wrapWithBorder(emptyBordered, IdeBorderFactory.createRoundedBorder());
|
||||
}
|
||||
|
||||
public static JPanel makeTitledPanel(JComponent aComponent, String aTitle) {
|
||||
|
||||
@@ -25,18 +25,18 @@ import javax.swing.border.TitledBorder;
|
||||
import java.awt.*;
|
||||
|
||||
public class IdeBorderFactory {
|
||||
public static TitledBorder createTitledBorder(String title) {
|
||||
//return BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title);
|
||||
return BorderFactory.createTitledBorder(new RoundedLineBorder(Color.LIGHT_GRAY, 3), title);
|
||||
}
|
||||
|
||||
public static TitledBorder createTitledHeaderBorder(String title) {
|
||||
//return BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title);
|
||||
return BorderFactory.createTitledBorder(new CompoundBorder(createEmptyBorder(0, 0, 5, 5), new SideBorder(Color.LIGHT_GRAY, SideBorder.TOP)), title);
|
||||
}
|
||||
public static final int BORDER_ROUNDNESS = 5;
|
||||
|
||||
public static Border createBorder() {
|
||||
return new RoundedLineBorder(Color.GRAY, 5);
|
||||
return createBorder(SideBorder.ALL);
|
||||
}
|
||||
|
||||
public static Border createBorder(int borders) {
|
||||
return new SideBorder(getBorderColor(), borders);
|
||||
}
|
||||
|
||||
public static Border createRoundedBorder() {
|
||||
return new RoundedLineBorder(getBorderColor(), BORDER_ROUNDNESS);
|
||||
}
|
||||
|
||||
public static Border createEmptyBorder(Insets insets) {
|
||||
@@ -47,11 +47,16 @@ public class IdeBorderFactory {
|
||||
return new EmptyBorder(top, left, bottom, right);
|
||||
}
|
||||
|
||||
public static Border createSimpleBorder() {
|
||||
return createSimpleBorder(1, 1, 1, 1);
|
||||
public static TitledBorder createTitledBorder(String title) {
|
||||
return BorderFactory.createTitledBorder(new RoundedLineBorder(getBorderColor(), BORDER_ROUNDNESS), title);
|
||||
}
|
||||
|
||||
public static Border createSimpleBorder(int top, int left, int bottom, int right) {
|
||||
return BorderFactory.createMatteBorder(top, left, bottom, right, UIUtil.getBorderSeparatorColor());
|
||||
public static TitledBorder createTitledHeaderBorder(String title) {
|
||||
return BorderFactory.createTitledBorder(new CompoundBorder(createEmptyBorder(0, 0, BORDER_ROUNDNESS, BORDER_ROUNDNESS),
|
||||
new SideBorder(getBorderColor(), SideBorder.TOP)), title);
|
||||
}
|
||||
}
|
||||
|
||||
private static Color getBorderColor() {
|
||||
return UIUtil.getBorderColor();
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ public class JBScrollBar extends JScrollBar{
|
||||
|
||||
private void init() {
|
||||
putClientProperty("JScrollBar.fastWheelScrolling", Boolean.TRUE); // fast scrolling for JDK 6
|
||||
setFocusable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.util.ui.ButtonlessScrollBarUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.plaf.ScrollPaneUI;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -45,7 +44,7 @@ public class JBScrollPane extends JScrollPane {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setBorder(IdeBorderFactory.createSimpleBorder());
|
||||
setBorder(IdeBorderFactory.createBorder());
|
||||
setCorner(UPPER_RIGHT_CORNER, new Corner(UPPER_RIGHT_CORNER));
|
||||
setCorner(UPPER_LEFT_CORNER, new Corner(UPPER_LEFT_CORNER));
|
||||
setCorner(LOWER_RIGHT_CORNER, new Corner(LOWER_RIGHT_CORNER));
|
||||
@@ -54,35 +53,7 @@ public class JBScrollPane extends JScrollPane {
|
||||
|
||||
public void setUI(ScrollPaneUI ui) {
|
||||
super.setUI(ui);
|
||||
setViewportBorder(new Border() {
|
||||
@Override
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
JViewport vp = getViewport();
|
||||
if (vp == null) return;
|
||||
|
||||
Component view = vp.getView();
|
||||
if (view == null) return;
|
||||
|
||||
Color bg = view.getBackground();
|
||||
if (bg == null) return;
|
||||
|
||||
g.setColor(bg);
|
||||
g.drawLine(0, 0, width - 1, 0);
|
||||
g.drawLine(0, height - 1, width - 1, height - 1);
|
||||
g.drawLine(0, 0, 0, height - 1);
|
||||
g.drawLine(width - 1, 0, width - 1, height - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets(Component c) {
|
||||
return new Insets(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBorderOpaque() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
setViewportBorder(new MyVewportBorder());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,4 +110,34 @@ public class JBScrollPane extends JScrollPane {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MyVewportBorder implements Border {
|
||||
@Override
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
JViewport vp = getViewport();
|
||||
if (vp == null) return;
|
||||
|
||||
Component view = vp.getView();
|
||||
if (view == null) return;
|
||||
|
||||
Color bg = view.getBackground();
|
||||
if (bg == null) return;
|
||||
|
||||
g.setColor(bg);
|
||||
g.drawLine(0, 0, width - 1, 0);
|
||||
g.drawLine(0, height - 1, width - 1, height - 1);
|
||||
g.drawLine(0, 0, 0, height - 1);
|
||||
g.drawLine(width - 1, 0, width - 1, height - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets(Component c) {
|
||||
return new Insets(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBorderOpaque() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +59,14 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
myEmptyTextHelper = new EmptyTextHelper(this) {
|
||||
@Override
|
||||
protected boolean isEmpty() {
|
||||
return getRowCount() == 0;
|
||||
return JBTable.this.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
myExpandableItemsHandler = ExpandableItemsHandlerFactory.install(this);
|
||||
|
||||
setFillsViewportHeight(true);
|
||||
|
||||
addMouseListener(new MyMouseListener());
|
||||
getColumnModel().addColumnModelListener(new TableColumnModelListener() {
|
||||
public void columnMarginChanged(ChangeEvent e) {
|
||||
@@ -82,6 +84,10 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
boolean marker = Patches.SUN_BUG_ID_4503845; // Don't remove. It's a marker for find usages
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getRowCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
@@ -70,6 +70,12 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI {
|
||||
return new ButtonlessScrollBarUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
scrollbar.setFocusable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
@@ -195,6 +201,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI {
|
||||
private static class EmptyButton extends JButton {
|
||||
private EmptyButton() {
|
||||
setFocusable(false);
|
||||
setRequestFocusEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ProjectUtil {
|
||||
if (settings.getConfirmOpenNewProject() < 0) {
|
||||
exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.open.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe"),
|
||||
CommonBundle.getCancelButtonText()}, 1, Messages.getQuestionIcon(), new DialogWrapper.DoNotAskOption() {
|
||||
CommonBundle.getCancelButtonText()}, 1, 0, Messages.getQuestionIcon(), new DialogWrapper.DoNotAskOption() {
|
||||
public boolean isToBeShown() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class DiffStatusBar extends JPanel {
|
||||
}
|
||||
};
|
||||
setLayout(new BorderLayout());
|
||||
setBorder(BorderFactory.createCompoundBorder(IdeBorderFactory.createSimpleBorder(),
|
||||
setBorder(BorderFactory.createCompoundBorder(IdeBorderFactory.createBorder(),
|
||||
BorderFactory.createEmptyBorder(3, 20, 3, 20)));
|
||||
|
||||
add(myTextLabel, BorderLayout.WEST);
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
+2
-4
@@ -19,8 +19,6 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since Jul 27, 2010 4:06:27 PM
|
||||
@@ -39,7 +37,7 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
|
||||
}
|
||||
|
||||
@Override
|
||||
public int textWidth(@NotNull CharSequence text, int start, int end, int x) {
|
||||
return EditorUtil.textWidth(myEditor, text, start, end, Font.PLAIN, x);
|
||||
public int textWidth(@NotNull CharSequence text, int start, int end, int fontType, int x) {
|
||||
return EditorUtil.textWidth(myEditor, text, start, end, fontType, x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.ui.components.JBScrollBar;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
@@ -78,6 +79,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.plaf.ScrollBarUI;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
@@ -348,12 +350,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
myEditorComponent = new EditorComponentImpl(this);
|
||||
myScrollPane = new MyScrollPane();
|
||||
myPanel = new JPanel() {
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
if (((JComponent)getParent()).getBorder() != null) myScrollPane.setBorder(null);
|
||||
}
|
||||
};
|
||||
myPanel = new JPanel();
|
||||
|
||||
myHeaderPanel = new MyHeaderPanel();
|
||||
myVerticalScrollBar = new MyScrollBar(Adjustable.VERTICAL);
|
||||
@@ -2560,6 +2557,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return myScrollPane;
|
||||
}
|
||||
|
||||
public void setBorder(Border border) {
|
||||
myScrollPane.setBorder(border);
|
||||
}
|
||||
|
||||
public int logicalPositionToOffset(@NotNull LogicalPosition pos) {
|
||||
assertReadAccess();
|
||||
assertIsDispatchThread();
|
||||
|
||||
+7
-6
@@ -48,11 +48,12 @@ public interface EditorTextRepresentationHelper {
|
||||
* <b>Note:</b> target region is allows to contain line feeds, the width is calculated as a difference between <code>'x'</code>
|
||||
* coordinates of the last and first symbols.
|
||||
*
|
||||
* @param text target text holder
|
||||
* @param start start offset of the target text sub-sequence (inclusive)
|
||||
* @param end end offset of the target text sub-sequence (exclusive)
|
||||
* @param x <code>'x'</code> offset from the visual line start
|
||||
* @return width in pixels necessary for the target text sub-sequence representation
|
||||
* @param text target text holder
|
||||
* @param start start offset of the target text sub-sequence (inclusive)
|
||||
* @param end end offset of the target text sub-sequence (exclusive)
|
||||
* @param fontType font type used for the given substring representation
|
||||
* @param x <code>'x'</code> offset from the visual line start
|
||||
* @return width in pixels necessary for the target text sub-sequence representation
|
||||
*/
|
||||
int textWidth(@NotNull CharSequence text, int start, int end, int x);
|
||||
int textWidth(@NotNull CharSequence text, int start, int end, int fontType, int x);
|
||||
}
|
||||
|
||||
@@ -58,10 +58,14 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
}
|
||||
|
||||
public SoftWrapModelImpl(@NotNull final EditorEx editor, @NotNull SoftWrapsStorage storage, @NotNull SoftWrapPainter painter) {
|
||||
this(editor, storage, painter, new DefaultEditorTextRepresentationHelper(editor));
|
||||
}
|
||||
|
||||
public SoftWrapModelImpl(@NotNull final EditorEx editor, @NotNull SoftWrapsStorage storage, @NotNull SoftWrapPainter painter,
|
||||
EditorTextRepresentationHelper representationHelper) {
|
||||
this(
|
||||
editor, storage, painter, new DefaultSoftWrapApplianceManager(storage, editor, painter),
|
||||
new SoftWrapDataMapper(editor, storage, new DefaultEditorTextRepresentationHelper(editor)),
|
||||
new SoftWrapDocumentChangeManager(editor, storage)
|
||||
editor, storage, painter, new DefaultSoftWrapApplianceManager(storage, editor, painter, representationHelper),
|
||||
new SoftWrapDataMapper(editor, storage, representationHelper), new SoftWrapDocumentChangeManager(editor, storage)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+21
-10
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.actions.EditorActionUtil;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -103,16 +104,22 @@ public class DefaultSoftWrapApplianceManager implements SoftWrapApplianceManager
|
||||
|
||||
private final TIntHashSet myProcessedLogicalLines = new TIntHashSet();
|
||||
|
||||
private final SoftWrapsStorage myStorage;
|
||||
private final EditorEx myEditor;
|
||||
private final SoftWrapPainter myPainter;
|
||||
private final EditorTextRepresentationHelper myTextRepresentationHelper;
|
||||
private final SoftWrapsStorage myStorage;
|
||||
private final EditorEx myEditor;
|
||||
private final SoftWrapPainter myPainter;
|
||||
|
||||
private int myVisibleAreaWidth;
|
||||
|
||||
public DefaultSoftWrapApplianceManager(SoftWrapsStorage storage, EditorEx editor, SoftWrapPainter painter) {
|
||||
public DefaultSoftWrapApplianceManager(SoftWrapsStorage storage,
|
||||
EditorEx editor,
|
||||
SoftWrapPainter painter,
|
||||
EditorTextRepresentationHelper textRepresentationHelper)
|
||||
{
|
||||
myStorage = storage;
|
||||
myEditor = editor;
|
||||
myPainter = painter;
|
||||
myTextRepresentationHelper = textRepresentationHelper;
|
||||
init(editor.getDocument());
|
||||
}
|
||||
|
||||
@@ -215,10 +222,11 @@ public class DefaultSoftWrapApplianceManager implements SoftWrapApplianceManager
|
||||
// Find offsets where soft wraps should be applied for the logical line in case of no indent usage.
|
||||
int x = myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
|
||||
int prevSoftWrapOffset = start;
|
||||
CharBuffer buffer = CharBuffer.wrap(text);
|
||||
for (int i = start; i < end; i++) {
|
||||
int symbolWidth = EditorUtil.textWidth(myEditor, CharBuffer.wrap(text), i, i + 1, fontType, x);
|
||||
int symbolWidth = myTextRepresentationHelper.textWidth(buffer, i, i + 1, fontType, x);
|
||||
if (x + symbolWidth >= myVisibleAreaWidth) {
|
||||
int offset = calculateSoftWrapOffset(text, i - 1, prevSoftWrapOffset, end);
|
||||
int offset = calculateSoftWrapOffset(text, i, prevSoftWrapOffset, end);
|
||||
if (offset >= end || offset <= prevSoftWrapOffset) {
|
||||
// There is no way to insert soft wrap.
|
||||
return result;
|
||||
@@ -272,8 +280,8 @@ public class DefaultSoftWrapApplianceManager implements SoftWrapApplianceManager
|
||||
for (int i = preferred; i > min; i--) {
|
||||
char c = text[i];
|
||||
|
||||
if (i < preferred && WHITE_SPACES.contains(c)) {
|
||||
return i + 1;
|
||||
if (WHITE_SPACES.contains(c)) {
|
||||
return i < preferred ? i + 1 : i;
|
||||
}
|
||||
|
||||
// Don't wrap on the non-id symbol preceded by another non-id symbol. E.g. consider that we have a statement
|
||||
@@ -281,8 +289,11 @@ public class DefaultSoftWrapApplianceManager implements SoftWrapApplianceManager
|
||||
if (i > min + 1 && !isIdSymbol(c) && !isIdSymbol(text[i - 1])) {
|
||||
continue;
|
||||
}
|
||||
if ((i < preferred) && SPECIAL_SYMBOLS_TO_WRAP_AFTER.contains(c)) {
|
||||
return i + 1;
|
||||
if (SPECIAL_SYMBOLS_TO_WRAP_AFTER.contains(c)) {
|
||||
if (i < preferred) {
|
||||
return i + 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (SPECIAL_SYMBOLS_TO_WRAP_BEFORE.contains(c) || WHITE_SPACES.contains(c)) {
|
||||
return i;
|
||||
|
||||
+5
-4
@@ -23,6 +23,7 @@ import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -264,7 +265,7 @@ public class SoftWrapDataMapper {
|
||||
int i = CharArrayUtil.shiftBackwardUntil(text, region.getEndOffset() - 1, "\n");
|
||||
// Process multi-line folding.
|
||||
if (i >= region.getStartOffset()) {
|
||||
afterFolding.x = myTextRepresentationHelper.textWidth(text, i + 1, region.getEndOffset(), 0);
|
||||
afterFolding.x = myTextRepresentationHelper.textWidth(text, i + 1, region.getEndOffset(), Font.PLAIN, 0);
|
||||
afterFolding.logicalColumn = myTextRepresentationHelper.toVisualColumnSymbolsNumber(text, i + 1, region.getEndOffset(), 0);
|
||||
afterFolding.softWrapLinesBefore += afterFolding.softWrapLinesCurrent;
|
||||
afterFolding.softWrapLinesCurrent = 0;
|
||||
@@ -274,7 +275,7 @@ public class SoftWrapDataMapper {
|
||||
}
|
||||
// Process single-line folding
|
||||
else {
|
||||
int width = myTextRepresentationHelper.textWidth(text, region.getStartOffset(), region.getEndOffset(), context.x);
|
||||
int width = myTextRepresentationHelper.textWidth(text, region.getStartOffset(), region.getEndOffset(), Font.PLAIN, context.x);
|
||||
int logicalColumnInc = myTextRepresentationHelper.toVisualColumnSymbolsNumber(
|
||||
text, region.getStartOffset(), region.getEndOffset(), context.x
|
||||
);
|
||||
@@ -342,7 +343,7 @@ public class SoftWrapDataMapper {
|
||||
|
||||
// Update state to the offset that corresponds to the same logical line that was used last time.
|
||||
if (currentLogicalLine == lastUsedLogicalLine) {
|
||||
int width = myTextRepresentationHelper.textWidth(text, result.offset, newOffset, result.x);
|
||||
int width = myTextRepresentationHelper.textWidth(text, result.offset, newOffset, Font.PLAIN, result.x);
|
||||
int columnDiff = myTextRepresentationHelper.toVisualColumnSymbolsNumber(text, result.offset, newOffset, result.x);
|
||||
result.x += width;
|
||||
result.logicalColumn += columnDiff;
|
||||
@@ -354,7 +355,7 @@ public class SoftWrapDataMapper {
|
||||
result.logicalLine += lineDiff;
|
||||
result.visualLine += lineDiff;
|
||||
int startLineOffset = document.getLineStartOffset(currentLogicalLine);
|
||||
int newX = myTextRepresentationHelper.textWidth(text, startLineOffset, newOffset, result.x);
|
||||
int newX = myTextRepresentationHelper.textWidth(text, startLineOffset, newOffset, Font.PLAIN, result.x);
|
||||
result.visualColumn = myTextRepresentationHelper.toVisualColumnSymbolsNumber(text, startLineOffset, newOffset, 0);
|
||||
result.x = newX;
|
||||
result.logicalColumn = result.visualColumn;
|
||||
|
||||
+5
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -80,6 +81,10 @@ public class TextComponentEditor extends UserDataHolderBase implements Editor {
|
||||
return myTextComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBorder(@Nullable Border border) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SelectionModel getSelectionModel() {
|
||||
return mySelectionModel;
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.openapi.wm.impl;
|
||||
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
|
||||
public class ActivatableLineBorder implements Border {
|
||||
|
||||
private boolean active = false;
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c) {
|
||||
return new Insets(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public boolean isBorderOpaque() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
final Color lineColor = active ? UIUtil.getBorderActiveColor() : UIUtil.getBorderInactiveColor();
|
||||
g.setColor(lineColor);
|
||||
|
||||
UIUtil.drawLine(g, x + 1, y, x + width - 2, y);
|
||||
UIUtil.drawLine(g, x + 1, y + height - 1, x + width - 2, y + height - 1);
|
||||
UIUtil.drawLine(g, x, y + 1, x, y + height - 2);
|
||||
UIUtil.drawLine(g, x + width - 1, y + 1, x + width - 1, y + height - 2);
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
|
||||
}
|
||||
|
||||
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
|
||||
g.setColor(UIUtil.getBorderInactiveColor());
|
||||
g.setColor(UIUtil.getHeaderInactiveColor());
|
||||
|
||||
Insets insets = getBorderInsets(c);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public final class TitlePanel extends JPanel {
|
||||
final Rectangle sideRec = SwingUtilities.convertRectangle(mySideButtons.getParent(), mySideButtons.getBounds(), this);
|
||||
g2d.fillRect(0, STRUT, getWidth() - sideRec.width, getHeight());
|
||||
|
||||
g2d.setColor(UIUtil.getBorderInactiveColor());
|
||||
g2d.setColor(UIUtil.getHeaderInactiveColor());
|
||||
final Color buttonInnerColor = myActive ? ACTIVE_SIDE_BUTTON_BG : INACTIVE_SIDE_BUTTON_BG;
|
||||
g2d.setPaint(new GradientPaint(sideRec.x, sideRec.y, Color.white, sideRec.x, (int)sideRec.getMaxY() - 1, buttonInnerColor));
|
||||
g2d.fillRect(sideRec.x + 2, sideRec.y, sideRec.width - 2, sideRec.height);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor {
|
||||
if (!forceOpenInNewFrame && openProjects.length > 0) {
|
||||
int exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.open.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe"),
|
||||
CommonBundle.getCancelButtonText()}, 1, Messages.getQuestionIcon());
|
||||
CommonBundle.getCancelButtonText()}, 1, 0, Messages.getQuestionIcon());
|
||||
if (exitCode == 1) { // "No" option
|
||||
if (!ProjectUtil.closeProject(projectToClose != null ? projectToClose : openProjects[openProjects.length - 1])) return null;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public class EditorTextField extends JPanel implements DocumentListener, TextCom
|
||||
editor.setOneLineMode(true);
|
||||
editor.getCaretModel().moveToOffset(myDocument.getTextLength());
|
||||
if (!shouldHaveBorder()) {
|
||||
editor.getScrollPane().setBorder(null);
|
||||
editor.setBorder(null);
|
||||
}
|
||||
|
||||
if (myIsViewer) {
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.openapi.editor.impl.softwrap;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.ScrollingModel;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.lib.legacy.ClassImposteriser;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 08/04/2010
|
||||
*/
|
||||
public class DefaultSoftWrapApplianceManagerTest {
|
||||
|
||||
private static final String EDGE_MARKER = "<EDGE>";
|
||||
private static final String WRAP_MARKER = "<WRAP>";
|
||||
private static final int SOFT_WRAP_DRAWING_SIZE = 11;
|
||||
|
||||
private DefaultSoftWrapApplianceManager myManager;
|
||||
private Mockery myMockery;
|
||||
private SoftWrapsStorage myStorage;
|
||||
private EditorEx myEditor;
|
||||
private SoftWrapPainter myPainter;
|
||||
private Document myDocument;
|
||||
private ScrollingModel myScrollingModel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
myMockery = new JUnit4Mockery() {{
|
||||
setImposteriser(ClassImposteriser.INSTANCE);
|
||||
}};
|
||||
myStorage = myMockery.mock(SoftWrapsStorage.class);
|
||||
myEditor = myMockery.mock(EditorEx.class);
|
||||
myPainter = myMockery.mock(SoftWrapPainter.class);
|
||||
myDocument = myMockery.mock(Document.class);
|
||||
myScrollingModel = myMockery.mock(ScrollingModel.class);
|
||||
|
||||
myMockery.checking(new Expectations() {{
|
||||
// Editor.
|
||||
allowing(myEditor).isViewer(); will(returnValue(false));
|
||||
|
||||
// Document.
|
||||
allowing(myEditor).getDocument(); will(returnValue(myDocument));
|
||||
allowing(myDocument).addDocumentListener(with(any(DocumentListener.class)));
|
||||
allowing(myDocument).getLineNumber(with(any(int.class))); will(returnValue(0)); // Expecting to work only with single lines here.
|
||||
allowing(myDocument).getLineStartOffset(0); will(returnValue(0)); // Expecting to work only with single lines here.
|
||||
allowing(myDocument).isWritable(); will(returnValue(true));
|
||||
|
||||
// Scrolling model.
|
||||
allowing(myEditor).getScrollingModel(); will(returnValue(myScrollingModel));
|
||||
|
||||
// Storage.
|
||||
allowing(myStorage).removeAll();
|
||||
|
||||
// Soft wrap drawings.
|
||||
allowing(myPainter).getMinDrawingWidth(with(any(SoftWrapDrawingType.class))); will(returnValue(SOFT_WRAP_DRAWING_SIZE));
|
||||
}});
|
||||
|
||||
myManager = new DefaultSoftWrapApplianceManager(myStorage, myEditor, myPainter, new MockEditorTextRepresentationHelper());
|
||||
}
|
||||
|
||||
@After
|
||||
public void checkExpectations() {
|
||||
myMockery.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commaNotSeparated() {
|
||||
String document =
|
||||
"void method(String <WRAP>p1<EDGE>, String p2) {}";
|
||||
doTest(document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrapOnExceedingWhiteSpace() {
|
||||
String document =
|
||||
"void method(String p1,<WRAP><EDGE> String p2) {}";
|
||||
doTest(document);
|
||||
}
|
||||
|
||||
private void doTest(final String document) {
|
||||
final Context context = new Context(document);
|
||||
context.init();
|
||||
myMockery.checking(new Expectations() {{
|
||||
allowing(myScrollingModel).getVisibleArea(); will(returnValue(new Rectangle(0, 0, context.visualWidth, Integer.MAX_VALUE)));
|
||||
allowing(myDocument).getLineEndOffset(0); will(returnValue(context.document.length()));
|
||||
}});
|
||||
char[] documentChars = context.document.toCharArray();
|
||||
myManager.registerSoftWrapIfNecessary(documentChars, 0, documentChars.length, 0, Font.PLAIN);
|
||||
}
|
||||
|
||||
private static TextChangeImpl createSoftWrap(int offset, int indent) {
|
||||
String text = "\n" + StringUtil.join(Collections.nCopies(indent, " "), "");
|
||||
return new TextChangeImpl(text, offset, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class for parsing and initialising test data.
|
||||
* <p/>
|
||||
* <b>Note:</b> this class is line-oriented, i.e. it assumes that target document doesn't contain line feeds.
|
||||
*/
|
||||
private class Context {
|
||||
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
private final String rawDocument;
|
||||
|
||||
private String document;
|
||||
private int visualWidth;
|
||||
private int index;
|
||||
private int wrapIndex;
|
||||
private int edgeIndex;
|
||||
|
||||
Context(String rawDocument) {
|
||||
if (rawDocument.contains("\n")) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Don't expect to test multi-line documents but the one is detected: '%s'", rawDocument)
|
||||
);
|
||||
}
|
||||
this.rawDocument = rawDocument;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
wrapIndex = rawDocument.indexOf(WRAP_MARKER);
|
||||
edgeIndex = rawDocument.indexOf(EDGE_MARKER);
|
||||
while (wrapIndex >= 0 || edgeIndex >= 0) {
|
||||
if (wrapIndex >= 0 && edgeIndex >= 0) {
|
||||
if (wrapIndex < edgeIndex) {
|
||||
processWrap();
|
||||
}
|
||||
else {
|
||||
processEdge();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wrapIndex >= 0) {
|
||||
processWrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (edgeIndex >= 0) {
|
||||
processEdge();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
buffer.append(rawDocument.substring(index));
|
||||
assert visualWidth > 0;
|
||||
document = buffer.toString();
|
||||
}
|
||||
|
||||
private void processWrap() {
|
||||
buffer.append(rawDocument.substring(index, wrapIndex));
|
||||
myMockery.checking(new Expectations() {{
|
||||
one(myStorage).storeOrReplace(createSoftWrap(buffer.length(), 0));
|
||||
}});
|
||||
index = wrapIndex + WRAP_MARKER.length();
|
||||
wrapIndex = rawDocument.indexOf(WRAP_MARKER, index);
|
||||
}
|
||||
|
||||
private void processEdge() {
|
||||
if (visualWidth > 0) {
|
||||
throw new IllegalArgumentException(String.format("More than one visual edge sign found at the document '%s'", rawDocument));
|
||||
}
|
||||
buffer.append(rawDocument.substring(index, edgeIndex));
|
||||
visualWidth = (buffer.length() * MockEditorTextRepresentationHelper.DEFAULT_SPACE_SIZE_IN_PIXELS) + SOFT_WRAP_DRAWING_SIZE + 1;
|
||||
index = edgeIndex + EDGE_MARKER.length();
|
||||
edgeIndex = rawDocument.indexOf(EDGE_MARKER, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.openapi.editor.impl.softwrap;
|
||||
|
||||
import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since Aug 5, 2010 9:18:15 AM
|
||||
*/
|
||||
public class MockEditorTextRepresentationHelper implements EditorTextRepresentationHelper {
|
||||
|
||||
public static final int DEFAULT_TAB_SIZE_IN_COLUMNS = 4;
|
||||
public static final int DEFAULT_SPACE_SIZE_IN_PIXELS = 7;
|
||||
|
||||
private final int mySpaceSizeInPixels;
|
||||
private final int myTabSizeInColumns;
|
||||
|
||||
public MockEditorTextRepresentationHelper() {
|
||||
this(DEFAULT_SPACE_SIZE_IN_PIXELS, DEFAULT_TAB_SIZE_IN_COLUMNS);
|
||||
}
|
||||
|
||||
MockEditorTextRepresentationHelper(int spaceSizeInPixels, int tabSizeInColumns) {
|
||||
mySpaceSizeInPixels = spaceSizeInPixels;
|
||||
myTabSizeInColumns = tabSizeInColumns;
|
||||
}
|
||||
|
||||
public int toVisualColumnSymbolsNumber(char c, int x) {
|
||||
return toVisualColumnSymbolsNumber(new String(new char[] {c}), 0, 1, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toVisualColumnSymbolsNumber(@NotNull CharSequence text, int start, int end, int x) {
|
||||
int result = 0;
|
||||
for (int i = start; i < end; i++) {
|
||||
int width = charWidth(text.charAt(i), x);
|
||||
result += width / mySpaceSizeInPixels;
|
||||
if (width % mySpaceSizeInPixels > 0) {
|
||||
result++;
|
||||
}
|
||||
x += width;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int textWidth(@NotNull CharSequence text, int start, int end, int fontType, int x) {
|
||||
int result = 0;
|
||||
for (int i = start; i < end; i++) {
|
||||
char c = text.charAt(i);
|
||||
switch (c) {
|
||||
case '\n': result = 0; break;
|
||||
default: result += charWidth(c, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int charWidth(char c, int x) {
|
||||
if (c == '\t') {
|
||||
int tabWidth = mySpaceSizeInPixels * myTabSizeInColumns;
|
||||
int tabsNumber = x / tabWidth;
|
||||
return (tabsNumber + 1) * tabWidth - x;
|
||||
}
|
||||
else {
|
||||
return mySpaceSizeInPixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-58
@@ -5,11 +5,9 @@ import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.FoldingModelEx;
|
||||
import com.intellij.openapi.editor.ex.SoftWrapModelEx;
|
||||
import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
@@ -21,6 +19,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -207,7 +206,7 @@ public class SoftWrapDataMapperTest {
|
||||
allowing(painter).getMinDrawingWidth(SoftWrapDrawingType.AFTER_SOFT_WRAP); will(returnValue(SOFT_WRAP_DRAWING_WIDTH));
|
||||
}});
|
||||
|
||||
myRepresentationHelper = new MockEditorTextRepresentationHelper();
|
||||
myRepresentationHelper = new MockEditorTextRepresentationHelper(SPACE_SIZE, TAB_SIZE);
|
||||
|
||||
myAdjuster = new SoftWrapDataMapper(myEditor, myStorage, myRepresentationHelper/*, new MockFontTypeProvider()*/);
|
||||
}
|
||||
@@ -398,7 +397,7 @@ public class SoftWrapDataMapperTest {
|
||||
if (text.charAt(i) == '\n') {
|
||||
break;
|
||||
}
|
||||
result += myRepresentationHelper.textWidth(text, i, i + 1, 0);
|
||||
result += myRepresentationHelper.textWidth(text, i, i + 1, Font.PLAIN, 0);
|
||||
}
|
||||
result += SOFT_WRAP_DRAWING_WIDTH;
|
||||
return result;
|
||||
@@ -493,8 +492,6 @@ public class SoftWrapDataMapperTest {
|
||||
// We don't want to perform the check for logical positions that correspond to the folded space because all of them relate to
|
||||
// the same logical position of the folding start.
|
||||
if (!data.foldedSpace && !data.insideTab && !equals(data.logical, actualLogicalByVisual)) {
|
||||
//TODO den remove
|
||||
myAdjuster.visualToLogical(data.visual);
|
||||
throw new AssertionError(
|
||||
String.format("Detected unmatched logical position by visual (%s). Expected: '%s', actual: '%s'. Calculation was performed "
|
||||
+ "against soft wrap-unaware logical: '%s'",
|
||||
@@ -507,8 +504,6 @@ public class SoftWrapDataMapperTest {
|
||||
// We don't to perform the check for the data that points to soft wrap location here. The reason is that it shares offset
|
||||
// with the first document symbol after soft wrap, hence, examination always fails.
|
||||
if (!data.virtualSpace && !data.insideTab && !equals(data.logical, actualLogicalByOffset)) {
|
||||
//TODO den remove
|
||||
myAdjuster.offsetToLogicalPosition(data.offset);
|
||||
throw new AssertionError(
|
||||
String.format("Detected unmatched logical position by offset. Expected: '%s', actual: '%s'. Calculation was performed "
|
||||
+ "against offset: '%d' and soft wrap-unaware logical: '%s'",
|
||||
@@ -698,7 +693,7 @@ public class SoftWrapDataMapperTest {
|
||||
}
|
||||
else if (c == '\t') {
|
||||
int tabWidthInColumns = myRepresentationHelper.toVisualColumnSymbolsNumber(c, x);
|
||||
x += MockEditorTextRepresentationHelper.charWidth(c, x);
|
||||
x += myRepresentationHelper.charWidth(c, x);
|
||||
|
||||
// There is a possible case that single tabulation symbols is shown in more than one visual column at IntelliJ editor.
|
||||
// We store data entry only for the first tab column without 'inside tab' flag then.
|
||||
@@ -715,7 +710,7 @@ public class SoftWrapDataMapperTest {
|
||||
} else {
|
||||
logicalColumn++;
|
||||
offset++;
|
||||
x += MockEditorTextRepresentationHelper.charWidth(c, x);
|
||||
x += myRepresentationHelper.charWidth(c, x);
|
||||
foldingColumnDiff--;
|
||||
}
|
||||
return;
|
||||
@@ -748,7 +743,7 @@ public class SoftWrapDataMapperTest {
|
||||
visualColumn++;
|
||||
softWrapColumnDiff++;
|
||||
softWrapSymbolsOnCurrentVisualLine++;
|
||||
x += MockEditorTextRepresentationHelper.charWidth(c, x);
|
||||
x += myRepresentationHelper.charWidth(c, x);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -769,7 +764,7 @@ public class SoftWrapDataMapperTest {
|
||||
}
|
||||
else if (c == '\t') {
|
||||
int tabWidthInColumns = myRepresentationHelper.toVisualColumnSymbolsNumber(c, x);
|
||||
x += MockEditorTextRepresentationHelper.charWidth(c, x);
|
||||
x += myRepresentationHelper.charWidth(c, x);
|
||||
|
||||
// There is a possible case that single tabulation symbols is shown in more than one visual column at IntelliJ editor.
|
||||
// We store data entry only for the first tab column without 'inside tab' flag then.
|
||||
@@ -789,7 +784,7 @@ public class SoftWrapDataMapperTest {
|
||||
visualColumn++;
|
||||
logicalColumn++;
|
||||
offset++;
|
||||
x += MockEditorTextRepresentationHelper.charWidth(c, x);
|
||||
x += myRepresentationHelper.charWidth(c, x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,51 +833,6 @@ public class SoftWrapDataMapperTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MockEditorTextRepresentationHelper implements EditorTextRepresentationHelper {
|
||||
|
||||
public int toVisualColumnSymbolsNumber(char c, int x) {
|
||||
return toVisualColumnSymbolsNumber(new String(new char[] {c}), 0, 1, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toVisualColumnSymbolsNumber(@NotNull CharSequence text, int start, int end, int x) {
|
||||
int result = 0;
|
||||
for (int i = start; i < end; i++) {
|
||||
int width = charWidth(text.charAt(i), x);
|
||||
result += width / SPACE_SIZE;
|
||||
if (width % SPACE_SIZE > 0) {
|
||||
result++;
|
||||
}
|
||||
x += width;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int textWidth(@NotNull CharSequence text, int start, int end, int x) {
|
||||
int result = 0;
|
||||
for (int i = start; i < end; i++) {
|
||||
char c = text.charAt(i);
|
||||
switch (c) {
|
||||
case '\n': result = 0; break;
|
||||
default: result += charWidth(c, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int charWidth(char c, int x) {
|
||||
if (c == '\t') {
|
||||
int tabWidth = SPACE_SIZE * TAB_SIZE;
|
||||
int tabsNumber = x / tabWidth;
|
||||
return (tabsNumber + 1) * tabWidth - x;
|
||||
}
|
||||
else {
|
||||
return SPACE_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private static class MockFontTypeProvider implements SoftWrapDataMapper.FontTypeProvider {
|
||||
// @Override
|
||||
// public void init(int start) {
|
||||
|
||||
@@ -55,7 +55,6 @@ usage.type.new=New instance creation
|
||||
usage.type.annotation=Annotation
|
||||
usage.type.read=Value read
|
||||
usage.type.write=Value write
|
||||
preview.title=<html>\\ \\ \\ Preview\\ <b>{0}</b>:\\ <br><br>
|
||||
preview.usages.action.text=Preview Usages
|
||||
select.the.usage.to.preview=Select the usage to preview
|
||||
usages.were.filtered.out={0,choice, 1#The usage was|2#{0,number} usages were} filtered out
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewBundle;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -45,13 +47,12 @@ public class UsagePreviewPanel extends JPanel implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.usages.impl.UsagePreviewPanel");
|
||||
private Editor myEditor;
|
||||
private final Project myProject;
|
||||
private String myTitle;
|
||||
private volatile boolean isDisposed = false;
|
||||
|
||||
public UsagePreviewPanel(final Project project) {
|
||||
myProject = project;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
setBorder(IdeBorderFactory.createBorder());
|
||||
}
|
||||
|
||||
private void resetEditor(@NotNull final List<UsageInfo> infos) {
|
||||
@@ -69,15 +70,12 @@ public class UsagePreviewPanel extends JPanel implements Disposable {
|
||||
|
||||
final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
|
||||
if (document == null) return;
|
||||
final String title = UsageViewBundle.message("preview.title", psiFile.getName());
|
||||
if (myEditor == null || document != myEditor.getDocument() || !Comparing.strEqual(title, myTitle)) {
|
||||
if (myEditor == null || document != myEditor.getDocument()) {
|
||||
releaseEditor();
|
||||
removeAll();
|
||||
myEditor = createEditor(psiFile, document);
|
||||
if (myEditor == null) return;
|
||||
myTitle = title;
|
||||
JComponent titleComp = new JLabel(myTitle);
|
||||
add(titleComp, BorderLayout.NORTH);
|
||||
myEditor.setBorder(null);
|
||||
add(myEditor.getComponent(), BorderLayout.CENTER);
|
||||
|
||||
revalidate();
|
||||
@@ -178,7 +176,6 @@ public class UsagePreviewPanel extends JPanel implements Disposable {
|
||||
if (myProject.isDisposed()) return;
|
||||
if (infos == null) {
|
||||
releaseEditor();
|
||||
myTitle = null;
|
||||
removeAll();
|
||||
JComponent titleComp = new JLabel(UsageViewBundle.message("select.the.usage.to.preview"));
|
||||
add(titleComp, BorderLayout.CENTER);
|
||||
|
||||
@@ -37,9 +37,7 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.ui.PopupHandler;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.SmartExpander;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
@@ -234,16 +232,21 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
Disposer.dispose(myUsagePreviewPanel);
|
||||
myUsagePreviewPanel = null;
|
||||
}
|
||||
JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
|
||||
|
||||
if (UsageViewSettings.getInstance().IS_PREVIEW_USAGES) {
|
||||
Splitter splitter = new Splitter(false, UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS);
|
||||
splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree));
|
||||
pane.putClientProperty(UIUtil.KEEP_BORDER_SIDES, SideBorder.RIGHT);
|
||||
|
||||
splitter.setFirstComponent(pane);
|
||||
myUsagePreviewPanel = new UsagePreviewPanel(myProject);
|
||||
myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
|
||||
Disposer.register(this, myUsagePreviewPanel);
|
||||
splitter.setSecondComponent(myUsagePreviewPanel);
|
||||
myCentralPanel.add(splitter, BorderLayout.CENTER);
|
||||
}
|
||||
else {
|
||||
myCentralPanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
|
||||
myCentralPanel.add(pane, BorderLayout.CENTER);
|
||||
}
|
||||
myCentralPanel.add(myButtonPanel, BorderLayout.SOUTH);
|
||||
|
||||
@@ -1212,6 +1215,8 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
}
|
||||
|
||||
public void add(int index, final Runnable runnable, String text) {
|
||||
if (getBorder() == null) setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
|
||||
|
||||
final JButton button = new JButton(UIUtil.replaceMnemonicAmpersand(text));
|
||||
DialogUtil.registerMnemonic(button);
|
||||
|
||||
|
||||
@@ -63,9 +63,11 @@ public class UIUtil {
|
||||
|
||||
private static final Color UNFOCUSED_SELECTION_COLOR = new Color(212, 212, 212);
|
||||
|
||||
private static final Color ACTIVE_COLOR = new Color(160, 186, 213);
|
||||
private static final Color INACTIVE_COLOR = new Color(128, 128, 128);
|
||||
private static final Color SEPARATOR_COLOR = INACTIVE_COLOR.brighter();
|
||||
private static final Color ACTIVE_HEADER_COLOR = new Color(160, 186, 213);
|
||||
private static final Color INACTIVE_HEADER_COLOR = new Color(128, 128, 128);
|
||||
|
||||
private static final Color BORDER_COLOR = new Color(170, 170, 170);
|
||||
|
||||
public static final Pattern CLOSE_TAG_PATTERN = Pattern.compile("<\\s*([^<>/ ]+)([^<>]*)/\\s*>", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@NonNls public static final String FOCUS_PROXY_KEY = "isFocusProxy";
|
||||
@@ -97,7 +99,7 @@ public class UIUtil {
|
||||
final FontRenderContext frc = g.getFontRenderContext();
|
||||
final Rectangle stringBounds = font.getStringBounds(string, frc).getBounds();
|
||||
|
||||
return (int) (centerY - stringBounds.height / 2.0 - stringBounds.y);
|
||||
return (int)(centerY - stringBounds.height / 2.0 - stringBounds.y);
|
||||
}
|
||||
|
||||
public static void setEnabled(Component component, boolean enabled, boolean recursively) {
|
||||
@@ -118,12 +120,12 @@ public class UIUtil {
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public static String[] splitText(String text, FontMetrics fontMetrics, int widthLimit, char separator){
|
||||
public static String[] splitText(String text, FontMetrics fontMetrics, int widthLimit, char separator) {
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
String currentLine = "";
|
||||
StringBuffer currentAtom = new StringBuffer();
|
||||
|
||||
for (int i=0; i < text.length(); i++) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char ch = text.charAt(i);
|
||||
currentAtom.append(ch);
|
||||
|
||||
@@ -679,13 +681,14 @@ public class UIUtil {
|
||||
|
||||
/**
|
||||
* Should be invoked only in EDT.
|
||||
* @param g Graphics surface
|
||||
* @param startX Line start X coordinate
|
||||
* @param endX Line end X coordinate
|
||||
* @param lineY Line Y coordinate
|
||||
*
|
||||
* @param g Graphics surface
|
||||
* @param startX Line start X coordinate
|
||||
* @param endX Line end X coordinate
|
||||
* @param lineY Line Y coordinate
|
||||
* @param bgColor Background color (optional)
|
||||
* @param fgColor Foreground color (optional)
|
||||
* @param opaque If opaque the image will be dr
|
||||
* @param opaque If opaque the image will be dr
|
||||
*/
|
||||
public static void drawBoldDottedLine(final Graphics2D g,
|
||||
final int startX,
|
||||
@@ -694,11 +697,12 @@ public class UIUtil {
|
||||
final Color bgColor,
|
||||
final Color fgColor,
|
||||
final boolean opaque) {
|
||||
if (SystemInfo.isMac || SystemInfo.isLinux) {
|
||||
drawAppleDottedLine(g, startX, endX, lineY, bgColor, fgColor, opaque);
|
||||
} else {
|
||||
drawBoringDottedLine(g, startX, endX, lineY, bgColor, fgColor, opaque);
|
||||
}
|
||||
if (SystemInfo.isMac || SystemInfo.isLinux) {
|
||||
drawAppleDottedLine(g, startX, endX, lineY, bgColor, fgColor, opaque);
|
||||
}
|
||||
else {
|
||||
drawBoringDottedLine(g, startX, endX, lineY, bgColor, fgColor, opaque);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawBoringDottedLine(final Graphics2D g,
|
||||
@@ -715,7 +719,7 @@ public class UIUtil {
|
||||
g.setColor(bgColor);
|
||||
|
||||
drawLine(g, startX, lineY, endX, lineY);
|
||||
drawLine(g, startX, lineY+1, endX, lineY+1);
|
||||
drawLine(g, startX, lineY + 1, endX, lineY + 1);
|
||||
}
|
||||
|
||||
// Draw dotted line:
|
||||
@@ -753,8 +757,8 @@ public class UIUtil {
|
||||
g.setColor(bgColor);
|
||||
|
||||
drawLine(g, startX, lineY, endX, lineY);
|
||||
drawLine(g, startX, lineY+1, endX, lineY+1);
|
||||
drawLine(g, startX, lineY+2, endX, lineY+2);
|
||||
drawLine(g, startX, lineY + 1, endX, lineY + 1);
|
||||
drawLine(g, startX, lineY + 2, endX, lineY + 2);
|
||||
}
|
||||
|
||||
// Draw apple like dotted line:
|
||||
@@ -781,7 +785,7 @@ public class UIUtil {
|
||||
final BufferedImage image = getAppleDotStamp(fgColor, oldColor);
|
||||
|
||||
// Now copy our dot several times
|
||||
final int dotX0 = (startX / step + startPosCorrection) * step;
|
||||
final int dotX0 = (startX / step + startPosCorrection) * step;
|
||||
for (int dotXi = dotX0; dotXi < endX; dotXi += step) {
|
||||
g.drawImage(image, dotXi, lineY, null);
|
||||
}
|
||||
@@ -831,7 +835,7 @@ public class UIUtil {
|
||||
|
||||
// dispose graphics
|
||||
g.dispose();
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -953,15 +957,13 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static
|
||||
Color getBgFillColor(@NotNull JComponent c) {
|
||||
public static Color getBgFillColor(@NotNull JComponent c) {
|
||||
final Component parent = findNearestOpaque(c);
|
||||
return parent == null ? c.getBackground() : parent.getBackground();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static
|
||||
Component findNearestOpaque(JComponent c) {
|
||||
public static Component findNearestOpaque(JComponent c) {
|
||||
Component eachParent = c;
|
||||
while (eachParent != null) {
|
||||
if (eachParent.isOpaque()) return eachParent;
|
||||
@@ -981,7 +983,9 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
public static boolean isStandardMenuLAF() {
|
||||
return isWinLafOnVista() || "Nimbus".equals(UIManager.getLookAndFeel().getName()) || "GTK look and feel".equals(UIManager.getLookAndFeel().getName());
|
||||
return isWinLafOnVista() ||
|
||||
"Nimbus".equals(UIManager.getLookAndFeel().getName()) ||
|
||||
"GTK look and feel".equals(UIManager.getLookAndFeel().getName());
|
||||
}
|
||||
|
||||
public static Color getFocusedFillColor() {
|
||||
@@ -993,7 +997,7 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
public static Color getBoundsColor() {
|
||||
return new Color(128, 128, 128);
|
||||
return getBorderColor();
|
||||
}
|
||||
|
||||
public static Color getBoundsColor(boolean focused) {
|
||||
@@ -1019,6 +1023,7 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
//todo maybe should do for all kind of listeners via the AWTEventMulticaster class
|
||||
|
||||
public static void dispose(final Component c) {
|
||||
if (c == null) return;
|
||||
|
||||
@@ -1051,7 +1056,7 @@ public class UIUtil {
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isToDispose(final JProgressBar progress) {
|
||||
private static boolean isToDispose(final JProgressBar progress) {
|
||||
final ProgressBarUI ui = progress.getUI();
|
||||
|
||||
if (ui == null) return false;
|
||||
@@ -1115,16 +1120,37 @@ public class UIUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Color getBorderActiveColor() {
|
||||
return ACTIVE_COLOR;
|
||||
public static Color getHeaderActiveColor() {
|
||||
return ACTIVE_HEADER_COLOR;
|
||||
}
|
||||
|
||||
public static Color getHeaderInactiveColor() {
|
||||
return INACTIVE_HEADER_COLOR;
|
||||
}
|
||||
|
||||
public static Color getBorderColor() {
|
||||
return BORDER_COLOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getBorderColor instead
|
||||
*/
|
||||
public static Color getBorderInactiveColor() {
|
||||
return INACTIVE_COLOR;
|
||||
return getBorderColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getBorderColor instead
|
||||
*/
|
||||
public static Color getBorderActiveColor() {
|
||||
return getBorderColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getBorderColor instead
|
||||
*/
|
||||
public static Color getBorderSeparatorColor() {
|
||||
return SEPARATOR_COLOR;
|
||||
return getBorderColor();
|
||||
}
|
||||
|
||||
public static HTMLEditorKit getHTMLEditorKit() {
|
||||
@@ -1147,10 +1173,10 @@ public class UIUtil {
|
||||
if (component instanceof JScrollPane) {
|
||||
if (!hasNonPrimitiveParents(c, component)) {
|
||||
final JScrollPane scrollPane = (JScrollPane)component;
|
||||
Integer keepBorderSides = (Integer) scrollPane.getClientProperty(KEEP_BORDER_SIDES);
|
||||
Integer keepBorderSides = (Integer)scrollPane.getClientProperty(KEEP_BORDER_SIDES);
|
||||
if (keepBorderSides != null) {
|
||||
if (scrollPane.getBorder() instanceof LineBorder) {
|
||||
Color color = ((LineBorder) scrollPane.getBorder()).getLineColor();
|
||||
Color color = ((LineBorder)scrollPane.getBorder()).getLineColor();
|
||||
scrollPane.setBorder(new SideBorder(color, keepBorderSides.intValue()));
|
||||
}
|
||||
else {
|
||||
@@ -1219,7 +1245,8 @@ public class UIUtil {
|
||||
public static void invokeLaterIfNeeded(@NotNull Runnable runnable) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SwingUtilities.invokeLater(runnable);
|
||||
}
|
||||
}
|
||||
@@ -1234,7 +1261,8 @@ public class UIUtil {
|
||||
public static void invokeAndWaitIfNeeded(@NotNull Runnable runnable) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
}
|
||||
@@ -1261,14 +1289,15 @@ public class UIUtil {
|
||||
public static class MacTreeUI extends BasicTreeUI {
|
||||
public static final String SOURCE_LIST_CLIENT_PROPERTY = "mac.ui.source.list";
|
||||
|
||||
private static final Icon TREE_COLLAPSED_ICON = (Icon) UIManager.get("Tree.collapsedIcon");
|
||||
private static final Icon TREE_EXPANDED_ICON = (Icon) UIManager.get("Tree.expandedIcon");
|
||||
private static final Icon TREE_COLLAPSED_ICON = (Icon)UIManager.get("Tree.collapsedIcon");
|
||||
private static final Icon TREE_EXPANDED_ICON = (Icon)UIManager.get("Tree.expandedIcon");
|
||||
private static final Icon TREE_SELECTED_COLLAPSED_ICON = IconLoader.getIcon("/mac/tree_white_right_arrow.png");
|
||||
private static final Icon TREE_SELECTED_EXPANDED_ICON = IconLoader.getIcon("/mac/tree_white_down_arrow.png");
|
||||
|
||||
private static final Border LIST_BACKGROUND_PAINTER = (Border) UIManager.get("List.sourceListBackgroundPainter");
|
||||
private static final Border LIST_SELECTION_BACKGROUND_PAINTER = (Border) UIManager.get("List.sourceListSelectionBackgroundPainter");
|
||||
private static final Border LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER = (Border) UIManager.get("List.sourceListFocusedSelectionBackgroundPainter");
|
||||
private static final Border LIST_BACKGROUND_PAINTER = (Border)UIManager.get("List.sourceListBackgroundPainter");
|
||||
private static final Border LIST_SELECTION_BACKGROUND_PAINTER = (Border)UIManager.get("List.sourceListSelectionBackgroundPainter");
|
||||
private static final Border LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER =
|
||||
(Border)UIManager.get("List.sourceListFocusedSelectionBackgroundPainter");
|
||||
|
||||
private boolean myWideSelection;
|
||||
private boolean myOldRepaintAllRowValue;
|
||||
@@ -1285,22 +1314,22 @@ public class UIUtil {
|
||||
private MouseListener mySelectionListener = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(@NotNull final MouseEvent e) {
|
||||
final JTree tree = (JTree) e.getSource();
|
||||
final JTree tree = (JTree)e.getSource();
|
||||
if (SwingUtilities.isLeftMouseButton(e) && !e.isPopupTrigger()) {
|
||||
// if we can't stop any ongoing editing, do nothing
|
||||
if (isEditing(tree) && tree.getInvokesStopCellEditing()
|
||||
&& !stopEditing(tree)) {
|
||||
return;
|
||||
&& !stopEditing(tree)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final TreePath pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());
|
||||
if (tree.isPathSelected(pressedPath)) return;
|
||||
|
||||
if (pressedPath != null) {
|
||||
Rectangle bounds = getPathBounds(tree, pressedPath);
|
||||
|
||||
if(e.getY() >= (bounds.y + bounds.height)) {
|
||||
return;
|
||||
if (e.getY() >= (bounds.y + bounds.height)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLocationInExpandControl(pressedPath, e.getX(), e.getY())) {
|
||||
@@ -1308,7 +1337,7 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
if (tree.getDragEnabled() || !startEditing(pressedPath, e)) {
|
||||
selectPathForEvent(pressedPath, e);
|
||||
selectPathForEvent(pressedPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1425,11 +1454,13 @@ public class UIUtil {
|
||||
else {
|
||||
LIST_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
rowGraphics.setColor(tree.getBackground());
|
||||
rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Color bg = tree.hasFocus() ? getTreeSelectionBackground() : getListUnfocusedSelectionBackground();
|
||||
if (!selected) {
|
||||
bg = tree.getBackground();
|
||||
@@ -1445,7 +1476,8 @@ public class UIUtil {
|
||||
|
||||
super.paintRow(rowGraphics, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
|
||||
rowGraphics.dispose();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
|
||||
}
|
||||
}
|
||||
@@ -1497,9 +1529,9 @@ public class UIUtil {
|
||||
boolean isPathSelected = tree.getSelectionModel().isPathSelected(path);
|
||||
|
||||
Icon expandIcon = isPathSelected && tree.hasFocus() ? TREE_SELECTED_EXPANDED_ICON
|
||||
: TREE_EXPANDED_ICON;
|
||||
: TREE_EXPANDED_ICON;
|
||||
Icon collapseIcon = isPathSelected && tree.hasFocus() ? TREE_SELECTED_COLLAPSED_ICON
|
||||
: TREE_COLLAPSED_ICON;
|
||||
: TREE_COLLAPSED_ICON;
|
||||
|
||||
|
||||
if (!isLeaf(row)) {
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ import java.util.List;
|
||||
* @author yole
|
||||
*/
|
||||
public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataProvider, Disposable, DecoratorManager {
|
||||
private static final Border RIGHT_BORDER = IdeBorderFactory.createSimpleBorder(1, 1, 0, 0);
|
||||
private static final Border RIGHT_BORDER = IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.LEFT);
|
||||
|
||||
private final Project myProject;
|
||||
private final Tree myChangesTree;
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.openapi.ui.ThreeComponentsSplitter;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SideBorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
@@ -28,8 +29,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WiseSplitter implements Disposable {
|
||||
private static final Border LEFT_BORDER = IdeBorderFactory.createSimpleBorder(1, 0, 0, 1);
|
||||
private static final Border MIDDLE_BORDER = IdeBorderFactory.createSimpleBorder(1, 1, 0, 1);
|
||||
private static final Border LEFT_BORDER = IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.RIGHT);
|
||||
private static final Border MIDDLE_BORDER = IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.LEFT | SideBorder.RIGHT);
|
||||
|
||||
private final Runnable myRefresher;
|
||||
private final Splitter myParentSplitter;
|
||||
|
||||
@@ -651,7 +651,7 @@ public class FileHistoryPanelImpl<S extends CommittedChangeList, U extends Chang
|
||||
};
|
||||
commentGroup.add(commentLabel, BorderLayout.NORTH);
|
||||
JScrollPane pane = ScrollPaneFactory.createScrollPane(myComments);
|
||||
pane.setBorder(IdeBorderFactory.createSimpleBorder(1, 1, myAdditionalDetails == null ? 0 : 1, 0));
|
||||
pane.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.LEFT | (myAdditionalDetails == null ? 0 : SideBorder.BOTTOM)));
|
||||
|
||||
commentGroup.add(pane, BorderLayout.CENTER);
|
||||
detailsSplitter.setFirstComponent(commentGroup);
|
||||
@@ -663,7 +663,7 @@ public class FileHistoryPanelImpl<S extends CommittedChangeList, U extends Chang
|
||||
myLoadingLabel.setBackground(UIUtil.getToolTipBackground());
|
||||
wrapper.add(myLoadingLabel, BorderLayout.NORTH);
|
||||
|
||||
myDualView.setViewBorder(IdeBorderFactory.createSimpleBorder(0, 1, 1, 0));
|
||||
myDualView.setViewBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.BOTTOM));
|
||||
wrapper.add(myDualView, BorderLayout.CENTER);
|
||||
|
||||
mySplitter.setFirstComponent(wrapper);
|
||||
|
||||
@@ -22,8 +22,8 @@ contributor([gdslScriptContext]) {
|
||||
method name: "contributor", params: [contexts: "java.util.Map", body: {}], type: void
|
||||
method name: "contributor", params: [contexts: "java.lang.Object", body: {}], type: void
|
||||
|
||||
method name: "category", params: [categoryClass: "java.lang.String", isStatic:"java.lang.Boolean", body: {}], type: void
|
||||
method name: "category", params: [categoryClass: "java.lang.String", body: {}], type: void
|
||||
method name: "category", params: [categoryClass: "java.lang.String", isStatic:"java.lang.Boolean"], type: void
|
||||
method name: "category", params: [categoryClass: "java.lang.String"], type: void
|
||||
|
||||
method name: "supportsVersion", params: [version: "java.lang.String"], type: boolean
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.plugins.groovy.dsl;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import groovy.lang.Closure;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.dsl.holders.CompoundMembersHolder;
|
||||
@@ -60,6 +61,11 @@ public class CustomMembersGenerator implements GdslMembersHolderConsumer {
|
||||
return JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, myDescriptor.getResolveScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return myDescriptor.getResolveScope();
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.dsl.holders.CustomMembersHolder;
|
||||
|
||||
@@ -34,4 +35,6 @@ public interface GdslMembersHolderConsumer {
|
||||
PsiType getPsiType();
|
||||
@Nullable
|
||||
PsiClass getPsiClass();
|
||||
|
||||
GlobalSearchScope getResolveScope();
|
||||
}
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 org.jetbrains.plugins.groovy.dsl.toplevel;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class CategoryMethodProvider {
|
||||
private static final Key<CachedValue<MultiMap<String, PsiMethod>>> METHOD_KEY = Key.create("Category methods");
|
||||
|
||||
private CategoryMethodProvider() {
|
||||
}
|
||||
|
||||
public static List<PsiMethod> provideMethods(@NotNull PsiType psiType,
|
||||
final Project project,
|
||||
String className,
|
||||
GlobalSearchScope scope,
|
||||
final Function<PsiMethod, PsiMethod> converter) {
|
||||
final PsiClass categoryClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
|
||||
if (categoryClass == null) return Collections.emptyList();
|
||||
final MultiMap<String, PsiMethod> map = CachedValuesManager.getManager(project)
|
||||
.getCachedValue(categoryClass, METHOD_KEY, new CachedValueProvider<MultiMap<String, PsiMethod>>() {
|
||||
@Override
|
||||
public Result<MultiMap<String, PsiMethod>> compute() {
|
||||
MultiMap<String, PsiMethod> map = new MultiMap<String, PsiMethod>();
|
||||
for (PsiMethod m : categoryClass.getMethods()) {
|
||||
final PsiParameter[] params = m.getParameterList().getParameters();
|
||||
if (params.length == 0) continue;
|
||||
final PsiType parameterType = params[0].getType();
|
||||
PsiType targetType = TypeConversionUtil.erasure(parameterType);
|
||||
map.putValue(targetType.getCanonicalText(), converter.fun(m));
|
||||
}
|
||||
return Result.create(map, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
|
||||
}
|
||||
}, false);
|
||||
Set<String> superTypes = ResolveUtil.getAllSuperTypes(psiType, project).keySet();
|
||||
List<PsiMethod> result = new ArrayList<PsiMethod>();
|
||||
for (String superType : superTypes) {
|
||||
result.addAll(map.get(superType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+2
-41
@@ -7,17 +7,7 @@ import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.AnnotatedScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClassScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClosureScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ScriptScope
|
||||
import com.intellij.psi.util.TypeConversionUtil
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValueProvider.Result
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrGdkMethodImpl
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.util.Function
|
||||
|
||||
@@ -73,41 +63,12 @@ class GdslMetaClassProperties {
|
||||
private def processCategoryMethods (def className, Function<PsiMethod, PsiMethod> converter) {
|
||||
contributor(context()) {
|
||||
if (!psiType) return;
|
||||
|
||||
def categoryClass = findClass(className)
|
||||
if (!categoryClass) return;
|
||||
categoryClass.methods.each {m ->
|
||||
def params = m.parameterList.parameters
|
||||
if (!params) return;
|
||||
def targetType = TypeConversionUtil.erasure(params[0].type)
|
||||
if (!ResolveUtil.isInheritor(psiType, targetType.getCanonicalText(), project)) return;
|
||||
|
||||
add CachedValuesManager.getManager(project).
|
||||
getCachedValue(m, CategoryMethodProvider.CATEGORY_METHOD, new CategoryMethodProvider(m, converter), false)
|
||||
}
|
||||
List methods = CategoryMethodProvider.provideMethods(psiType, project, className, resolveScope, converter)
|
||||
for (m in methods) add m
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class CategoryMethodProvider implements CachedValueProvider<GrGdkMethod> {
|
||||
static final Key<CachedValue<GrGdkMethod>> CATEGORY_METHOD = Key.create("category method");
|
||||
|
||||
def method
|
||||
def converter
|
||||
|
||||
def CategoryMethodProvider(def method, def converter) {
|
||||
this.method = method;
|
||||
this.converter = converter
|
||||
}
|
||||
|
||||
Result<GrGdkMethod> compute() {
|
||||
return Result.create(
|
||||
converter.fun(method),
|
||||
PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT,
|
||||
ProjectRootManager.getInstance(method.project));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary methods for context definition
|
||||
*/
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class ConstructorReferencesSearcher extends QueryExecutorBase<PsiReferenc
|
||||
if (element instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)element;
|
||||
if (method.isConstructor()) {
|
||||
GroovyConstructorUsagesSearcher.processConstructorUsages(method, queryParameters.getScope(), consumer, queryParameters.getOptimizer(), true);
|
||||
GroovyConstructorUsagesSearcher.processConstructorUsages(method, queryParameters.getScope(), consumer, queryParameters.getOptimizer(), true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-15
@@ -80,10 +80,10 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
|
||||
@Override
|
||||
public void processQuery(MethodReferencesSearch.SearchParameters p, Processor<PsiReference> consumer) {
|
||||
processConstructorUsages(p.getMethod(), p.getScope(), consumer, p.getOptimizer(), true);
|
||||
processConstructorUsages(p.getMethod(), p.getScope(), consumer, p.getOptimizer(), true, !p.isStrictSignatureSearch());
|
||||
}
|
||||
|
||||
static void processConstructorUsages(final PsiMethod constructor, final SearchScope searchScope, final Processor<PsiReference> consumer, final SearchRequestCollector collector, final boolean searchGppCalls) {
|
||||
static void processConstructorUsages(final PsiMethod constructor, final SearchScope searchScope, final Processor<PsiReference> consumer, final SearchRequestCollector collector, final boolean searchGppCalls, final boolean includeOverloads) {
|
||||
if (!constructor.isConstructor()) return;
|
||||
|
||||
SearchScope onlyGroovy = PsiUtil.restrictScopeToGroovyFiles(searchScope);
|
||||
@@ -103,13 +103,13 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
}
|
||||
}
|
||||
|
||||
final LiteralConstructorSearcher literalProcessor = new LiteralConstructorSearcher(constructor, consumer);
|
||||
final LiteralConstructorSearcher literalProcessor = new LiteralConstructorSearcher(constructor, consumer, includeOverloads);
|
||||
|
||||
final Processor<GrNewExpression> newExpressionProcessor = new Processor<GrNewExpression>() {
|
||||
@Override
|
||||
public boolean process(GrNewExpression grNewExpression) {
|
||||
final PsiMethod resolvedConstructor = grNewExpression.resolveConstructor();
|
||||
if (constructor.getManager().areElementsEquivalent(resolvedConstructor, constructor)) {
|
||||
if (includeOverloads || constructor.getManager().areElementsEquivalent(resolvedConstructor, constructor)) {
|
||||
return consumer.process(grNewExpression.getReferenceElement());
|
||||
}
|
||||
return true;
|
||||
@@ -217,7 +217,7 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
for (PsiType psiType : GroovyExpectedTypesProvider.getDefaultExpectedTypes(argument)) {
|
||||
if (psiType instanceof PsiClassType &&
|
||||
targetClass.getManager().areElementsEquivalent(targetClass, ((PsiClassType)psiType).resolve()) &&
|
||||
!literalProcessor.processLiteral((GrListOrMap)argument, (PsiClassType)psiType)) {
|
||||
!literalProcessor.processLiteral((GrListOrMap)argument)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
}
|
||||
};
|
||||
if (currentTarget.isConstructor()) {
|
||||
processConstructorUsages(currentTarget, gppScope, gppCallProcessor, originalCollector, false);
|
||||
processConstructorUsages(currentTarget, gppScope, gppCallProcessor, originalCollector, false, false);
|
||||
}
|
||||
else {
|
||||
MethodReferencesSearch.searchOptimized(currentTarget, gppScope, true, originalCollector, gppCallProcessor);
|
||||
@@ -271,7 +271,7 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
final GrVariable[] vars = ((GrVariableDeclaration)grandpa).getVariables();
|
||||
if (vars.length == 1) {
|
||||
final GrVariable variable = vars[0];
|
||||
if (!checkLiteralInstantiation(variable.getInitializerGroovy(), typeElement, literalProcessor)) {
|
||||
if (!checkLiteralInstantiation(variable.getInitializerGroovy(), literalProcessor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
ControlFlowUtils.visitAllExitPoints(method.getBlock(), new ControlFlowUtils.ExitPointVisitor() {
|
||||
@Override
|
||||
public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
|
||||
if (!checkLiteralInstantiation(returnValue, typeElement, literalProcessor)) {
|
||||
if (!checkLiteralInstantiation(returnValue, literalProcessor)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -293,14 +293,14 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
else if (grandpa instanceof GrTypeCastExpression) {
|
||||
final GrTypeCastExpression cast = (GrTypeCastExpression)grandpa;
|
||||
if (cast.getCastTypeElement() == typeElement &&
|
||||
!checkLiteralInstantiation(cast.getOperand(), typeElement, literalProcessor)) {
|
||||
!checkLiteralInstantiation(cast.getOperand(), literalProcessor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (grandpa instanceof GrSafeCastExpression) {
|
||||
final GrSafeCastExpression cast = (GrSafeCastExpression)grandpa;
|
||||
if (cast.getCastTypeElement() == typeElement &&
|
||||
!checkLiteralInstantiation(cast.getOperand(), typeElement, literalProcessor)) {
|
||||
!checkLiteralInstantiation(cast.getOperand(), literalProcessor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -336,14 +336,10 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase<PsiRefere
|
||||
}
|
||||
|
||||
private static boolean checkLiteralInstantiation(GrExpression expression,
|
||||
final GrTypeElement typeElement,
|
||||
final LiteralConstructorSearcher literalProcessor) {
|
||||
|
||||
if (expression instanceof GrListOrMap) {
|
||||
final PsiType expectedType = typeElement.getType();
|
||||
if (expectedType instanceof PsiClassType) {
|
||||
return literalProcessor.processLiteral((GrListOrMap)expression, (PsiClassType)expectedType);
|
||||
}
|
||||
return literalProcessor.processLiteral((GrListOrMap)expression);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package org.jetbrains.plugins.groovy.findUsages;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.expectedTypes.GroovyExpectedTypesProvider;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class LiteralConstructorReference extends PsiReferenceBase.Poly<GrListOrMap> {
|
||||
private final PsiClassType myConstructedClass;
|
||||
|
||||
public LiteralConstructorReference(@NotNull GrListOrMap element, @NotNull PsiClassType constructedClassType) {
|
||||
super(element, TextRange.from(0, 0), false);
|
||||
myConstructedClass = constructedClassType;
|
||||
}
|
||||
|
||||
private static boolean isConstructorCall(PsiClassType expectedType,
|
||||
@Nullable PsiType[] argTypes,
|
||||
PsiMethod constructor,
|
||||
GroovyPsiElement context) {
|
||||
for (GroovyResolveResult candidate : PsiUtil.getConstructorCandidates(expectedType, argTypes, context)) {
|
||||
if (constructor.getManager().areElementsEquivalent(candidate.getElement(), constructor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<ResolveResult> getConstructorCandidates(PsiClassType classType,
|
||||
@NotNull GroovyPsiElement context, @Nullable PsiType[] argTypes) {
|
||||
PsiClass psiClass = classType.resolve();
|
||||
if (psiClass == null) return Collections.emptyList();
|
||||
|
||||
List<ResolveResult> applicable = CollectionFactory.arrayList();
|
||||
final List<ResolveResult> byName = CollectionFactory.arrayList();
|
||||
for (PsiMethod constructor : psiClass.getConstructors()) {
|
||||
final ResolveResult resolveResult = new PsiElementResolveResult(constructor);
|
||||
byName.add(resolveResult);
|
||||
if (argTypes != null && isConstructorCall(classType, argTypes, constructor, context)) {
|
||||
applicable.add(resolveResult);
|
||||
}
|
||||
}
|
||||
if (applicable.isEmpty()) {
|
||||
applicable.addAll(byName);
|
||||
}
|
||||
return applicable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiClassType getTargetConversionType(@NotNull GrExpression expression) {
|
||||
//todo hack
|
||||
if (expression.getParent() instanceof GrSafeCastExpression) {
|
||||
final PsiType type = ((GrSafeCastExpression)expression.getParent()).getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
return (PsiClassType)type;
|
||||
}
|
||||
}
|
||||
if (expression.getParent() instanceof GrTypeCastExpression) {
|
||||
final PsiType type = ((GrTypeCastExpression)expression.getParent()).getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
return (PsiClassType)type;
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiType type : GroovyExpectedTypesProvider.getDefaultExpectedTypes(expression)) {
|
||||
if (type instanceof PsiClassType) {
|
||||
return (PsiClassType)type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiType[] argTypes() {
|
||||
final GrListOrMap literal = getElement();
|
||||
final PsiType listType = literal.getType();
|
||||
if (listType instanceof GrTupleType) {
|
||||
return ((GrTupleType)listType).getComponentTypes();
|
||||
}
|
||||
else if (listType instanceof GrMapType) {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final GrListOrMap literal = getElement();
|
||||
final GrNamedArgument superConstructor = literal.findNamedArgument("super");
|
||||
if (superConstructor != null) {
|
||||
final PsiReference reference = ObjectUtils.assertNotNull(superConstructor.getLabel()).getReference();
|
||||
if (reference instanceof PsiPolyVariantReference) {
|
||||
return ((PsiPolyVariantReference)reference).multiResolve(incompleteCode);
|
||||
}
|
||||
}
|
||||
|
||||
final List<ResolveResult> candidates = getConstructorCandidates(myConstructedClass, literal, argTypes());
|
||||
return candidates.toArray(new ResolveResult[candidates.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
+17
-43
@@ -1,14 +1,12 @@
|
||||
package org.jetbrains.plugins.groovy.findUsages;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.plugins.groovy.gpp.GppReferenceContributor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -16,53 +14,29 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
public class LiteralConstructorSearcher {
|
||||
private final PsiMethod myConstructor;
|
||||
private final Processor<PsiReference> myConsumer;
|
||||
private final boolean myIncludeOverloads;
|
||||
|
||||
public LiteralConstructorSearcher(PsiMethod constructor, Processor<PsiReference> consumer) {
|
||||
public LiteralConstructorSearcher(PsiMethod constructor, Processor<PsiReference> consumer, boolean includeOverloads) {
|
||||
myConstructor = constructor;
|
||||
myConsumer = consumer;
|
||||
myIncludeOverloads = includeOverloads;
|
||||
}
|
||||
|
||||
private static boolean checkLiteralInstantiation(PsiMethod constructor,
|
||||
Processor<PsiReference> consumer,
|
||||
GrListOrMap literal,
|
||||
PsiClassType expectedType) {
|
||||
final PsiType listType = literal.getType();
|
||||
if (listType instanceof GrTupleType) {
|
||||
if (GppReferenceContributor.isConstructorCall(expectedType, ((GrTupleType)listType).getComponentTypes(), constructor, literal)) {
|
||||
return consumer.process(PsiReferenceBase.createSelfReference(literal, TextRange.from(0, literal.getTextLength()), constructor));
|
||||
public boolean processLiteral(GrListOrMap literal) {
|
||||
if (literal.isMap()) {
|
||||
final GrNamedArgument argument = literal.findNamedArgument("super");
|
||||
if (argument != null) {
|
||||
return processConstructorReference(ObjectUtils.assertNotNull(argument.getLabel()).getReference());
|
||||
}
|
||||
}
|
||||
else if (listType instanceof GrMapType) {
|
||||
final PsiType constructorArgs = ((GrMapType)listType).getValueType("super");
|
||||
if (constructorArgs == null) {
|
||||
if (constructor.getParameterList().getParametersCount() == 0) {
|
||||
if (!consumer.process(PsiReferenceBase.createSelfReference(literal, TextRange.from(0, literal.getTextLength()), constructor))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (GrNamedArgument argument : literal.getNamedArguments()) {
|
||||
final GrArgumentLabel label = argument.getLabel();
|
||||
if (label != null && "super".equals(label.getName())) {
|
||||
final PsiReference reference = label.getReference();
|
||||
if (reference != null && reference.isReferenceTo(constructor)) {
|
||||
return consumer.process(reference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return processConstructorReference(literal.getReference());
|
||||
}
|
||||
|
||||
//no 'super', only default constructor applicable
|
||||
if (constructor.getParameterList().getParametersCount() == 0) {
|
||||
return consumer.process(PsiReferenceBase.createSelfReference(literal, TextRange.from(0, literal.getTextLength()), constructor));
|
||||
}
|
||||
private boolean processConstructorReference(@Nullable PsiReference reference) {
|
||||
if (reference != null && (myIncludeOverloads || reference.isReferenceTo(myConstructor))) {
|
||||
return myConsumer.process(reference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean processLiteral(GrListOrMap list, PsiClassType expectedType) {
|
||||
return checkLiteralInstantiation(myConstructor, myConsumer, list, expectedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,54 +9,38 @@ import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.findUsages.LiteralConstructorReference;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.expectedTypes.GroovyExpectedTypesProvider;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class GppReferenceContributor extends PsiReferenceContributor {
|
||||
public static boolean mayInvokeConstructor(PsiClassType expectedType, PsiMethod constructor, GrExpression args) {
|
||||
if (args == null) {
|
||||
return true;
|
||||
@Nullable
|
||||
private static PsiType[] getSuperConstructorArguments(GrExpression superAttributeValue) {
|
||||
if (superAttributeValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiType type = args.getType();
|
||||
final PsiType type = superAttributeValue.getType();
|
||||
if (type == null) {
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (type instanceof GrTupleType) {
|
||||
return isConstructorCall(expectedType, ((GrTupleType)type).getComponentTypes(), constructor, args);
|
||||
return ((GrTupleType)type).getComponentTypes();
|
||||
}
|
||||
|
||||
return isConstructorCall(expectedType, new PsiType[]{type}, constructor, args);
|
||||
}
|
||||
|
||||
public static boolean isConstructorCall(PsiClassType expectedType,
|
||||
PsiType[] argTypes,
|
||||
PsiMethod constructor,
|
||||
GroovyPsiElement context) {
|
||||
for (GroovyResolveResult candidate : PsiUtil.getConstructorCandidates(expectedType, argTypes, context)) {
|
||||
if (constructor.getManager().areElementsEquivalent(candidate.getElement(), constructor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return new PsiType[]{type};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,67 +74,38 @@ public class GppReferenceContributor extends PsiReferenceContributor {
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final GrArgumentLabel context = getElement();
|
||||
final GrNamedArgument namedArgument = (GrNamedArgument) context.getParent();
|
||||
for (PsiType type : getTargetConversionTypes((GrExpression)namedArgument.getParent())) {
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass psiClass = classType.resolve();
|
||||
if (psiClass != null) {
|
||||
final GrExpression value = namedArgument.getExpression();
|
||||
final PsiClassType classType = LiteralConstructorReference.getTargetConversionType((GrExpression)namedArgument.getParent());
|
||||
if (classType != null) {
|
||||
final PsiClass psiClass = classType.resolve();
|
||||
if (psiClass != null) {
|
||||
final GrExpression value = namedArgument.getExpression();
|
||||
|
||||
final List<ResolveResult> applicable = addMethodCandidates(classType, value);
|
||||
final List<ResolveResult> applicable = addMethodCandidates(classType, value);
|
||||
|
||||
final String memberName = getValue();
|
||||
if ("super".equals(memberName) && GppTypeConverter.hasTypedContext(myElement)) {
|
||||
applicable.addAll(addConstructorCandidates(classType, psiClass, value));
|
||||
}
|
||||
final String memberName = getValue();
|
||||
if ("super".equals(memberName) && GppTypeConverter.hasTypedContext(myElement)) {
|
||||
applicable.addAll(LiteralConstructorReference.getConstructorCandidates(classType, context, getSuperConstructorArguments(value)));
|
||||
}
|
||||
|
||||
if (value == null || applicable.isEmpty()) {
|
||||
final PsiMethod setter = PropertyUtil.findPropertySetter(psiClass, memberName, false, true);
|
||||
if (setter != null) {
|
||||
applicable.add(new PsiElementResolveResult(setter));
|
||||
} else {
|
||||
final PsiField field = PropertyUtil.findPropertyField(psiClass.getProject(), psiClass, memberName, false);
|
||||
if (field != null) {
|
||||
applicable.add(new PsiElementResolveResult(field));
|
||||
}
|
||||
if (value == null || applicable.isEmpty()) {
|
||||
final PsiMethod setter = PropertyUtil.findPropertySetter(psiClass, memberName, false, true);
|
||||
if (setter != null) {
|
||||
applicable.add(new PsiElementResolveResult(setter));
|
||||
} else {
|
||||
final PsiField field = PropertyUtil.findPropertyField(psiClass.getProject(), psiClass, memberName, false);
|
||||
if (field != null) {
|
||||
applicable.add(new PsiElementResolveResult(field));
|
||||
}
|
||||
}
|
||||
|
||||
return applicable.toArray(new ResolveResult[applicable.size()]);
|
||||
}
|
||||
|
||||
return applicable.toArray(new ResolveResult[applicable.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
return ResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
private static Set<PsiType> getTargetConversionTypes(GrExpression expression) {
|
||||
//todo hack
|
||||
if (expression.getParent() instanceof GrSafeCastExpression) {
|
||||
final PsiType type = ((GrSafeCastExpression)expression.getParent()).getType();
|
||||
if (type != null) {
|
||||
return Collections.singleton(type);
|
||||
}
|
||||
}
|
||||
|
||||
return GroovyExpectedTypesProvider.getDefaultExpectedTypes(expression);
|
||||
}
|
||||
|
||||
|
||||
private static List<ResolveResult> addConstructorCandidates(PsiClassType classType, PsiClass psiClass, GrExpression value) {
|
||||
List<ResolveResult> applicable = CollectionFactory.arrayList();
|
||||
final List<ResolveResult> byName = CollectionFactory.arrayList();
|
||||
for (PsiMethod constructor : psiClass.getConstructors()) {
|
||||
final ResolveResult resolveResult = new PsiElementResolveResult(constructor);
|
||||
byName.add(resolveResult);
|
||||
if (mayInvokeConstructor(classType, constructor, value)) {
|
||||
applicable.add(resolveResult);
|
||||
}
|
||||
}
|
||||
if (applicable.isEmpty()) {
|
||||
applicable.addAll(byName);
|
||||
}
|
||||
return applicable;
|
||||
}
|
||||
|
||||
private List<ResolveResult> addMethodCandidates(PsiClassType classType, GrExpression value) {
|
||||
PsiType valueType = value == null ? null : value.getType();
|
||||
|
||||
+4
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.UserDataHolderEx;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiArrayInitializerMemberValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
|
||||
@@ -42,5 +43,8 @@ public interface GrListOrMap extends UserDataHolderEx, Cloneable, Iconable, PsiE
|
||||
@NotNull
|
||||
GrNamedArgument[] getNamedArguments();
|
||||
|
||||
@Nullable
|
||||
GrNamedArgument findNamedArgument(@NotNull String label);
|
||||
|
||||
boolean isMap();
|
||||
}
|
||||
|
||||
+27
-8
@@ -21,6 +21,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
@@ -37,6 +39,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryE
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrClosureSignatureUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
@@ -142,14 +145,9 @@ public class GroovyExpectedTypesProvider {
|
||||
|
||||
@Override
|
||||
public void visitOpenBlock(GrOpenBlock block) {
|
||||
if (block.getParent() instanceof PsiMethod) {
|
||||
final GrStatement[] statements = block.getStatements();
|
||||
if (statements.length > 0 && myExpression.equals(statements[statements.length - 1])) {
|
||||
final PsiType type = ((PsiMethod)block.getParent()).getReturnType();
|
||||
if (type != null) {
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(type, type)};
|
||||
}
|
||||
}
|
||||
final GrStatement[] statements = block.getStatements();
|
||||
if (statements.length > 0 && myExpression.equals(statements[statements.length - 1])) {
|
||||
checkExitPoint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +155,27 @@ public class GroovyExpectedTypesProvider {
|
||||
if (myExpression.equals(ifStatement.getCondition())) {
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(TypesUtil.getJavaLangObject(ifStatement), PsiType.BOOLEAN)};
|
||||
}
|
||||
else if (myExpression.equals(ifStatement.getThenBranch()) || myExpression.equals(ifStatement.getElseBranch())) {
|
||||
checkExitPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkExitPoint() {
|
||||
final PsiElement element = PsiTreeUtil.getParentOfType(myExpression, PsiMethod.class, GrClosableBlock.class);
|
||||
if (element instanceof GrMethod) {
|
||||
final GrMethod method = (GrMethod)element;
|
||||
ControlFlowUtils.visitAllExitPoints(method.getBlock(), new ControlFlowUtils.ExitPointVisitor() {
|
||||
@Override
|
||||
public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
|
||||
if (returnValue == myExpression) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
myResult = new TypeConstraint[]{new SubtypeConstraint(returnType, returnType)};
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void visitWhileStatement(GrWhileStatement whileStatement) {
|
||||
|
||||
+19
-16
@@ -354,13 +354,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
String[] paramNames,
|
||||
String body,
|
||||
PsiElement context) {
|
||||
final GrMethod method = createMethodFromText(null, constructorName, null, paramTypes, paramNames, body, context);
|
||||
final String text = generateMethodText(null, constructorName, null, paramTypes, paramNames, body, true);
|
||||
|
||||
GroovyFileImpl file = createDummyFile("class " + constructorName + "{" + method.getText() + "}");
|
||||
GroovyFileImpl file = createDummyFile("class " + constructorName + "{" + text + "}");
|
||||
file.setContext(context);
|
||||
GrTopLevelDefintion defintion = file.getTopLevelDefinitions()[0];
|
||||
assert defintion != null && defintion instanceof GrClassDefinition;
|
||||
final PsiMethod constructor = ((GrClassDefinition) defintion).getMethods()[0];
|
||||
GrTopLevelDefintion definition = file.getTopLevelDefinitions()[0];
|
||||
assert definition != null && definition instanceof GrClassDefinition;
|
||||
final PsiMethod constructor = ((GrClassDefinition) definition).getMethods()[0];
|
||||
assert constructor instanceof GrConstructorImpl;
|
||||
return ((GrConstructorImpl) constructor);
|
||||
}
|
||||
@@ -502,13 +502,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
}
|
||||
|
||||
|
||||
private GrMethod createMethodFromText(String modifier,
|
||||
String name,
|
||||
String type,
|
||||
@Nullable String[] paramTypes,
|
||||
@NotNull String[] paramNames,
|
||||
String body,
|
||||
PsiElement context) {
|
||||
private static String generateMethodText(String modifier,
|
||||
String name,
|
||||
String type,
|
||||
String[] paramTypes,
|
||||
String[] paramNames,
|
||||
String body,
|
||||
boolean isConstructor) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (modifier != null){
|
||||
@@ -516,7 +516,9 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
builder.append(" ");
|
||||
}
|
||||
|
||||
builder.append("def ");
|
||||
if (!isConstructor) {
|
||||
builder.append("def ");
|
||||
}
|
||||
|
||||
//This is for constructor creation
|
||||
if (type != null) {
|
||||
@@ -547,7 +549,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
builder.append("}");
|
||||
}
|
||||
|
||||
return createMethodFromText(builder.toString(), context);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public GrMethod createMethodFromText(String modifier, String name, @Nullable String type, String[] paramTypes, PsiElement context) {
|
||||
@@ -565,8 +567,9 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
res.add(psiType);
|
||||
}
|
||||
|
||||
return createMethodFromText(modifier, name, type, paramTypes,
|
||||
QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()])), null, context);
|
||||
String[] paramNames = QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()]));
|
||||
final String text = generateMethodText(modifier, name, type, paramTypes, paramNames, null, false);
|
||||
return createMethodFromText(text, context);
|
||||
}
|
||||
|
||||
public GrDocComment createDocCommentFromText(String text) {
|
||||
|
||||
+22
@@ -24,6 +24,7 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.findUsages.LiteralConstructorReference;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
@@ -92,6 +93,27 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
return findChildrenByClass(GrNamedArgument.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrNamedArgument findNamedArgument(@NotNull String labelName) {
|
||||
for (GrNamedArgument argument : getNamedArguments()) {
|
||||
final GrArgumentLabel label = argument.getLabel();
|
||||
if (label != null && labelName.equals(label.getName())) {
|
||||
return argument;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiReference getReference() {
|
||||
final PsiClassType conversionType = LiteralConstructorReference.getTargetConversionType(this);
|
||||
if (conversionType != null) {
|
||||
return new LiteralConstructorReference(this, conversionType);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class MyTypesCalculator implements Function<GrListOrMapImpl, PsiType> {
|
||||
@Nullable
|
||||
public PsiType fun(GrListOrMapImpl listOrMap) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.testFramework.PsiTestUtil
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import com.intellij.psi.PsiClass
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -123,4 +124,17 @@ public class GroovyDslTest extends LightCodeInsightFixtureTestCase {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public void testCategoryWhenMethodRenamed() {
|
||||
PsiClass category = myFixture.addClass("""
|
||||
public class MyCategory {
|
||||
public void foo(String s) {}
|
||||
}""")
|
||||
def foo = category.getMethods()[0]
|
||||
final PsiFile file = myFixture.addFileToProject(getTestName(false) + "Enhancer.gdsl", """
|
||||
category 'MyCategory'""");
|
||||
GroovyDslFileIndex.activateUntilModification(file.virtualFile)
|
||||
myFixture.renameElement foo, "bar", false, false
|
||||
|
||||
myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,6 +407,29 @@ class Point {
|
||||
assertEquals 2, multiResolveReference().size()
|
||||
}
|
||||
|
||||
public void testGotoSuperConstructorFromLiteralOnsets() throws Exception {
|
||||
PsiClass point = myFixture.addClass("""
|
||||
class Point {
|
||||
Point() {}
|
||||
Point(int y) {}
|
||||
}""")
|
||||
|
||||
configureGppScript "Point p = <caret>[super: 2]"
|
||||
assertEquals point.constructors[1], resolveReference()
|
||||
|
||||
configureGppScript "Point p = <caret>[2]"
|
||||
assertEquals point.constructors[1], resolveReference()
|
||||
|
||||
configureGppScript "Point p = <caret>[]"
|
||||
assertEquals point.constructors[0], resolveReference()
|
||||
|
||||
configureGppScript "Point p = <caret>[:]"
|
||||
assertEquals point.constructors[0], resolveReference()
|
||||
|
||||
configureGppScript "Point p = <caret>[239, 42]"
|
||||
assertEquals 2, multiResolveReference().size()
|
||||
}
|
||||
|
||||
public void testResolveTraitMethod() throws Exception {
|
||||
configureScript """
|
||||
@Trait
|
||||
|
||||
+26
-3
@@ -1,7 +1,8 @@
|
||||
package org.jetbrains.plugins.groovy.lang
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -26,8 +27,14 @@ class LiteralConstructorUsagesTest extends LightCodeInsightFixtureTestCase {
|
||||
Foo() {}
|
||||
}
|
||||
""")
|
||||
myFixture.addFileToProject "a.groovy", "Foo foo() { if (true) [] else return [] }"
|
||||
assertEquals(2, ReferencesSearch.search(foo.constructors[0]).findAll().size())
|
||||
myFixture.addFileToProject "a.groovy", """
|
||||
Foo foo() {
|
||||
if (true) []
|
||||
else return []
|
||||
}
|
||||
Foo bar() { [] }
|
||||
"""
|
||||
assertEquals(3, ReferencesSearch.search(foo.constructors[0]).findAll().size())
|
||||
}
|
||||
|
||||
public void testList_Cast() throws Exception {
|
||||
@@ -160,4 +167,20 @@ class LiteralConstructorUsagesTest extends LightCodeInsightFixtureTestCase {
|
||||
assertEquals(2, ReferencesSearch.search(foo.constructors[1]).findAll().size())
|
||||
}
|
||||
|
||||
public void testOverloadedConstructorUsages() throws Exception {
|
||||
def foo = myFixture.addClass("""
|
||||
class Foo {
|
||||
Foo() {}
|
||||
Foo(int a) {}
|
||||
}
|
||||
""")
|
||||
|
||||
myFixture.addFileToProject "a.gpp", """
|
||||
Foo b = []
|
||||
Foo b1 = [2]
|
||||
"""
|
||||
assertEquals(2, MethodReferencesSearch.search(foo.constructors[0], false).findAll().size())
|
||||
assertEquals(2, MethodReferencesSearch.search(foo.constructors[1], false).findAll().size())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user