Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2012-05-16 16:03:33 +04:00
53 changed files with 4757 additions and 13814 deletions
+3
View File
@@ -21,6 +21,7 @@ if [ -z "$UNAME" -o -z "$GREP" -o -z "$CUT" -o -z "$MKTEMP" -o -z "$RM" -o -z "$
fi
OS_TYPE=`"$UNAME" -s`
WORKING_DIR=`pwd`
# ---------------------------------------------------------------------
# Locate a JDK installation directory which will be used to run the IDE.
@@ -140,6 +141,8 @@ if [ -r "$VM_OPTIONS_FILE" ]; then
VM_OPTIONS="$VM_OPTIONS -Djb.vmOptionsFile=\"$VM_OPTIONS_FILE\""
fi
VM_OPTIONS="$VM_OPTIONS -Doriginal.working.dir=\"$WORKING_DIR\""
IS_EAP="@@isEap@@"
if [ "$IS_EAP" = "true" ]; then
OS_NAME=`echo $OS_TYPE | "$TR" '[:upper:]' '[:lower:]'`
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -54,6 +54,7 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase {
ourMap2 = new HashMap<IElementType, TextAttributesKey>();
fillMap(ourMap1, ElementType.KEYWORD_BIT_SET, SyntaxHighlighterColors.KEYWORD);
fillMap(ourMap1, ElementType.LITERAL_BIT_SET, SyntaxHighlighterColors.KEYWORD);
fillMap(ourMap1, ElementType.OPERATION_BIT_SET, SyntaxHighlighterColors.OPERATION_SIGN);
for (IElementType type : JavaDocTokenType.ALL_JAVADOC_TOKENS.getTypes()) {
@@ -21,9 +21,7 @@ import com.intellij.psi.PsiTypeElement;
import com.intellij.psi.impl.source.PsiElementArrayConstructor;
import com.intellij.psi.tree.TokenSet;
public interface ElementType extends JavaTokenType, JavaDocTokenType,
JavaElementType, JavaDocElementType {
public interface ElementType extends JavaTokenType, JavaDocTokenType, JavaElementType, JavaDocElementType {
TokenSet JAVA_WHITESPACE_BIT_SET = TokenSet.create(WHITE_SPACE);
TokenSet JAVA_PLAIN_COMMENT_BIT_SET = TokenSet.create(END_OF_LINE_COMMENT, C_STYLE_COMMENT);
@@ -32,13 +30,16 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType,
TokenSet JAVA_COMMENT_OR_WHITESPACE_BIT_SET = TokenSet.orSet(JAVA_WHITESPACE_BIT_SET, JAVA_COMMENT_BIT_SET);
TokenSet KEYWORD_BIT_SET = TokenSet.create(
ABSTRACT_KEYWORD, ASSERT_KEYWORD, BOOLEAN_KEYWORD, BREAK_KEYWORD, BYTE_KEYWORD, CASE_KEYWORD, CATCH_KEYWORD, CHAR_KEYWORD, CLASS_KEYWORD,
CONST_KEYWORD, CONTINUE_KEYWORD, DEFAULT_KEYWORD, DO_KEYWORD, DOUBLE_KEYWORD, ELSE_KEYWORD, EXTENDS_KEYWORD, FINAL_KEYWORD,
ABSTRACT_KEYWORD, ASSERT_KEYWORD, BOOLEAN_KEYWORD, BREAK_KEYWORD, BYTE_KEYWORD, CASE_KEYWORD, CATCH_KEYWORD, CHAR_KEYWORD,
CLASS_KEYWORD,
CONST_KEYWORD, CONTINUE_KEYWORD, DEFAULT_KEYWORD, DO_KEYWORD, DOUBLE_KEYWORD, ELSE_KEYWORD, ENUM_KEYWORD, EXTENDS_KEYWORD,
FINAL_KEYWORD,
FINALLY_KEYWORD, FLOAT_KEYWORD, FOR_KEYWORD, GOTO_KEYWORD, IF_KEYWORD, IMPLEMENTS_KEYWORD, IMPORT_KEYWORD, INSTANCEOF_KEYWORD,
INT_KEYWORD, INTERFACE_KEYWORD, LONG_KEYWORD, NATIVE_KEYWORD, NEW_KEYWORD, PACKAGE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD,
SHORT_KEYWORD, SUPER_KEYWORD, SWITCH_KEYWORD, STRICTFP_KEYWORD, SYNCHRONIZED_KEYWORD, THIS_KEYWORD, THROW_KEYWORD, PROTECTED_KEYWORD,
TRANSIENT_KEYWORD, RETURN_KEYWORD, VOID_KEYWORD, STATIC_KEYWORD, WHILE_KEYWORD, TRY_KEYWORD, VOLATILE_KEYWORD, THROWS_KEYWORD,
ENUM_KEYWORD);
INT_KEYWORD, INTERFACE_KEYWORD, LONG_KEYWORD, NATIVE_KEYWORD, NEW_KEYWORD, PACKAGE_KEYWORD, PRIVATE_KEYWORD, PROTECTED_KEYWORD,
PUBLIC_KEYWORD, RETURN_KEYWORD, SHORT_KEYWORD, SUPER_KEYWORD, STATIC_KEYWORD, STRICTFP_KEYWORD, SWITCH_KEYWORD, SYNCHRONIZED_KEYWORD,
THIS_KEYWORD, THROW_KEYWORD, THROWS_KEYWORD, TRANSIENT_KEYWORD, TRY_KEYWORD, VOID_KEYWORD, VOLATILE_KEYWORD, WHILE_KEYWORD);
TokenSet LITERAL_BIT_SET = TokenSet.create(TRUE_KEYWORD, FALSE_KEYWORD, NULL_KEYWORD);
TokenSet OPERATION_BIT_SET = TokenSet.create(
EQ, GT, LT, EXCL, TILDE, QUEST, COLON, PLUS, MINUS, ASTERISK, DIV, AND, OR, XOR,
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -20,23 +20,23 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiKeyword;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.Nullable;
public class ModifierListElement extends CompositeElement {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.ModifierListElement");
public ModifierListElement() {
super(Constants.MODIFIER_LIST);
super(JavaElementType.MODIFIER_LIST);
}
@Override
public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) {
if (before == null){
if (first == last && ElementType.KEYWORD_BIT_SET.contains(first.getElementType())){
if (before == null) {
if (first == last && ElementType.KEYWORD_BIT_SET.contains(first.getElementType())) {
anchor = getDefaultAnchor((PsiModifierList)SourceTreeToPsiMap.treeElementToPsi(this),
(PsiKeyword)SourceTreeToPsiMap.treeElementToPsi(first));
before = Boolean.TRUE;
@@ -68,11 +68,11 @@ public class ModifierListElement extends CompositeElement {
ourModifierToOrderMap.put(PsiModifier.STRICTFP, 6);
}
@Nullable
private static ASTNode getDefaultAnchor(PsiModifierList modifierList, PsiKeyword modifier) {
Integer order = ourModifierToOrderMap.get(modifier.getText());
if (order == null) return null;
for (ASTNode child = SourceTreeToPsiMap.psiElementToTree(modifierList).getFirstChildNode(); child != null; child = child.getTreeNext())
{
for (ASTNode child = SourceTreeToPsiMap.psiToTreeNotNull(modifierList).getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (ElementType.KEYWORD_BIT_SET.contains(child.getElementType())) {
Integer order1 = ourModifierToOrderMap.get(child.getText());
if (order1 == null) continue;
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.ex.DocumentEx;
import org.jetbrains.annotations.NotNull;
/**
* Is intended to hold utility methods to use during {@link Document} processing.
*
* @author Denis Zhdanov
* @since 5/16/12 10:12 AM
*/
public class DocumentUtil {
private DocumentUtil() {
}
// TODO den add doc
public static void executeInBulk(@NotNull Document document, final boolean executeInBulk, @NotNull Runnable task) {
if (!(document instanceof DocumentEx)) {
task.run();
return;
}
DocumentEx documentEx = (DocumentEx)document;
if (executeInBulk == documentEx.isInBulkUpdate()) {
task.run();
return;
}
documentEx.setInBulkUpdate(executeInBulk);
try {
task.run();
}
finally {
documentEx.setInBulkUpdate(!executeInBulk);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -41,6 +41,7 @@ import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.DocumentUtil;
import com.intellij.util.containers.IntStack;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
@@ -231,8 +232,8 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
if (stamp != null && stamp.longValue() == nowStamp()) return;
List<RangeHighlighter> oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY);
List<RangeHighlighter> newHighlighters = new ArrayList<RangeHighlighter>();
MarkupModel mm = myEditor.getMarkupModel();
final List<RangeHighlighter> newHighlighters = new ArrayList<RangeHighlighter>();
final MarkupModel mm = myEditor.getMarkupModel();
int curRange = 0;
@@ -264,9 +265,16 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
}
}
for (; curRange < myRanges.size(); curRange++) {
newHighlighters.add(createHighlighter(mm, myRanges.get(curRange)));
}
final int startRangeIndex = curRange;
DocumentUtil.executeInBulk(myDocument, myRanges.size() > 10000, new Runnable() {
@Override
public void run() {
for (int i = startRangeIndex; i < myRanges.size(); i++) {
newHighlighters.add(createHighlighter(mm, myRanges.get(i)));
}
}
});
myEditor.putUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters);
myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp());
@@ -271,6 +271,9 @@ public class FileBasedIndexImpl extends FileBasedIndex {
}
*/
}
private void initExtensions() {
try {
final FileBasedIndexExtension[] extensions = Extensions.getExtensions(FileBasedIndexExtension.EXTENSION_POINT_NAME);
for (FileBasedIndexExtension<?, ?> extension : extensions) {
@@ -318,6 +321,9 @@ public class FileBasedIndexImpl extends FileBasedIndex {
registerIndexableSet(new AdditionalIndexableFileSet(), null);
}
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
@Override
@@ -329,6 +335,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
saveRegisteredIndices(myIndices.keySet());
myFlushingFuture = FlushingDaemon.everyFiveSeconds(new Runnable() {
int lastModCount = 0;
@Override
public void run() {
if (lastModCount == myLocalModCount) {
@@ -343,6 +350,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
@Override
public void initComponent() {
initExtensions();
}
@Nullable
@@ -17,6 +17,7 @@ package com.intellij.openapi.diff;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationStarterEx;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.StreamUtil;
@@ -162,7 +163,12 @@ public abstract class ApplicationStarterBase implements ApplicationStarterEx {
@NotNull
public static VirtualFile findFile(final String path) throws OperationFailedException {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path));
File ioFile = new File(path);
if (!ioFile.exists()) {
final String dir = PathManager.getOriginalWorkingDir();
ioFile = new File(dir + File.separator + path);
}
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
if (file == null) {
throw new OperationFailedException("Can't find file " + path);
}
@@ -19,7 +19,6 @@ import com.intellij.diagnostic.IdeErrorsDialog;
import com.intellij.diagnostic.PluginException;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.impl.ComponentManagerImpl;
@@ -66,39 +65,28 @@ abstract class ComponentStoreImpl implements IComponentStore {
throw new UnsupportedOperationException("Method getDefaultsStorage is not supported in " + getClass());
}
public String initComponent(@NotNull final Object component, final boolean service) {
boolean isSerializable = component instanceof JDOMExternalizable ||
component instanceof PersistentStateComponent ||
component instanceof SettingsSavingComponent;
if (!isSerializable) return null;
public void initComponent(@NotNull final Object component, final boolean service) {
if (component instanceof SettingsSavingComponent) {
SettingsSavingComponent settingsSavingComponent = (SettingsSavingComponent)component;
mySettingsSavingComponents.add(settingsSavingComponent);
}
final String[] componentName = {null};
final Runnable r = new Runnable() {
boolean isSerializable = component instanceof JDOMExternalizable ||
component instanceof PersistentStateComponent;
if (!isSerializable) return;
ApplicationManagerEx.getApplicationEx().runReadAction(new Runnable() {
public void run() {
if (component instanceof PersistentStateComponent) {
componentName[0] = initPersistentComponent((PersistentStateComponent<?>)component, false);
initPersistentComponent((PersistentStateComponent<?>)component, false);
}
else if (component instanceof JDOMExternalizable) {
componentName[0] = initJdomExternalizable((JDOMExternalizable)component);
else {
initJdomExternalizable((JDOMExternalizable)component);
}
}
};
final ApplicationEx applicationEx = ApplicationManagerEx.getApplicationEx();
if (applicationEx.isUnitTestMode()) {
r.run(); // Todo
}
else {
applicationEx.runReadAction(r);
}
return componentName[0];
});
}
public boolean isSaving() {
@@ -28,12 +28,11 @@ import java.util.List;
import java.util.Set;
public interface IComponentStore {
@Nullable
String initComponent(Object component, boolean service);
void initComponent(Object component, boolean service);
void reinitComponents(Set<String> componentNames, boolean reloadData);
boolean isReloadPossible(Set<String> componentNames);
void load() throws IOException, StateStorageException;
boolean isSaving();
@@ -6060,6 +6060,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
List<? extends SoftWrap> softWraps = getSoftWrapModel().getRegisteredSoftWraps();
int softWrapsIndex = -1;
FontInfo lastFontInfo = null;
for (int line = 0; line < lineCount; line++) {
if (myLineWidths.getQuick(line) != -1) continue;
if (line == lineCount - 1) {
@@ -6158,7 +6159,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
}
}
else {
x += ComplementaryFontsRegistry.getFontAbleToDisplay(c, fontSize, fontType, fontName).charWidth(c);
if (lastFontInfo == null || !lastFontInfo.canDisplay(c)) {
lastFontInfo = ComplementaryFontsRegistry.getFontAbleToDisplay(c, fontSize, fontType, fontName);
}
x += lastFontInfo.charWidth(c);
offset++;
}
}
@@ -56,6 +56,7 @@ public abstract class FileEditorManagerEx extends FileEditorManager implements B
*
* @see EditorComposite#getPreferredFocusedComponent()
*/
@Nullable
public abstract JComponent getPreferredFocusedComponent();
@NotNull
@@ -113,6 +114,7 @@ public abstract class FileEditorManagerEx extends FileEditorManager implements B
public abstract boolean hasOpenedFile ();
@Nullable
public abstract VirtualFile getCurrentFile();
@Nullable
@@ -49,7 +49,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.impl.ProjectImpl;
import com.intellij.openapi.roots.ModuleRootAdapter;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
@@ -1043,7 +1042,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
openFiles.addAll(Arrays.asList(each.getOpenFiles()));
}
return VfsUtil.toVirtualFileArray(openFiles);
return VfsUtilCore.toVirtualFileArray(openFiles);
}
@NotNull
@@ -1053,7 +1052,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
selectedFiles.addAll(Arrays.asList(each.getSelectedFiles()));
}
return VfsUtil.toVirtualFileArray(selectedFiles);
return VfsUtilCore.toVirtualFileArray(selectedFiles);
}
@NotNull
@@ -105,12 +105,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
}
private final MessageBus myMessageBus;
private static final Map<String, StandardFileType> ourStandardFileTypes = new LinkedHashMap<String, StandardFileType>();
private final Map<String, StandardFileType> myStandardFileTypes = new LinkedHashMap<String, StandardFileType>();
@NonNls private static final String[] FILE_TYPES_WITH_PREDEFINED_EXTENSIONS = {"JSP", "JSPX", "DTD", "HTML", "Properties", "XHTML"};
private final SchemesManager<FileType, AbstractFileType> mySchemesManager;
@NonNls private static final String FILE_SPEC = "$ROOT_CONFIG$/filetypes";
static {
private void initStandardFileTypes() {
final FileTypeConsumer consumer = new FileTypeConsumer() {
@Override
public void consume(@NotNull FileType fileType) {
@@ -129,25 +129,24 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
@Override
public FileType getStandardFileTypeByName(@NotNull final String name) {
final StandardFileType type = ourStandardFileTypes.get(name);
final StandardFileType type = myStandardFileTypes.get(name);
return type != null ? type.fileType : null;
}
private void register(final FileType fileType, final List<FileNameMatcher> fileNameMatchers) {
final StandardFileType type = ourStandardFileTypes.get(fileType.getName());
final StandardFileType type = myStandardFileTypes.get(fileType.getName());
if (type != null) {
for (FileNameMatcher matcher : fileNameMatchers) type.matchers.add(matcher);
}
else {
ourStandardFileTypes.put(fileType.getName(), new StandardFileType(fileType, fileNameMatchers));
myStandardFileTypes.put(fileType.getName(), new StandardFileType(fileType, fileNameMatchers));
}
}
};
final FileTypeFactory[] fileTypeFactories = Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP);
for (final FileTypeFactory factory : fileTypeFactories) {
for (final FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) {
try {
initFactory(consumer, factory);
factory.createFileTypes(consumer);
}
catch (final Error ex) {
PluginManager.disableIncompatiblePlugin(factory, ex);
@@ -155,10 +154,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
}
}
private static void initFactory(final FileTypeConsumer consumer, final FileTypeFactory factory) {
factory.createFileTypes(consumer);
}
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
@@ -238,12 +233,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
fireFileTypesChanged();
}
}, RoamingType.PER_USER);
for (final StandardFileType pair : ourStandardFileTypes.values()) {
registerFileTypeWithoutNotification(pair.fileType, pair.matchers);
}
if (loadAllFileTypes()) {
restoreStandardFileExtensions();
}
}
private static void writeImportedExtensionsMap(final Element map, final ImportedFileType type) {
@@ -264,7 +253,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
@Override
@NotNull
public FileType getStdFileType(@NotNull @NonNls String name) {
StandardFileType stdFileType = ourStandardFileTypes.get(name);
StandardFileType stdFileType = myStandardFileTypes.get(name);
return stdFileType != null ? stdFileType.fileType : PlainTextFileType.INSTANCE;
}
@@ -289,6 +278,14 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
@Override
public void initComponent() {
initStandardFileTypes();
for (final StandardFileType pair : myStandardFileTypes.values()) {
registerFileTypeWithoutNotification(pair.fileType, pair.matchers);
}
if (loadAllFileTypes()) {
restoreStandardFileExtensions();
}
}
// -------------------------------------------------------------------------
@@ -722,7 +719,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME
private void restoreStandardFileExtensions() {
for (final String name : FILE_TYPES_WITH_PREDEFINED_EXTENSIONS) {
final StandardFileType stdFileType = ourStandardFileTypes.get(name);
final StandardFileType stdFileType = myStandardFileTypes.get(name);
if (stdFileType != null) {
FileType fileType = stdFileType.fileType;
for (FileNameMatcher matcher : myPatternsTable.getAssociations(fileType)) {
@@ -122,7 +122,7 @@ public class MockProjectStore implements IProjectStore {
}
@Override
public String initComponent(Object component, final boolean service) {
public void initComponent(Object component, final boolean service) {
throw new UnsupportedOperationException("Method initComponent is not yet implemented in " + getClass().getName());
}
@@ -17,7 +17,6 @@
package com.intellij.openapi.application;
import com.google.common.collect.Lists;
import com.intellij.CommonBundle;
import com.intellij.openapi.util.NamedJDOMExternalizable;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.SystemInfoRt;
@@ -49,6 +48,7 @@ public class PathManager {
@NonNls public static final String PROPERTY_HOME_PATH = "idea.home.path";
@NonNls public static final String PROPERTY_LOG_PATH = "idea.log.path";
@NonNls public static final String PROPERTY_PATHS_SELECTOR = "idea.paths.selector";
@NonNls public static final String PROPERTY_ORIGINAL_WORKING_DIR = "original.working.dir";
@NonNls private static String ourHomePath;
@NonNls private static String ourSystemPath;
@@ -293,6 +293,11 @@ public class PathManager {
return new File(getOptionsPath()+File.separatorChar+externalizable.getExternalFileName()+".xml");
}
@Nullable
public static String getOriginalWorkingDir() {
return System.getProperty(PROPERTY_ORIGINAL_WORKING_DIR);
}
@NonNls
public static File getOptionsFile(@NonNls String fileName) {
return new File(getOptionsPath()+File.separatorChar+fileName+".xml");
@@ -36,6 +36,10 @@ public class RootView extends JComponent {
setImage(image);
}
public BufferedImage getImage() {
return myImage;
}
public void setImage(BufferedImage image) {
myImage = image;
myEmptyRegions = new ArrayList<EmptyRegion>();
@@ -16,6 +16,7 @@
package com.intellij.android.designer.designSurface.layout;
import com.intellij.android.designer.designSurface.AbstractEditOperation;
import com.intellij.android.designer.designSurface.RootView;
import com.intellij.android.designer.designSurface.layout.relative.*;
import com.intellij.android.designer.model.ModelParser;
import com.intellij.android.designer.model.RadViewComponent;
@@ -30,6 +31,7 @@ import com.intellij.psi.xml.XmlTag;
import com.intellij.ui.IdeBorderFactory;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -81,6 +83,9 @@ public class RelativeLayoutOperation extends AbstractEditOperation {
if (myContext.isCreate() || myContext.isPaste()) {
myBounds = new Rectangle(0, 0, 64, 32);
myBoundsFeedback = new AlphaFeedback(myComponents.size() == 1 ? Color.green : Color.orange);
// XXX
}
else {
Iterator<RadComponent> I = myComponents.iterator();
@@ -95,12 +100,28 @@ public class RelativeLayoutOperation extends AbstractEditOperation {
if (myBounds.height == 0) {
myBounds.height = 32;
}
if (myComponents.size() == 1) {
RadComponent component = myComponents.get(0);
final Rectangle bounds = component.getBounds();
final BufferedImage image = ((RootView)((RadViewComponent)component.getRoot()).getNativeComponent()).getImage();
myBoundsFeedback = new AlphaFeedback(null) {
@Override
protected void paintOther2(Graphics2D g2d) {
g2d.drawImage(image,
0, 0, bounds.width, bounds.height,
bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
null);
}
};
}
else {
myBoundsFeedback = new AlphaFeedback(Color.orange);
}
}
// XXX
myBoundsFeedback = new AlphaFeedback(myComponents.size() == 1 ? Color.green : Color.orange);
myBoundsFeedback.setSize(myBounds.width, myBounds.height);
layer.add(myBoundsFeedback);
layer.repaint();
@@ -55,8 +55,11 @@ public class RelativeLayoutResizeOperation implements EditOperation {
private Rectangle myContainerBounds;
private Dimension myWrapSize;
private List<SnapPoint> myHorizontalPoints;
private List<SnapPoint> myVerticalPoints;
private Side myResizeHorizontalSide;
private Side myResizeVerticalSide;
private List<ResizeSnapPoint> myHorizontalPoints;
private List<ResizeSnapPoint> myVerticalPoints;
private SnapPoint myHorizontalPoint;
private SnapPoint myVerticalPoint;
@@ -94,6 +97,7 @@ public class RelativeLayoutResizeOperation implements EditOperation {
layer.add(myBoundsFeedback);
int direction = myContext.getResizeDirection();
if (direction == Position.EAST || direction == Position.SOUTH || direction == Position.SOUTH_EAST) {
Rectangle bounds = myComponent.getBounds(myContext.getArea().getFeedbackLayer());
String width = myComponent.getTag().getAttributeValue("android:layout_width");
@@ -121,6 +125,19 @@ public class RelativeLayoutResizeOperation implements EditOperation {
layer.add(myWrapFeedback);
}
if ((direction & Position.NORTH) != 0) {
myResizeVerticalSide = Side.top;
}
if ((direction & Position.SOUTH) != 0) {
myResizeVerticalSide = Side.bottom;
}
if ((direction & Position.WEST) != 0) {
myResizeHorizontalSide = Side.left;
}
if ((direction & Position.EAST) != 0) {
myResizeHorizontalSide = Side.right;
}
myContainerBounds = myContainer.getBounds(layer);
mySnapFeedback = new SnapPointFeedbackHost();
@@ -146,14 +163,14 @@ public class RelativeLayoutResizeOperation implements EditOperation {
myHorizontalPoint = null;
myVerticalPoint = null;
for (SnapPoint point : myHorizontalPoints) {
if (point.processBounds(myComponents, bounds, mySnapFeedback)) {
for (ResizeSnapPoint point : myHorizontalPoints) {
if (point.processBounds(myComponents, bounds, myResizeHorizontalSide, mySnapFeedback)) {
myHorizontalPoint = point;
break;
}
}
for (SnapPoint point : myVerticalPoints) {
if (point.processBounds(myComponents, bounds, mySnapFeedback)) {
for (ResizeSnapPoint point : myVerticalPoints) {
if (point.processBounds(myComponents, bounds, myResizeVerticalSide, mySnapFeedback)) {
myVerticalPoint = point;
break;
}
@@ -192,8 +209,8 @@ public class RelativeLayoutResizeOperation implements EditOperation {
}
private void createPoints() {
myHorizontalPoints = new ArrayList<SnapPoint>();
myVerticalPoints = new ArrayList<SnapPoint>();
myHorizontalPoints = new ArrayList<ResizeSnapPoint>();
myVerticalPoints = new ArrayList<ResizeSnapPoint>();
List<RadComponent> snapComponents = RelativeLayoutOperation.getSnapComponents(myContainer, myComponents);
snapComponents.removeAll(myContext.getComponents());
@@ -207,7 +224,7 @@ public class RelativeLayoutResizeOperation implements EditOperation {
}
}
private void createPoints(List<SnapPoint> points, List<RadComponent> snapComponents, boolean horizontal, int direction) {
private void createPoints(List<ResizeSnapPoint> points, List<RadComponent> snapComponents, boolean horizontal, int direction) {
for (RadComponent component : snapComponents) {
points.add(new ResizeComponentSnapPoint((RadViewComponent)component, horizontal));
}
@@ -218,7 +235,7 @@ public class RelativeLayoutResizeOperation implements EditOperation {
points.add(new WrapSizeSnapPoint(myComponent, horizontal, myWrapSize));
}
points.add(new AutoResizeSnapPoint(myContainer, horizontal, direction));
points.add(new AutoResizeSnapPoint(myContainer, horizontal));
}
@Override
@@ -19,7 +19,6 @@ import com.intellij.android.designer.model.ModelParser;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.designer.designSurface.feedbacks.TextFeedback;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.utils.Position;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.xml.XmlTag;
@@ -29,14 +28,13 @@ import java.util.List;
/**
* @author Alexander Lobas
*/
public class AutoResizeSnapPoint extends SnapPoint {
private final int myDirection;
public class AutoResizeSnapPoint extends ResizeSnapPoint {
private int myMargin;
private int mySize;
private Side mySide;
public AutoResizeSnapPoint(RadViewComponent container, boolean horizontal, int direction) {
public AutoResizeSnapPoint(RadViewComponent container, boolean horizontal) {
super(container, horizontal);
myDirection = direction;
}
@Override
@@ -48,7 +46,7 @@ public class AutoResizeSnapPoint extends SnapPoint {
feedback.append(", ");
}
if ((myDirection & Position.EAST_WEST) != 0) {
if (mySide == Side.left || mySide == Side.right) {
feedback.append("layout:width ");
}
else {
@@ -60,13 +58,15 @@ public class AutoResizeSnapPoint extends SnapPoint {
}
@Override
public boolean processBounds(List<RadComponent> components, Rectangle bounds, SnapPointFeedbackHost feedback) {
super.processBounds(components, bounds, feedback);
public boolean processBounds(List<RadComponent> components, Rectangle bounds, Side resizeSide, SnapPointFeedbackHost feedback) {
super.processBounds(components, bounds, resizeSide, feedback);
mySide = resizeSide;
if (myHorizontal) {
mySize = bounds.width;
if ((myDirection & Position.WEST) != 0) {
if (resizeSide == Side.left) {
myMargin = bounds.x - myBounds.x;
feedback.addVerticalLine(myBounds.x, myBounds.y, myBounds.height);
feedback.addHorizontalArrow(myBounds.x, bounds.y + bounds.height / 2, myMargin);
@@ -75,7 +75,7 @@ public class AutoResizeSnapPoint extends SnapPoint {
else {
mySize = bounds.height;
if ((myDirection & Position.NORTH) != 0) {
if (resizeSide == Side.top) {
myMargin = bounds.y - myBounds.y;
feedback.addHorizontalLine(myBounds.x, myBounds.y, myBounds.width);
feedback.addVerticalArrow(bounds.x + bounds.width / 2, myBounds.y, myMargin);
@@ -92,11 +92,29 @@ public class AutoResizeSnapPoint extends SnapPoint {
public void run() {
XmlTag tag = ((RadViewComponent)components.get(0)).getTag();
if (myMargin > 0) {
tag.setAttribute("android:layout_alignParent" + (myHorizontal ? "Left" : "Top"), "true");
tag.setAttribute("android:layout_margin" + (myHorizontal ? "Left" : "Top"), Integer.toString(myMargin) + "dp");
String attribute = myHorizontal ? "Left" : "Top";
tag.setAttribute("android:layout_alignParent" + attribute, "true");
tag.setAttribute("android:layout_margin" + attribute, Integer.toString(myMargin) + "dp");
ModelParser.deleteAttribute(tag, "android:layout_align" + attribute);
if (myHorizontal) {
ModelParser.deleteAttribute(tag, "android:layout_toRightOf");
}
else {
ModelParser.deleteAttribute(tag, "android:layout_below");
}
}
else {
ModelParser.deleteAttribute(tag, "android:layout_alignParent" + (myHorizontal ? "Right" : "Bottom"));
String attribute = myHorizontal ? "Right" : "Bottom";
ModelParser.deleteAttribute(tag, "android:layout_alignParent" + attribute);
ModelParser.deleteAttribute(tag, "android:layout_align" + attribute);
if (myHorizontal) {
ModelParser.deleteAttribute(tag, "android:layout_toLeftOf");
}
else {
ModelParser.deleteAttribute(tag, "android:layout_above");
}
}
tag.setAttribute("android:layout_" + (myHorizontal ? "width" : "height"), Integer.toString(mySize) + "dp");
}
@@ -28,7 +28,7 @@ import java.util.List;
* @author Alexander Lobas
*/
public class ComponentSnapPoint extends SnapPoint {
protected Side myBeginSide;
private Side myBeginSide;
private Side myEndSide;
public ComponentSnapPoint(RadViewComponent component, boolean horizontal) {
@@ -61,6 +61,10 @@ public class ComponentSnapPoint extends SnapPoint {
int startX = myBounds.x - SNAP_SIZE;
int endX = startX + 2 * SNAP_SIZE;
return processLeftLeft(startX, endX, targetBounds, feedback) || processLeftRight(startX, endX, targetBounds, feedback);
}
protected boolean processLeftLeft(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetX = targetBounds.x;
if (startX <= targetX && targetX <= endX) {
targetBounds.x = myBounds.x;
@@ -69,7 +73,11 @@ public class ComponentSnapPoint extends SnapPoint {
return true;
}
targetX = targetBounds.x + targetBounds.width;
return false;
}
protected boolean processLeftRight(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetX = targetBounds.x + targetBounds.width;
if (startX <= targetX && targetX <= endX) {
targetBounds.x = myBounds.x - targetBounds.width;
addVerticalFeedback(feedback, myBounds, targetBounds, true);
@@ -84,6 +92,10 @@ public class ComponentSnapPoint extends SnapPoint {
int startX = myBounds.x + myBounds.width - SNAP_SIZE;
int endX = startX + 2 * SNAP_SIZE;
return processRightLeft(startX, endX, targetBounds, feedback) || processRightRight(startX, endX, targetBounds, feedback);
}
protected boolean processRightLeft(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetX = targetBounds.x;
if (startX <= targetX && targetX <= endX) {
targetBounds.x = myBounds.x + myBounds.width;
@@ -92,7 +104,11 @@ public class ComponentSnapPoint extends SnapPoint {
return true;
}
targetX = targetBounds.x + targetBounds.width;
return false;
}
protected boolean processRightRight(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetX = targetBounds.x + targetBounds.width;
if (startX <= targetX && targetX <= endX) {
targetBounds.x = myBounds.x + myBounds.width - targetBounds.width;
addVerticalFeedback(feedback, myBounds, targetBounds, false);
@@ -107,6 +123,10 @@ public class ComponentSnapPoint extends SnapPoint {
int startY = myBounds.y - SNAP_SIZE;
int endY = startY + 2 * SNAP_SIZE;
return processTopTop(startY, endY, targetBounds, feedback) || processTopBottom(startY, endY, targetBounds, feedback);
}
protected boolean processTopTop(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetY = targetBounds.y;
if (startY <= targetY && targetY <= endY) {
targetBounds.y = myBounds.y;
@@ -115,7 +135,11 @@ public class ComponentSnapPoint extends SnapPoint {
return true;
}
targetY = targetBounds.y + targetBounds.height;
return false;
}
protected boolean processTopBottom(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetY = targetBounds.y + targetBounds.height;
if (startY <= targetY && targetY <= endY) {
targetBounds.y = myBounds.y - targetBounds.height;
addHorizontalFeedback(feedback, myBounds, targetBounds, true);
@@ -130,6 +154,10 @@ public class ComponentSnapPoint extends SnapPoint {
int startY = myBounds.y + myBounds.height - SNAP_SIZE;
int endY = startY + 2 * SNAP_SIZE;
return processBottomTop(startY, endY, targetBounds, feedback) || processBottomBottom(startY, endY, targetBounds, feedback);
}
protected boolean processBottomTop(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetY = targetBounds.y;
if (startY <= targetY && targetY <= endY) {
targetBounds.y = myBounds.y + myBounds.height;
@@ -138,7 +166,11 @@ public class ComponentSnapPoint extends SnapPoint {
return true;
}
targetY = targetBounds.y + targetBounds.height;
return false;
}
protected boolean processBottomBottom(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int targetY = targetBounds.y + targetBounds.height;
if (startY <= targetY && targetY <= endY) {
targetBounds.y = myBounds.y + myBounds.height - targetBounds.height;
addHorizontalFeedback(feedback, myBounds, targetBounds, false);
@@ -158,19 +190,7 @@ public class ComponentSnapPoint extends SnapPoint {
public void execute(final List<RadComponent> components) throws Exception {
final String attribute;
if (myBeginSide == Side.left && myEndSide == Side.left) {
attribute = "android:layout_alignLeft";
}
else if (myBeginSide == Side.right && myEndSide == Side.right) {
attribute = "android:layout_alignRight";
}
else if (myBeginSide == Side.left && myEndSide == Side.right) {
attribute = "android:layout_toRightOf";
}
else if (myBeginSide == Side.right && myEndSide == Side.left) {
attribute = "android:layout_toLeftOf";
}
else if (myBeginSide == Side.top && myEndSide == Side.top) {
if (myBeginSide == Side.top && myEndSide == Side.top) {
attribute = "android:layout_alignTop";
}
else if (myBeginSide == Side.bottom && myEndSide == Side.bottom) {
@@ -182,6 +202,18 @@ public class ComponentSnapPoint extends SnapPoint {
else if (myBeginSide == Side.bottom && myEndSide == Side.top) {
attribute = "android:layout_above";
}
else if (myBeginSide == Side.left && myEndSide == Side.left) {
attribute = "android:layout_alignLeft";
}
else if (myBeginSide == Side.right && myEndSide == Side.right) {
attribute = "android:layout_alignRight";
}
else if (myBeginSide == Side.left && myEndSide == Side.right) {
attribute = "android:layout_toRightOf";
}
else if (myBeginSide == Side.right && myEndSide == Side.left) {
attribute = "android:layout_toLeftOf";
}
else {
return;
}
@@ -29,7 +29,7 @@ import java.util.List;
* @author Alexander Lobas
*/
public class ContainerSnapPoint extends SnapPoint {
protected Side mySide;
private Side mySide;
public ContainerSnapPoint(RadViewComponent container, boolean horizontal) {
super(container, horizontal);
@@ -48,14 +48,14 @@ public class ContainerSnapPoint extends SnapPoint {
if (mySide == Side.top) {
return "alignParentTop";
}
else if (mySide == Side.left) {
return "alignParentLeft";
}
else if (mySide == Side.bottom) {
return "alignParentBottom";
}
else if (mySide == Side.left) {
return "alignParentLeft";
}
else if (mySide == Side.right) {
return "alignParentTop";
return "alignParentRight";
}
else if (mySide == Side.center_horizontal) {
return "centerHorizontal";
@@ -72,6 +72,10 @@ public class ContainerSnapPoint extends SnapPoint {
mySide = null;
return processBounds(bounds, feedback);
}
protected boolean processBounds(Rectangle bounds, SnapPointFeedbackHost feedback) {
if (myHorizontal) {
return processLeft(bounds, feedback) || processRight(bounds, feedback) || processHorizontalCenter(bounds, feedback);
}
@@ -79,7 +83,7 @@ public class ContainerSnapPoint extends SnapPoint {
return processTop(bounds, feedback) || processBottom(bounds, feedback) || processVerticalCenter(bounds, feedback);
}
private boolean processLeft(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
protected final boolean processLeft(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int startX = myBounds.x - SNAP_SIZE;
int endX = startX + 2 * SNAP_SIZE;
@@ -94,7 +98,7 @@ public class ContainerSnapPoint extends SnapPoint {
return false;
}
private boolean processRight(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
protected final boolean processRight(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int startX = myBounds.x + myBounds.width - SNAP_SIZE;
int endX = startX + 2 * SNAP_SIZE;
@@ -109,7 +113,7 @@ public class ContainerSnapPoint extends SnapPoint {
return false;
}
private boolean processTop(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
protected final boolean processTop(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int startY = myBounds.y - SNAP_SIZE;
int endY = startY + 2 * SNAP_SIZE;
@@ -124,7 +128,7 @@ public class ContainerSnapPoint extends SnapPoint {
return false;
}
private boolean processBottom(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
protected final boolean processBottom(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int startY = myBounds.y + myBounds.height - SNAP_SIZE;
int endY = startY + 2 * SNAP_SIZE;
@@ -139,7 +143,7 @@ public class ContainerSnapPoint extends SnapPoint {
return false;
}
protected boolean processHorizontalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
private boolean processHorizontalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int centerX = myBounds.x + myBounds.width / 2;
int startX = centerX - SNAP_SIZE;
@@ -156,7 +160,7 @@ public class ContainerSnapPoint extends SnapPoint {
return false;
}
protected boolean processVerticalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
private boolean processVerticalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
int centerY = myBounds.y + myBounds.height / 2;
int startY = centerY - SNAP_SIZE;
@@ -17,42 +17,105 @@ package com.intellij.android.designer.designSurface.layout.relative;
import com.intellij.android.designer.model.ModelParser;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.designer.designSurface.feedbacks.TextFeedback;
import com.intellij.designer.model.RadComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.xml.XmlTag;
import java.awt.*;
import java.util.List;
/**
* @author Alexander Lobas
*/
public class ResizeComponentSnapPoint extends ComponentSnapPoint {
public class ResizeComponentSnapPoint extends ResizeSnapPoint {
private Side mySide;
private ComponentSnapPoint mySnapPoint;
public ResizeComponentSnapPoint(RadViewComponent component, boolean horizontal) {
super(component, horizontal);
}
@Override
public void addTextInfo(TextFeedback feedback) {
mySnapPoint.addTextInfo(feedback);
}
@Override
public boolean processBounds(List<RadComponent> components, Rectangle bounds, Side resizeSide, SnapPointFeedbackHost feedback) {
super.processBounds(components, bounds, resizeSide, feedback);
mySide = resizeSide;
if (mySnapPoint == null) {
mySnapPoint = new ComponentSnapPoint(myComponent, myHorizontal) {
@Override
protected boolean processLeftLeft(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.left && super.processLeftLeft(startX, endX, targetBounds, feedback);
}
@Override
protected boolean processLeftRight(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.right && super.processLeftRight(startX, endX, targetBounds, feedback);
}
@Override
protected boolean processRightLeft(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.left && super.processRightLeft(startX, endX, targetBounds, feedback);
}
@Override
protected boolean processRightRight(int startX, int endX, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.right && super.processRightRight(startX, endX, targetBounds, feedback);
}
@Override
protected boolean processTopTop(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.top && super.processTopTop(startY, endY, targetBounds, feedback);
}
@Override
protected boolean processTopBottom(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.bottom && super.processTopBottom(startY, endY, targetBounds, feedback);
}
@Override
protected boolean processBottomTop(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.top && super.processBottomTop(startY, endY, targetBounds, feedback);
}
@Override
protected boolean processBottomBottom(int startY, int endY, Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return mySide == Side.bottom && super.processBottomBottom(startY, endY, targetBounds, feedback);
}
};
}
return mySnapPoint.processBounds(components, bounds, feedback);
}
@Override
public void execute(final List<RadComponent> components) throws Exception {
super.execute(components);
mySnapPoint.execute(components);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
XmlTag tag = ((RadViewComponent)components.get(0)).getTag();
if (myBeginSide == Side.top) {
if (mySide == Side.top) {
ModelParser.deleteAttribute(tag, "android:layout_alignParentTop");
ModelParser.deleteAttribute(tag, "android:layout_marginTop");
}
else if (myBeginSide == Side.bottom) {
else if (mySide == Side.bottom) {
ModelParser.deleteAttribute(tag, "android:layout_alignParentBottom");
ModelParser.deleteAttribute(tag, "android:layout_marginBottom");
}
else if (myBeginSide == Side.left) {
else if (mySide == Side.left) {
ModelParser.deleteAttribute(tag, "android:layout_alignParentLeft");
ModelParser.deleteAttribute(tag, "android:layout_marginLeft");
}
else if (myBeginSide == Side.right) {
else if (mySide == Side.right) {
ModelParser.deleteAttribute(tag, "android:layout_alignParentRight");
ModelParser.deleteAttribute(tag, "android:layout_marginRight");
}
@@ -17,6 +17,7 @@ package com.intellij.android.designer.designSurface.layout.relative;
import com.intellij.android.designer.model.ModelParser;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.designer.designSurface.feedbacks.TextFeedback;
import com.intellij.designer.model.RadComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.xml.XmlTag;
@@ -27,24 +28,41 @@ import java.util.List;
/**
* @author Alexander Lobas
*/
public class ResizeContainerSnapPoint extends ContainerSnapPoint {
public class ResizeContainerSnapPoint extends ResizeSnapPoint {
private Side mySide;
private ContainerSnapPoint mySnapPoint;
public ResizeContainerSnapPoint(RadViewComponent container, boolean horizontal) {
super(container, horizontal);
}
@Override
protected boolean processHorizontalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return false;
public void addTextInfo(TextFeedback feedback) {
mySnapPoint.addTextInfo(feedback);
}
@Override
protected boolean processVerticalCenter(Rectangle targetBounds, SnapPointFeedbackHost feedback) {
return false;
public boolean processBounds(List<RadComponent> components, Rectangle bounds, Side resizeSide, SnapPointFeedbackHost feedback) {
mySide = resizeSide;
if (mySnapPoint == null) {
mySnapPoint = new ContainerSnapPoint(myComponent, myHorizontal) {
@Override
protected boolean processBounds(Rectangle bounds, SnapPointFeedbackHost feedback) {
if (myHorizontal) {
return mySide == Side.left ? processLeft(bounds, feedback) : processRight(bounds, feedback);
}
return mySide == Side.top ? processTop(bounds, feedback) : processBottom(bounds, feedback);
}
};
}
return mySnapPoint.processBounds(components, bounds, feedback);
}
@Override
public void execute(final List<RadComponent> components) throws Exception {
super.execute(components);
mySnapPoint.execute(components);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
@@ -54,18 +72,22 @@ public class ResizeContainerSnapPoint extends ContainerSnapPoint {
if (mySide == Side.top) {
ModelParser.deleteAttribute(tag, "android:layout_alignTop");
ModelParser.deleteAttribute(tag, "android:layout_below");
}
else if (mySide == Side.left) {
ModelParser.deleteAttribute(tag, "android:layout_alignBottom");
ModelParser.deleteAttribute(tag, "android:layout_above");
ModelParser.deleteAttribute(tag, "android:layout_marginTop");
}
else if (mySide == Side.bottom) {
ModelParser.deleteAttribute(tag, "android:layout_alignBottom");
ModelParser.deleteAttribute(tag, "android:layout_above");
ModelParser.deleteAttribute(tag, "android:layout_marginBottom");
}
else if (mySide == Side.left) {
ModelParser.deleteAttribute(tag, "android:layout_alignLeft");
ModelParser.deleteAttribute(tag, "android:layout_toRightOf");
ModelParser.deleteAttribute(tag, "android:layout_marginLeft");
}
else if (mySide == Side.right) {
ModelParser.deleteAttribute(tag, "android:layout_alignRight");
ModelParser.deleteAttribute(tag, "android:layout_toLeftOf");
ModelParser.deleteAttribute(tag, "android:layout_marginRight");
}
}
});
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2012 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.android.designer.designSurface.layout.relative;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.designer.model.RadComponent;
import java.awt.*;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class ResizeSnapPoint extends SnapPoint {
public ResizeSnapPoint(RadViewComponent component, boolean horizontal) {
super(component, horizontal);
}
@Override
public final boolean processBounds(List<RadComponent> components, Rectangle bounds, SnapPointFeedbackHost feedback) {
throw new UnsupportedOperationException();
}
public boolean processBounds(List<RadComponent> components, Rectangle bounds, Side resizeSide, SnapPointFeedbackHost feedback) {
return super.processBounds(components, bounds, feedback);
}
}
@@ -28,7 +28,7 @@ import java.util.List;
/**
* @author Alexander Lobas
*/
public class WrapSizeSnapPoint extends SnapPoint {
public class WrapSizeSnapPoint extends ResizeSnapPoint {
private final Dimension myWrapSize;
public WrapSizeSnapPoint(RadViewComponent component, boolean horizontal, Dimension wrapSize) {
@@ -43,8 +43,8 @@ public class WrapSizeSnapPoint extends SnapPoint {
}
@Override
public boolean processBounds(List<RadComponent> components, Rectangle bounds, SnapPointFeedbackHost feedback) {
super.processBounds(components, bounds, feedback);
public boolean processBounds(List<RadComponent> components, Rectangle bounds, Side resizeSide, SnapPointFeedbackHost feedback) {
super.processBounds(components, bounds, resizeSide, feedback);
if (myHorizontal) {
if (Math.abs(bounds.width - myWrapSize.width) < SNAP_SIZE) {
@@ -21,8 +21,8 @@
*/
package com.wrq.rearranger;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
@@ -31,14 +31,12 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.wrq.rearranger.entry.ClassContentsEntry;
import com.wrq.rearranger.popup.FileStructurePopup;
import com.wrq.rearranger.rearrangement.Emitter;
@@ -48,6 +46,8 @@ import com.wrq.rearranger.rearrangement.Spacer;
import com.wrq.rearranger.ruleinstance.RuleInstance;
import com.wrq.rearranger.settings.RearrangerSettings;
import com.wrq.rearranger.util.CommentUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.dnd.DragSource;
import java.util.List;
@@ -71,9 +71,6 @@ public final class RearrangerActionHandler extends EditorActionHandler {
return tabSize;
}
public void setTabSize(int tabSize) {
RearrangerActionHandler.tabSize = tabSize;
}
// -------------------------- OTHER METHODS --------------------------
public final void execute(final Editor editor, final DataContext context) {
@@ -81,11 +78,14 @@ public final class RearrangerActionHandler extends EditorActionHandler {
return;
}
LOG.debug("enter RearrangerActionHandler.execute()");
final Project project = (Project)context.getData(DataConstants.PROJECT);
final Document document = editor.getDocument();
final PsiFile psiFile = getFile(editor, context);
LOG.debug("suggested tool window = " +
WindowManager.getInstance().suggestParentWindow(project));
if (psiFile == null) {
return;
}
final Project project = PlatformDataKeys.PROJECT.getData(context);
final Document document = editor.getDocument();
LOG.debug("suggested tool window = " + WindowManager.getInstance().suggestParentWindow(project));
LOG.debug("drag source image supported = " + DragSource.isDragImageSupported());
if (!psiFile.getName().endsWith(".java")) {
LOG.debug("not a .java file -- skipping " + psiFile.getName());
@@ -109,15 +109,14 @@ public final class RearrangerActionHandler extends EditorActionHandler {
);
}
private static PsiFile getFile(final Editor editor,
final DataContext context)
{
final Project project = (Project)context.getData(DataConstants.PROJECT);
final Document document = editor.getDocument();
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile virtualFile = fileDocumentManager.getFile(document);
final PsiManager psiManager = PsiManager.getInstance(project);
return psiManager.findFile(virtualFile);
@Nullable
private static PsiFile getFile(final Editor editor, final DataContext context) {
final Project project = PlatformDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
return PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
}
/**
@@ -152,7 +151,7 @@ public final class RearrangerActionHandler extends EditorActionHandler {
wb.whenTrue();
}
catch (InterruptedException e) {
e.printStackTrace();
LOG.warn(e);
}
LOG.debug("end execute");
}
@@ -162,10 +161,11 @@ public final class RearrangerActionHandler extends EditorActionHandler {
return file != null && file.isWritable();
}
public final void rearrangeDocument(final Project project,
final PsiFile psiFile,
final RearrangerSettings settings,
final Document document)
@SuppressWarnings("MethodMayBeStatic")
public final void rearrangeDocument(@NotNull final Project project,
@NotNull final PsiFile psiFile,
@NotNull final RearrangerSettings settings,
@NotNull final Document document)
{
LOG.debug("enter rearrangeDocument");
new CommentUtil(settings); // create CommentUtil singleton
@@ -45,10 +45,7 @@ import java.util.*;
* Corresponds to a method in the source file.
* Contains structures and logic to handle related method rearrangement.
*/
public class MethodEntry
extends ClassContentsEntry
implements RelatableEntry
{
public class MethodEntry extends ClassContentsEntry implements RelatableEntry {
// ------------------------------ FIELDS ------------------------------
private static final Logger LOG = Logger.getInstance("#" + MethodEntry.class.getName());
@@ -716,9 +713,7 @@ public class MethodEntry
}
}
public void determineSettersAndMethodCalls(RearrangerSettings settings,
List<ClassContentsEntry> contents)
{
public void determineSettersAndMethodCalls(RearrangerSettings settings, List<ClassContentsEntry> contents) {
if (isGetter()) {
if (settings.isKeepGettersSettersTogether()) {
determineSetter(contents, settings); // link getters/setters via correspondingGetterSetter entries
@@ -26,9 +26,7 @@ import com.wrq.rearranger.settings.CommentRule;
import java.util.List;
/** Used to store a generated comment which is emitted based on whether it matches preceding rules. */
public class PrecedingCommentRuleInstance
extends CommentRuleInstance
{
public class PrecedingCommentRuleInstance extends CommentRuleInstance {
public PrecedingCommentRuleInstance(final CommentRule commentRule) {
super(commentRule);
@@ -62,22 +62,6 @@ public class CommentFillString {
this.fillString = fillString;
}
public boolean isUseProjectWidthForFill() {
return useProjectWidthForFill;
}
public void setUseProjectWidthForFill(boolean useProjectWidthForFill) {
this.useProjectWidthForFill = useProjectWidthForFill;
}
public int getFillWidth() {
return fillWidth;
}
public void setFillWidth(int fillWidth) {
this.fillWidth = fillWidth;
}
public final boolean equals(final Object object) {
if (!(object instanceof CommentFillString)) return false;
final CommentFillString c = (CommentFillString)object;
@@ -111,8 +95,8 @@ public class CommentFillString {
public final void writeExternal(final Element me) {
me.setAttribute("fillString", CommentRule.escape(fillString));
me.setAttribute("useProjectWidthForFill", "" + useProjectWidthForFill);
me.setAttribute("fillWidth", "" + fillWidth);
me.setAttribute("useProjectWidthForFill", String.valueOf(useProjectWidthForFill));
me.setAttribute("fillWidth", String.valueOf(fillWidth));
}
public final JPanel getCommentFillStringPanel() {
@@ -180,7 +164,7 @@ public class CommentFillString {
String fs = fillString;
if (fs.length() == 0) fs = " ";
final int length = fs.length();
StringBuffer sb = new StringBuffer(length * (length + 1) / 2 + length * 3);
StringBuilder sb = new StringBuilder(length * (length + 1) / 2 + length * 3);
sb.append('(');
sb.append(RegexUtil.escape(fs));
sb.append(")*");
@@ -24,26 +24,26 @@ package com.wrq.rearranger.settings.atomicAttributes;
import com.wrq.rearranger.ModifierConstants;
import org.jdom.Element;
public final class InitToAnonClassAttribute extends AndNotAttribute {
public final class InitialisedByAnonymousClassAttribute extends AndNotAttribute {
// -------------------------- STATIC METHODS --------------------------
public static InitToAnonClassAttribute readExternal(final Element item) {
final InitToAnonClassAttribute result = new InitToAnonClassAttribute();
public static InitialisedByAnonymousClassAttribute readExternal(final Element item) {
final InitialisedByAnonymousClassAttribute result = new InitialisedByAnonymousClassAttribute();
result.loadAttributes(item.getChild(result.getElementName()));
return result;
}
// --------------------------- CONSTRUCTORS ---------------------------
public InitToAnonClassAttribute() {
public InitialisedByAnonymousClassAttribute() {
super("initialized to anonymous class", ModifierConstants.INIT_TO_ANON_CLASS);
}
// -------------------------- OTHER METHODS --------------------------
public final /*InitToAnonClassAttribute*/AtomicAttribute deepCopy() {
final InitToAnonClassAttribute result = new InitToAnonClassAttribute();
final InitialisedByAnonymousClassAttribute result = new InitialisedByAnonymousClassAttribute();
result.value = value;
result.invert = invert;
return result;
@@ -25,9 +25,7 @@ import com.wrq.rearranger.ModifierConstants;
import org.jdom.Element;
/** Routines to handle a static initializer method. */
public final class InitializerAttribute
extends AndNotAttribute
{
public final class InitializerAttribute extends AndNotAttribute {
// -------------------------- STATIC METHODS --------------------------
@@ -26,9 +26,7 @@ import org.jdom.Element;
import java.lang.reflect.Modifier;
/** Routines to handle the 'static' modifier. */
public final class StaticAttribute
extends AndNotAttribute
{
public final class StaticAttribute extends AndNotAttribute {
// -------------------------- STATIC METHODS --------------------------
@@ -23,7 +23,7 @@ package com.wrq.rearranger.settings.attributeGroups;
import com.intellij.psi.PsiField;
import com.wrq.rearranger.entry.RangeEntry;
import com.wrq.rearranger.settings.atomicAttributes.InitToAnonClassAttribute;
import com.wrq.rearranger.settings.atomicAttributes.InitialisedByAnonymousClassAttribute;
import com.wrq.rearranger.settings.atomicAttributes.TransientAttribute;
import com.wrq.rearranger.settings.atomicAttributes.TypeAttribute;
import com.wrq.rearranger.settings.atomicAttributes.VolatileAttribute;
@@ -40,17 +40,17 @@ public final class FieldAttributes extends ItemAttributes {
// ------------------------------ FIELDS ------------------------------
private InitToAnonClassAttribute initToAnonClassAttr;
private TransientAttribute transientAttr;
private VolatileAttribute volatileAttr;
private TypeAttribute typeAttr;
private InitialisedByAnonymousClassAttribute myInitialisedByAnonymousClassAttr;
private TransientAttribute transientAttr;
private VolatileAttribute volatileAttr;
private TypeAttribute typeAttr;
// -------------------------- STATIC METHODS --------------------------
public static /*FieldAttributes*/AttributeGroup readExternal(final Element item) {
final FieldAttributes result = new FieldAttributes();
CommonAttributes.readExternal(result, item);
result.initToAnonClassAttr = InitToAnonClassAttribute.readExternal(item);
result.myInitialisedByAnonymousClassAttr = InitialisedByAnonymousClassAttribute.readExternal(item);
result.transientAttr = TransientAttribute.readExternal(item);
result.volatileAttr = VolatileAttribute.readExternal(item);
result.typeAttr = TypeAttribute.readExternal(item);
@@ -60,7 +60,7 @@ public final class FieldAttributes extends ItemAttributes {
// --------------------------- CONSTRUCTORS ---------------------------
public FieldAttributes() {
initToAnonClassAttr = new InitToAnonClassAttribute();
myInitialisedByAnonymousClassAttr = new InitialisedByAnonymousClassAttribute();
transientAttr = new TransientAttribute();
volatileAttr = new VolatileAttribute();
typeAttr = new TypeAttribute();
@@ -68,8 +68,8 @@ public final class FieldAttributes extends ItemAttributes {
// --------------------- GETTER / SETTER METHODS ---------------------
public InitToAnonClassAttribute getInitToAnonClassAttr() {
return initToAnonClassAttr;
public InitialisedByAnonymousClassAttribute getInitialisedByAnonymousClassAttr() {
return myInitialisedByAnonymousClassAttr;
}
private TransientAttribute getTransientAttr() {
@@ -100,8 +100,8 @@ public final class FieldAttributes extends ItemAttributes {
else {
sb.append("fields");
}
if (initToAnonClassAttr.isValue()) {
if (!initToAnonClassAttr.isInvert()) {
if (myInitialisedByAnonymousClassAttr.isValue()) {
if (!myInitialisedByAnonymousClassAttr.isInvert()) {
sb.append(" which are initialized to an anonymous class");
}
else {
@@ -109,14 +109,14 @@ public final class FieldAttributes extends ItemAttributes {
}
}
if (getNameAttribute().isMatch()) {
if (initToAnonClassAttr.isValue()) {
if (myInitialisedByAnonymousClassAttr.isValue()) {
sb.append(" and");
}
sb.append(' ');
sb.append(getNameAttribute().getDescriptiveString());
}
if (typeAttr.isMatch()) {
if (getNameAttribute().isMatch() || initToAnonClassAttr.isValue()) {
if (getNameAttribute().isMatch() || myInitialisedByAnonymousClassAttr.isValue()) {
sb.append(" and");
}
sb.append(' ');
@@ -135,7 +135,7 @@ public final class FieldAttributes extends ItemAttributes {
public final /*FieldAttributes*/AttributeGroup deepCopy() {
final FieldAttributes result = new FieldAttributes();
deepCopyCommonItems(result);
result.initToAnonClassAttr = (InitToAnonClassAttribute)initToAnonClassAttr.deepCopy();
result.myInitialisedByAnonymousClassAttr = (InitialisedByAnonymousClassAttribute)myInitialisedByAnonymousClassAttr.deepCopy();
result.transientAttr = (TransientAttribute)transientAttr.deepCopy();
result.volatileAttr = (VolatileAttribute)volatileAttr.deepCopy();
result.typeAttr = (TypeAttribute)typeAttr.deepCopy();
@@ -146,7 +146,7 @@ public final class FieldAttributes extends ItemAttributes {
public final void writeExternal(@NotNull final Element parent) {
final Element child = new Element("Field");
writeExternalCommonAttributes(child);
initToAnonClassAttr.appendAttributes(child);
myInitialisedByAnonymousClassAttr.appendAttributes(child);
transientAttr.appendAttributes(child);
volatileAttr.appendAttributes(child);
typeAttr.appendAttributes(child);
@@ -161,7 +161,7 @@ public final class FieldAttributes extends ItemAttributes {
return super.equals(fa) &&
transientAttr.equals(fa.transientAttr) &&
volatileAttr.equals(fa.volatileAttr) &&
initToAnonClassAttr.equals(fa.initToAnonClassAttr) &&
myInitialisedByAnonymousClassAttr.equals(fa.myInitialisedByAnonymousClassAttr) &&
typeAttr.equals(fa.typeAttr);
}
@@ -191,7 +191,7 @@ public final class FieldAttributes extends ItemAttributes {
constraints.insets = new Insets(5, 0, 0, 0);
constraints.gridx = 0;
constraints.gridy++;
plPanel.add(getInitToAnonClassAttr().getAndNotPanel(), constraints);
plPanel.add(getInitialisedByAnonymousClassAttr().getAndNotPanel(), constraints);
constraints.gridy++;
plPanel.add(getNameAttribute().getStringPanel(), constraints);
constraints.gridy++;
@@ -206,7 +206,7 @@ public final class FieldAttributes extends ItemAttributes {
public boolean isMatch(@NotNull RangeEntry rangeEntry) {
return rangeEntry.getEnd() instanceof PsiField &&
initToAnonClassAttr.isMatch(rangeEntry.getModifiers()) &&
myInitialisedByAnonymousClassAttr.isMatch(rangeEntry.getModifiers()) &&
transientAttr.isMatch(rangeEntry.getModifiers()) &&
volatileAttr.isMatch(rangeEntry.getModifiers()) &&
typeAttr.isMatch(rangeEntry.getType()) &&
@@ -629,8 +629,7 @@ public final class MethodAttributes
// Start Methods of Interface IRule
public final boolean isMatch(@NotNull RangeEntry entry) {
final boolean result = (entry.getEnd() instanceof PsiMethod ||
entry.getEnd() instanceof PsiClassInitializer) &&
final boolean result = (entry.getEnd() instanceof PsiMethod || entry.getEnd() instanceof PsiClassInitializer) &&
super.isMatch(entry) &&
abstractAttr.isMatch(entry.getModifiers()) &&
overriddenAttr.isMatch(entry.getModifiers()) &&
@@ -42,7 +42,7 @@ public final class ModifierUtils {
final String m = st.nextToken();
for (int i = 1; i != 0; i <<= 1) {
if (Modifier.toString(i).equals(m)) {
mask = mask | i;
mask |= i;
break;
}
}
@@ -30,6 +30,7 @@ import com.wrq.rearranger.settings.attributeGroups.FieldAttributes
import com.wrq.rearranger.settings.attributeGroups.MethodAttributes
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
import com.wrq.rearranger.settings.CommentRule
/** JUnit tests for the rearranger plugin. */
class RearrangerTest extends LightCodeInsightFixtureTestCase {
@@ -100,83 +101,61 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase {
}
}
// public final void testAnonClassInit() throws Exception {
// configureByFile("/com/wrq/rearranger/RearrangementTest7.java");
// final PsiFile file = getFile();
// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
// final FieldAttributes fa;
// fa = new FieldAttributes();
// fa.getInitToAnonClassAttr().setValue(true);
// rs.addItem(fa, 0);
// final RearrangerActionHandler rah = new RearrangerActionHandler();
// rah.rearrangeDocument(getProject(), file, rs, doc);
// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult7.java");
// }
//
// public final void testNameMatch() throws Exception {
// configureByFile("/com/wrq/rearranger/RearrangementTest.java");
// final PsiFile file = getFile();
// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
// final FieldAttributes fa;
// fa = new FieldAttributes();
// fa.getNameAttr().setMatch(true);
// fa.getNameAttr().setExpression(".*5");
// rs.addItem(fa, 0);
// final MethodAttributes ma = new MethodAttributes();
// ma.getNameAttr().setMatch(true);
// ma.getNameAttr().setExpression(".*2");
// rs.addItem(ma, 1);
// final RearrangerActionHandler rah = new RearrangerActionHandler();
// rah.rearrangeDocument(getProject(), file, rs, doc);
// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult8.java");
// }
//
// public final void testStaticInitializer() throws Exception {
// configureByFile("/com/wrq/rearranger/RearrangementTest8.java");
// final PsiFile file = getFile();
// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
// final MethodAttributes ma;
// ma = new MethodAttributes();
// ma.getStaticInitAttr().setValue(true);
// rs.addItem(ma, 0);
// final RearrangerActionHandler rah = new RearrangerActionHandler();
// rah.rearrangeDocument(getProject(), file, rs, doc);
// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult8A.java");
// }
//
// public final void testAlphabetizingGSMethods() throws Exception {
// configureByFile("/com/wrq/rearranger/RearrangementTest.java");
// final PsiFile file = getFile();
// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
// final MethodAttributes ma;
// ma = new MethodAttributes();
// ma.setGetterSetterMethodType(true);
// ma.setOtherMethodType(true);
// ma.setConstructorMethodType(false);
// ma.getSortAttr().setByName(true);
// rs.addItem(ma, 0);
// rs.setKeepGettersSettersTogether(false);
// final RearrangerActionHandler rah = new RearrangerActionHandler();
// rah.rearrangeDocument(getProject(), file, rs, doc);
// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult9.java");
// }
//
// public final void testSimpleComment() throws Exception {
// configureByFile("/com/wrq/rearranger/RearrangementTest.java");
// final PsiFile file = getFile();
// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
// final FieldAttributes fa = new FieldAttributes();
// fa.getPlAttr().setPlPublic(true);
// rs.addItem(fa, 0);
// final CommentRule c = new CommentRule();
// c.setCommentText("// simple comment **********");
// c.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE);
// rs.addItem(c, 1);
// final RearrangerActionHandler rah = new RearrangerActionHandler();
// rah.rearrangeDocument(getProject(), file, rs, doc);
// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult10.java");
// }
//
public final void testAnonClassInit() throws Exception {
doTest('RearrangementTest7', 'RearrangementResult7') {
def attributes = new FieldAttributes()
attributes.initialisedByAnonymousClassAttr.value = true
mySettings.addItem(attributes, 0)
}
}
public final void testNameMatch() throws Exception {
doTest('RearrangementTest', 'RearrangementResult8') {
def fieldAttributes = new FieldAttributes()
fieldAttributes.nameAttribute.match = true
fieldAttributes.nameAttribute.expression = '.*5'
mySettings.addItem(fieldAttributes, 0)
def methodAttributes = new MethodAttributes()
methodAttributes.nameAttribute.match = true
methodAttributes.nameAttribute.expression = '.*2'
mySettings.addItem(methodAttributes, 1)
}
}
public final void testStaticInitializer() throws Exception {
doTest('RearrangementTest8', 'RearrangementResult8A') {
def methodAttributes = new MethodAttributes()
methodAttributes.staticAttribute.value = true
mySettings.addItem(methodAttributes, 0)
}
}
public final void testAlphabetizingGSMethods() throws Exception {
doTest('RearrangementTest', 'RearrangementResult9') {
def attributes = new MethodAttributes()
attributes.getterSetterMethodType = true
attributes.otherMethodType = true
attributes.constructorMethodType = false
attributes.sortOptions.byName = true
mySettings.addItem(attributes, 0)
mySettings.keepGettersSettersTogether = false
}
}
public final void testSimpleComment() throws Exception {
doTest('RearrangementTest', 'RearrangementResult10') {
def attributes = new FieldAttributes()
attributes.protectionLevelAttributes.plPublic = true
mySettings.addItem(attributes, 0)
def comment = new CommentRule()
comment.commentText = '// simple comment **********'
comment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE
mySettings.addItem(comment, 1)
}
}
// /**
// * Delete old comment and insert (identical) new one. This tests proper identification and deletion of old
// * comments.
@@ -5,6 +5,7 @@ package com.wrq.rearranger;
/** public class comments. */
public class RearrangementTest {
/** field 1. */
private int field1;
private int field2;
@@ -11,8 +11,8 @@ public class RearrangementTest {
/** field 1. */
private int field1;
private int field2;
final int field5 = 5;
protected int field6 = 6;
final int field5 = 5;
protected int field6 = 6;
/** method 1 comment. */
void method1() {
@@ -7,6 +7,7 @@ package com.wrq.rearranger;
public class RearrangementTest {
public static final int field3 = 3;
public static final int field4 = 4;
/** field 1. */
private int field1;
private int field2;
@@ -5,6 +5,7 @@ package com.wrq.rearranger;
/** public class comments. */
public class RearrangementTest {
/** field 1. */
private int field1;
private int field2;
@@ -9,6 +9,7 @@ public class RearrangementTest {
NoRearrangementTest() {
// constructor body
}
/** field 1. */
private int field1;
private int field2;
@@ -9,6 +9,7 @@ class AnotherOuterClass {
/** public class comments. */
public class RearrangementTest {
/** field 1. */
private int field1;
private int field2;
@@ -5,7 +5,7 @@ package com.wrq.rearranger;
/** public class comments. */
public class RearrangementTest {
final int field5 = 5;
final int field5 = 5;
/** method 2 comment. */
public void method2() {
@@ -5,6 +5,7 @@ package com.wrq.rearranger;
/** public class comments. */
public class RearrangementTest {
/** field 1. */
private int field1;
private int field2;
@@ -22,8 +22,8 @@ import java.awt.*;
* @author Alexander Lobas
*/
public class AlphaFeedback extends JComponent {
private static final AlphaComposite myComposite1 = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3f);
private static final AlphaComposite myComposite2 = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.6f);
protected static final AlphaComposite myComposite1 = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3f);
protected static final AlphaComposite myComposite2 = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.6f);
private final Color myColor;
private final Color myBorderColor;