Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sergey Rieder
2013-10-31 20:23:36 +04:00
14 changed files with 211 additions and 44 deletions
@@ -23,13 +23,13 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
/**
* Is intended to test formatting in editor behavior, i.e. check how formatting affects things like caret position, selection etc.
*
* Is intended to test formatting in editor behavior, i.e. check how formatting affects things like caret position, selection etc.
*
* @author Denis Zhdanov
* @since 6/1/11 6:17 PM
*/
public class JavaFormatterInEditorTest extends LightPlatformCodeInsightTestCase {
public void testCaretPositionOnLongLineWrapping() throws IOException {
// Inspired by IDEA-70242
getCurrentCodeStyleSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -39,7 +39,7 @@ public class JavaFormatterInEditorTest extends LightPlatformCodeInsightTestCase
"\n" +
"class <caret>Test {\n" +
"}",
"import static java.util.concurrent\n" +
" .atomic.AtomicInteger.*;\n" +
"\n" +
@@ -47,10 +47,59 @@ public class JavaFormatterInEditorTest extends LightPlatformCodeInsightTestCase
"}"
);
}
public void testCaretPositionPreserved_WhenOnSameLineWithWhiteSpacesOnly() throws IOException {
String text = "class Test {\n" +
" void test() {\n" +
" <caret>\n" +
" }\n" +
"}";
doTest(text, text);
String after = "class Test {\n" +
" void test() {\n" +
" <caret> \n" +
" }\n" +
"}";
doTest(text, after);
}
public void testCaretPositionPreserved_WhenSomeFormattingNeeded() throws IOException {
String before = "public class Test {\n" +
" int a;\n" +
" \n" +
" public static void main(String[] args) {\n" +
" <caret>\n" +
" }\n" +
"\n" +
" static final long j = 2;\n" +
"}";
String after = "public class Test {\n" +
" int a;\n" +
"\n" +
" public static void main(String[] args) {\n" +
" <caret>\n" +
" }\n" +
"\n" +
" static final long j = 2;\n" +
"}";
doTest(before, after);
before = "public class Test {\n" +
" int a;\n" +
" \n" +
" public static void main(String[] args) {\n" +
" <caret> \n" +
" }\n" +
"\n" +
" static final long j = 2;\n" +
"}";
doTest(before, after);
}
public void doTest(@NotNull String before, @NotNull String after) throws IOException {
configureFromFileText(getTestName(false) + ".java", before);
CodeStyleManager.getInstance(getProject()).reformatText(getFile(), 0, getEditor().getDocument().getTextLength());
checkResultByText(after);
}
}
}
@@ -181,7 +181,7 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
// So, if 'virtual space in editor' is enabled, we save target visual column. Caret indent is ensured otherwise
int visualColumnToRestore = -1;
String caretIndentToRestore = null;
RangeMarker caretRangeMarker = null;
RangeMarker beforeCaretRangeMarker = null;
if (editor != null) {
Document document = editor.getDocument();
@@ -202,7 +202,7 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
if (fixCaretPosition) {
visualColumnToRestore = editor.getCaretModel().getVisualPosition().column;
caretIndentToRestore = document.getText(TextRange.create(lineStartOffset, caretOffset));
caretRangeMarker = document.createRangeMarker(lineStartOffset, caretOffset);
beforeCaretRangeMarker = document.createRangeMarker(0, lineStartOffset);
}
}
@@ -261,11 +261,11 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
}
}
else {
if (caretRangeMarker == null || !caretRangeMarker.isValid() || caretIndentToRestore == null) {
if (beforeCaretRangeMarker == null || !beforeCaretRangeMarker.isValid() || caretIndentToRestore == null) {
return;
}
int offset = caretRangeMarker.getStartOffset();
caretRangeMarker.dispose();
int offset = beforeCaretRangeMarker.getEndOffset();
beforeCaretRangeMarker.dispose();
if (editor.getCaretModel().getVisualPosition().column == visualColumnToRestore) {
return;
}
@@ -484,10 +484,10 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
* </ol>
* </pre>
* <p/>
* This method inserts that dummy comment (fallback to identifier <code>xxx</code>, see {@link CodeStyleManagerImpl#createDummy(PsiFile)})
* This method inserts that dummy comment (fallback to identifier <code>xxx</code>, see {@link CodeStyleManagerImpl#createDummy(PsiFile)})
* if necessary (if target line contains white space symbols only).
* <p/>
* <b>Note:</b> it's expected that the whole white space region that contains given offset is processed in a way that all
* {@link RangeMarker range markers} registered for the given offset are expanded to the whole white space region.
* E.g. there is a possible case that particular range marker serves for defining formatting range, hence, its start/end offsets
@@ -109,6 +109,8 @@ public class HgLogProvider implements VcsLogProvider {
repository.update();
Collection<HgNameWithHashInfo> branches = repository.getBranches();
Collection<HgNameWithHashInfo> bookmarks = repository.getBookmarks();
Collection<HgNameWithHashInfo> tags = repository.getTags();
Collection<HgNameWithHashInfo> localTags = repository.getLocalTags();
Collection<VcsRef> refs = new ArrayList<VcsRef>(branches.size() + bookmarks.size());
@@ -123,17 +125,16 @@ public class HgLogProvider implements VcsLogProvider {
if (currentRevision != null) { // null => fresh repository
refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(currentRevision), "HEAD", HgRefManager.HEAD, root));
}
//refs.addAll(readTags(root));
for (HgNameWithHashInfo tagInfo : tags) {
refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(tagInfo.getHash()), tagInfo.getName(), HgRefManager.TAG, root));
}
for (HgNameWithHashInfo localTagInfo : localTags) {
refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(localTagInfo.getHash()), localTagInfo.getName(),
HgRefManager.LOCAL_TAG, root));
}
return refs;
}
//todo implement
/* @NotNull
private Collection<? extends VcsRef> readTags(@NotNull VirtualFile root) throws VcsException {
return Collections.emptyList();
}*/
@NotNull
@Override
public VcsKey getSupportedVcs() {
@@ -38,11 +38,13 @@ public class HgRefManager implements VcsLogRefManager {
private static final Color BRANCH_COLOR = new JBColor(new Color(0x75eec7), new Color(0x0D6D4F));
private static final Color BOOKMARK_COLOR = new JBColor(new Color(0xbcbcfc), new Color(0xbcbcfc).darker().darker());
private static final Color TAG_COLOR = JBColor.WHITE;
private static final Color LOCAL_TAG_COLOR = JBColor.CYAN;
public static final VcsRefType HEAD = new SimpleRefType(true, HEAD_COLOR);
public static final VcsRefType BRANCH = new SimpleRefType(true, BRANCH_COLOR);
public static final VcsRefType BOOKMARK = new SimpleRefType(true, BOOKMARK_COLOR);
public static final VcsRefType TAG = new SimpleRefType(false, TAG_COLOR);
public static final VcsRefType LOCAL_TAG = new SimpleRefType(false, LOCAL_TAG_COLOR);
// first has the highest priority
private static final List<VcsRefType> REF_TYPE_PRIORITIES = Arrays.asList(HEAD, BRANCH, BOOKMARK, TAG);
@@ -103,7 +105,6 @@ public class HgRefManager implements VcsLogRefManager {
@NotNull
@Override
public List<RefGroup> group(Collection<VcsRef> refs) {
// TODO group non-tracking refs into remotes
return ContainerUtil.map(sort(refs), new Function<VcsRef, RefGroup>() {
@Override
public RefGroup fun(final VcsRef ref) {
@@ -36,19 +36,25 @@ public class HgRepoInfo {
@Nullable private String myCurrentBookmark = null;
@NotNull private Set<HgNameWithHashInfo> myBranches = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myBookmarks = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myTags = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myLocalTags = Collections.emptySet();
public HgRepoInfo(@NotNull String currentBranch,
@Nullable String currentRevision,
@NotNull Repository.State state,
@NotNull Collection<HgNameWithHashInfo> branches,
@NotNull Collection<HgNameWithHashInfo> bookmarks,
@Nullable String currentBookmark) {
@Nullable String currentBookmark,
@NotNull Collection<HgNameWithHashInfo> tags,
@NotNull Collection<HgNameWithHashInfo> localTags) {
myCurrentBranch = currentBranch;
myCurrentRevision = currentRevision;
myState = state;
myBranches = new LinkedHashSet<HgNameWithHashInfo>(branches);
myBookmarks = new LinkedHashSet<HgNameWithHashInfo>(bookmarks);
myCurrentBookmark = currentBookmark;
myTags = new LinkedHashSet<HgNameWithHashInfo>(tags);
myLocalTags = new LinkedHashSet<HgNameWithHashInfo>(localTags);
}
@NotNull
@@ -66,6 +72,16 @@ public class HgRepoInfo {
return myBookmarks;
}
@NotNull
public Collection<HgNameWithHashInfo> getTags() {
return myTags;
}
@NotNull
public Collection<HgNameWithHashInfo> getLocalTags() {
return myLocalTags;
}
@Nullable
public String getCurrentRevision() {
return myCurrentRevision;
@@ -94,13 +110,15 @@ public class HgRepoInfo {
if (myCurrentBookmark != null ? !myCurrentBookmark.equals(info.myCurrentBookmark) : info.myCurrentBookmark != null) return false;
if (!myBranches.equals(info.myBranches)) return false;
if (!myBookmarks.equals(info.myBookmarks)) return false;
if (!myTags.equals(info.myTags)) return false;
if (!myLocalTags.equals(info.myLocalTags)) return false;
return true;
}
@Override
public int hashCode() {
return Objects.hashCode(myCurrentBranch, myCurrentRevision, myCurrentBookmark, myState, myBranches, myBookmarks);
return Objects.hashCode(myCurrentBranch, myCurrentRevision, myCurrentBookmark, myState, myBranches, myBookmarks, myTags, myLocalTags);
}
@Override
@@ -44,6 +44,12 @@ public interface HgRepository extends Repository {
@NotNull
Collection<HgNameWithHashInfo> getBookmarks();
@NotNull
Collection<HgNameWithHashInfo> getTags();
@NotNull
Collection<HgNameWithHashInfo> getLocalTags();
@Nullable
String getCurrentBookmark();
@@ -36,6 +36,8 @@ public class HgRepositoryFiles {
public static final String MERGE = "merge";
public static final String BRANCH = "branch";
public static final String BOOKMARKS = "bookmarks";
public static final String LOCAL_TAGS = "localtags";
public static final String TAGS = ".hgtags";
public static final String CURRENT_BOOKMARK = "bookmarks.current";
public static final String CONFIG_HGRC = "hgrc";
@@ -45,6 +47,8 @@ public class HgRepositoryFiles {
@NotNull private final String myMergePath;
@NotNull private final String myBranchPath;
@NotNull private final String myBookmarksPath;
@NotNull private final String myTagsPath;
@NotNull private final String myLocalTagsPath;
@NotNull private final String myCurrentBookmarkPath;
@NotNull private final String myConfigHgrcPath;
@@ -59,6 +63,8 @@ public class HgRepositoryFiles {
myBranchPath = hgDir.getPath() + slash(BRANCH);
myMergePath = hgDir.getPath() + slash(MERGE);
myBookmarksPath = hgDir.getPath() + slash(BOOKMARKS);
myTagsPath = hgDir.getParent().getPath() + slash(TAGS);
myLocalTagsPath = hgDir.getPath() + slash(LOCAL_TAGS);
myCurrentBookmarkPath = hgDir.getPath() + slash(CURRENT_BOOKMARK);
myConfigHgrcPath = hgDir.getPath() + slash(CONFIG_HGRC);
}
@@ -104,4 +110,12 @@ public class HgRepositoryFiles {
public boolean isConfigHgrcFile(String filePath) {
return filePath.equals(myConfigHgrcPath);
}
public boolean isTagsFile(String filePath) {
return filePath.equals(myTagsPath);
}
public boolean isLocalTagsFile(String filePath) {
return filePath.equals(myLocalTagsPath);
}
}
@@ -105,6 +105,18 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
return myInfo.getCurrentBookmark();
}
@NotNull
@Override
public Collection<HgNameWithHashInfo> getTags() {
return myInfo.getTags();
}
@NotNull
@Override
public Collection<HgNameWithHashInfo> getLocalTags() {
return myInfo.getLocalTags();
}
@NotNull
@Override
public HgConfig getRepositoryConfig() {
@@ -142,7 +154,7 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
//in GitRepositoryImpl there are temporary state object for reader fields storing! Todo Check;
return
new HgRepoInfo(myReader.readCurrentBranch(), myReader.readCurrentRevision(), myReader.readState(), myReader.readBranches(),
myReader.readBookmarks(), myReader.readCurrentBookmark());
myReader.readBookmarks(), myReader.readCurrentBookmark(), myReader.readTags(), myReader.readLocalTags());
}
public void updateConfig() {
@@ -45,6 +45,8 @@ public class HgRepositoryReader {
@NotNull private final File myCurrentBranch; // .hg/branch
@NotNull private final File myBookmarksFile; //.hg/bookmarks
@NotNull private final File myCurrentBookmark; //.hg/bookmarks.current
@NotNull private final File myTagsFile; //.hgtags - not in .hg directory!!!
@NotNull private final File myLocalTagsFile; // .hg/localtags
@NotNull private final VcsLogObjectsFactory myVcsObjectsFactory;
public HgRepositoryReader(@NotNull File hgDir) {
@@ -56,6 +58,8 @@ public class HgRepositoryReader {
myCurrentBranch = new File(myHgDir, "branch");
myBookmarksFile = new File(myHgDir, "bookmarks");
myCurrentBookmark = new File(myHgDir, "bookmarks.current");
myLocalTagsFile = new File(myHgDir, "localtags");
myTagsFile = new File(myHgDir.getParentFile(), ".hgtags");
myVcsObjectsFactory = ServiceManager.getService(VcsLogObjectsFactory.class);
}
@@ -123,19 +127,34 @@ public class HgRepositoryReader {
@NotNull
public Collection<HgNameWithHashInfo> readBookmarks() {
// .hg/bookmarks contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark
Set<HgNameWithHashInfo> bookmarks = new HashSet<HgNameWithHashInfo>();
if (!myBookmarksFile.exists()) {
return bookmarks;
return readReference(myBookmarksFile);
}
@NotNull
public Collection<HgNameWithHashInfo> readTags() {
return readReference(myTagsFile);
}
@NotNull
public Collection<HgNameWithHashInfo> readLocalTags() {
return readReference(myLocalTagsFile);
}
@NotNull
private Collection<HgNameWithHashInfo> readReference(@NotNull File fileWithReferences) {
// files like .hg/bookmarks which contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark
Set<HgNameWithHashInfo> refs = new HashSet<HgNameWithHashInfo>();
if (!fileWithReferences.exists()) {
return refs;
}
String[] bookmarksWithHeads = RepositoryUtil.tryLoadFile(myBookmarksFile).split("\n");
for (String str : bookmarksWithHeads) {
String[] namesWithHashes = RepositoryUtil.tryLoadFile(fileWithReferences).split("\n");
for (String str : namesWithHashes) {
Matcher matcher = HASH_NAME.matcher(str);
if (matcher.matches()) {
bookmarks.add(new HgNameWithHashInfo(matcher.group(2), myVcsObjectsFactory.createHash(matcher.group(1))));
refs.add(new HgNameWithHashInfo(matcher.group(2), myVcsObjectsFactory.createHash(matcher.group(1))));
}
}
return bookmarks;
return refs;
}
@Nullable
@@ -92,6 +92,8 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
boolean branchFileChanged = false;
boolean mergeFileChanged = false;
boolean bookmarksFileChanged = false;
boolean tagsFileChanged = false;
boolean localTagsFileChanged = false;
boolean currentBookmarkFileChanged = false;
boolean configHgrcChanged = false;
for (VFileEvent event : events) {
@@ -112,6 +114,12 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
else if (myRepositoryFiles.isBookmarksFile(filePath)) {
bookmarksFileChanged = true;
}
else if (myRepositoryFiles.isTagsFile(filePath)) {
tagsFileChanged = true;
}
else if (myRepositoryFiles.isLocalTagsFile(filePath)) {
localTagsFileChanged = true;
}
else if (myRepositoryFiles.isCurrentBookmarksFile(filePath)) {
currentBookmarkFileChanged = true;
}
@@ -121,7 +129,13 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
}
}
if (branchHeadsChanged || branchFileChanged || mergeFileChanged || bookmarksFileChanged || currentBookmarkFileChanged) {
if (branchHeadsChanged ||
branchFileChanged ||
mergeFileChanged ||
bookmarksFileChanged ||
currentBookmarkFileChanged ||
tagsFileChanged ||
localTagsFileChanged) {
myUpdateQueue.add(Void.TYPE);
}
if (configHgrcChanged) {
+2
View File
@@ -0,0 +1,2 @@
25e44c95b2612e3cdf29a704dabf82c77066cb67 tag1
c4e6b94abdf018515b2300698e3eb9b441d53619 tag2
@@ -0,0 +1 @@
25e44c95b2612e3cdf29a704dabf82c77066cb67 localTag
@@ -40,7 +40,7 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest {
super.setUp();
File hgDir = new File(myRepository.getPath(), ".hg");
assertTrue(hgDir.exists());
createBranches();
createBranchesAndTags();
myRepositoryReader = new HgRepositoryReader(hgDir);
}
@@ -62,6 +62,16 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest {
Arrays.asList("default", "branchA", "branchB"));
}
public void testTags() {
TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags()),
Arrays.asList("tag1", "tag2"));
}
public void testLocalTags() {
TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags()),
Arrays.asList("localTag"));
}
public void testCurrentBookmark() {
hg("update B_BookMark");
assertEquals(myRepositoryReader.readCurrentBookmark(), "B_BookMark");
@@ -72,19 +82,22 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest {
Arrays.asList("A_BookMark", "B_BookMark", "C_BookMark"));
}
private void createBranches() {
private void createBranchesAndTags() {
cd(myRepository);
hg("bookmark A_BookMark");
hg("tag tag1");
String aFile = "A.txt";
touch(aFile, "base");
hg("add " + aFile);
hg("commit -m 'create file'");
hg("bookmark B_BookMark");
hg("branch branchA");
hg("tag tag2");
echo(aFile, " modify with a");
hg("commit -m 'create branchA'");
hg("up default");
hg("branch branchB");
hg("tag -l localTag");
echo(aFile, " modify with b");
hg("commit -m 'modify file in branchB'");
hg("bookmark C_BookMark");
@@ -37,6 +37,8 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
@NotNull private File myHgDir;
@NotNull private Collection<String> myBranches;
@NotNull private Collection<String> myBookmarks;
@NotNull private Collection<String> myTags;
@NotNull private Collection<String> myLocalTags;
@Override
public void setUp() throws Exception {
@@ -52,14 +54,20 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
File testBranchFile = new File(testHgDir, "branch");
File testBookmarkFile = new File(testHgDir, "bookmarks");
File testCurrentBookmarkFile = new File(testHgDir, "bookmarks.current");
File testTagFile = new File(testHgDir.getParentFile(), ".hgtags");
File testLocalTagFile = new File(testHgDir, "localtags");
FileUtil.copyDir(cacheDir, new File(myHgDir, "cache"));
FileUtil.copy(testBranchFile, new File(myHgDir, "branch"));
FileUtil.copy(testBookmarkFile, new File(myHgDir, "bookmarks"));
FileUtil.copy(testCurrentBookmarkFile, new File(myHgDir, "bookmarks.current"));
FileUtil.copy(testTagFile, new File(myHgDir.getParentFile(), ".hgtags"));
FileUtil.copy(testLocalTagFile, new File(myHgDir, "localtags"));
myRepositoryReader = new HgRepositoryReader(myHgDir);
myBranches = readBranches();
myBookmarks = readBookmarks();
myBookmarks = readRefs(testBookmarkFile);
myTags = readRefs(testTagFile);
myLocalTags = readRefs(testLocalTagFile);
}
public void testHEAD() {
@@ -81,6 +89,16 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
TestRepositoryUtil.assertEqualCollections(bookmarks, myBookmarks);
}
public void testTags() {
Collection<String> tags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags());
TestRepositoryUtil.assertEqualCollections(tags, myTags);
}
public void testLocalTags() {
Collection<String> localTags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags());
TestRepositoryUtil.assertEqualCollections(localTags, myLocalTags);
}
@NotNull
private Collection<String> readBranches() throws IOException {
Collection<String> branches = new HashSet<String>();
@@ -100,15 +118,14 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
}
@NotNull
private Collection<String> readBookmarks() throws IOException {
Collection<String> bookmarks = new HashSet<String>();
File bookmarksFile = new File(myHgDir, "bookmarks");
String[] bookmarksWithHashes = FileUtil.loadFile(bookmarksFile).split("\n");
for (String str : bookmarksWithHashes) {
private static Collection<String> readRefs(@NotNull File refFile) throws IOException {
Collection<String> refs = new HashSet<String>();
String[] refsWithHashes = FileUtil.loadFile(refFile).split("\n");
for (String str : refsWithHashes) {
String[] refAndName = str.trim().split(" ");
assertEquals(2, refAndName.length);
bookmarks.add(refAndName[1]);
refs.add(refAndName[1]);
}
return bookmarks;
return refs;
}
}