mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
@@ -19,8 +19,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A char sequence that supports fast copying of its full or partial contents to a char array. May be useful for performance optimizations
|
||||
* @see com.intellij.util.text.CharSequenceBackedByArray
|
||||
* @see com.intellij.util.text.CharArrayUtil#getChars(CharSequence, char[], int)
|
||||
* @see CharSequenceBackedByArray
|
||||
* @see CharArrayUtil#getChars(CharSequence, char[], int)
|
||||
*/
|
||||
public interface CharArrayExternalizable extends CharSequence {
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@ import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -152,7 +149,7 @@ public class CharArrayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find an offset from the <code>[startOffset; endOffset)</code> interval such that a char from the given buffer is
|
||||
* Tries to find an offset from the {@code [startOffset; endOffset)} interval such that a char from the given buffer is
|
||||
* not contained at the given 'chars' string.
|
||||
* <p/>
|
||||
* Example:
|
||||
@@ -162,9 +159,9 @@ public class CharArrayUtil {
|
||||
* @param startOffset start offset to use within the given buffer (inclusive)
|
||||
* @param endOffset end offset to use within the given buffer (exclusive)
|
||||
* @param chars pass-through symbols
|
||||
* @return offset from the <code>[startOffset; endOffset)</code> which points to a symbol at the given buffer such
|
||||
* @return offset from the {@code [startOffset; endOffset)} which points to a symbol at the given buffer such
|
||||
* as that that symbol is not contained at the given 'chars';
|
||||
* <code>endOffset</code> otherwise
|
||||
* {@code endOffset} otherwise
|
||||
*/
|
||||
public static int shiftForward(@NotNull CharSequence buffer, final int startOffset, final int endOffset, @NotNull String chars) {
|
||||
for (int offset = startOffset, limit = Math.min(endOffset, buffer.length()); offset < limit; offset++) {
|
||||
@@ -254,24 +251,24 @@ public class CharArrayUtil {
|
||||
* <ul>
|
||||
* <li>is less than or equal to the given offset;</li>
|
||||
* <li>
|
||||
* it's guaranteed that all symbols of the given buffer that are located at <code>(returned offset; given offset]</code>
|
||||
* it's guaranteed that all symbols of the given buffer that are located at {@code (returned offset; given offset]}
|
||||
* interval differ from the given symbols;
|
||||
* </li>
|
||||
* </ul>
|
||||
* <p/>
|
||||
* Example: suppose that this method is called with buffer that holds <code>'test data'</code> symbols, offset that points
|
||||
* to the last symbols and <code>'sf'</code> as a chars to exclude. Offset that points to <code>'s'</code> symbol
|
||||
* Example: suppose that this method is called with buffer that holds {@code 'test data'} symbols, offset that points
|
||||
* to the last symbols and {@code 'sf'} as a chars to exclude. Offset that points to {@code 's'} symbol
|
||||
* is returned then, i.e. all symbols of the given buffer that are located after it and not after given offset
|
||||
* (<code>'t data'</code>) are guaranteed to not contain given chars (<code>'sf'</code>).
|
||||
* ({@code 't data'}) are guaranteed to not contain given chars ({@code 'sf'}).
|
||||
*
|
||||
* @param buffer symbols buffer to check
|
||||
* @param offset initial symbols buffer offset to use
|
||||
* @param chars chars to exclude
|
||||
* @return offset of the given buffer that guarantees that all symbols at <code>(returned offset; given offset]</code>
|
||||
* interval of the given buffer differ from symbols of given <code>'chars'</code> arguments;
|
||||
* @return offset of the given buffer that guarantees that all symbols at {@code (returned offset; given offset]}
|
||||
* interval of the given buffer differ from symbols of given {@code 'chars'} arguments;
|
||||
* given offset is returned if it is outside of given buffer bounds;
|
||||
* <code>'-1'</code> is returned if all document symbols that precede given offset differ from symbols
|
||||
* of the given <code>'chars to exclude'</code>
|
||||
* {@code '-1'} is returned if all document symbols that precede given offset differ from symbols
|
||||
* of the given {@code 'chars to exclude'}
|
||||
*/
|
||||
public static int shiftBackwardUntil(@NotNull CharSequence buffer, int offset, @NotNull String chars) {
|
||||
if (offset >= buffer.length()) return offset;
|
||||
@@ -366,14 +363,14 @@ public class CharArrayUtil {
|
||||
* @param pattern target characters sequence to find at the given buffer
|
||||
* @param fromIndex start index (inclusive). Zero is used if given index is negative
|
||||
* @param toIndex end index (exclusive)
|
||||
* @return index of the given pattern at the given buffer if the match is found; <code>-1</code> otherwise
|
||||
* @return index of the given pattern at the given buffer if the match is found; {@code -1} otherwise
|
||||
*/
|
||||
public static int indexOf(@NotNull CharSequence buffer, @NotNull CharSequence pattern, int fromIndex, final int toIndex) {
|
||||
final int patternLength = pattern.length();
|
||||
int limit = toIndex - patternLength + 1;
|
||||
if (fromIndex < 0) {
|
||||
fromIndex = 0;
|
||||
}
|
||||
int limit = toIndex - patternLength + 1;
|
||||
SearchLoop:
|
||||
for (int i = fromIndex; i < limit; i++) {
|
||||
for (int j = 0; j < patternLength; j++) {
|
||||
@@ -385,15 +382,15 @@ public class CharArrayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find index that points to the first location of the given symbol at the given char array at range <code>[from; to)</code>.
|
||||
* Tries to find index that points to the first location of the given symbol at the given char array at range {@code [from; to)}.
|
||||
*
|
||||
* @param buffer target symbols holder to check
|
||||
* @param symbol target symbol which offset should be found
|
||||
* @param fromIndex start index to search (inclusive)
|
||||
* @param toIndex end index to search (exclusive)
|
||||
* @return index that points to the first location of the given symbol at the given char array at range
|
||||
* <code>[from; to)</code> if target symbol is found;
|
||||
* <code>-1</code> otherwise
|
||||
* {@code [from; to)} if target symbol is found;
|
||||
* {@code -1} otherwise
|
||||
*/
|
||||
public static int indexOf(@NotNull char[] buffer, final char symbol, int fromIndex, final int toIndex) {
|
||||
if (fromIndex < 0) {
|
||||
@@ -408,15 +405,15 @@ public class CharArrayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find index that points to the last location of the given symbol at the given char array at range <code>[from; to)</code>.
|
||||
* Tries to find index that points to the last location of the given symbol at the given char array at range {@code [from; to)}.
|
||||
*
|
||||
* @param buffer target symbols holder to check
|
||||
* @param symbol target symbol which offset should be found
|
||||
* @param fromIndex start index to search (inclusive)
|
||||
* @param toIndex end index to search (exclusive)
|
||||
* @return index that points to the last location of the given symbol at the given char array at range
|
||||
* <code>[from; to)</code> if target symbol is found;
|
||||
* <code>-1</code> otherwise
|
||||
* {@code [from; to)} if target symbol is found;
|
||||
* {@code -1} otherwise
|
||||
*/
|
||||
public static int lastIndexOf(@NotNull char[] buffer, final char symbol, int fromIndex, final int toIndex) {
|
||||
if (fromIndex < 0) {
|
||||
@@ -462,24 +459,6 @@ public class CharArrayUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static byte[] toByteArray(@NotNull char[] chars) throws IOException {
|
||||
return toByteArray(chars, chars.length);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static byte[] toByteArray(@NotNull char[] chars, int size) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out);
|
||||
try {
|
||||
writer.write(chars, 0, size);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
public static boolean containsOnlyWhiteSpaces(@Nullable CharSequence chars) {
|
||||
if (chars == null) return true;
|
||||
for (int i = 0; i < chars.length(); i++) {
|
||||
@@ -490,18 +469,6 @@ public class CharArrayUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Commented in order to apply to green code policy as the method is unused.
|
||||
//
|
||||
//public static boolean subArraysEqual(char[] ca1, int startOffset1, int endOffset1,char[] ca2, int startOffset2, int endOffset2) {
|
||||
// if (endOffset1 - startOffset1 != endOffset2 - startOffset2) return false;
|
||||
// for (int i = startOffset1; i < endOffset1; i++) {
|
||||
// char c1 = ca1[i];
|
||||
// char c2 = ca2[i - startOffset1 + startOffset2];
|
||||
// if (c1 != c2) return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
|
||||
@NotNull
|
||||
public static TextRange[] getIndents(@NotNull CharSequence charsSequence, int shift) {
|
||||
List<TextRange> result = new ArrayList<TextRange>();
|
||||
@@ -553,7 +520,7 @@ public class CharArrayUtil {
|
||||
* @param text text to check
|
||||
* @param start start offset within the given text to check (inclusive)
|
||||
* @param end end offset within the given text to check (exclusive)
|
||||
* @return <code>true</code> if target region of the given text contains white space symbols only; <code>false</code> otherwise
|
||||
* @return {@code true} if target region of the given text contains white space symbols only; {@code false} otherwise
|
||||
*/
|
||||
public static boolean isEmptyOrSpaces(@NotNull CharSequence text, int start, int end) {
|
||||
for (int i = start; i < end; i++) {
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
* A char sequence based on a char array. May be used for performance optimizations.
|
||||
*
|
||||
* @author Maxim.Mossienko
|
||||
* @see com.intellij.util.text.CharArrayExternalizable
|
||||
* @see com.intellij.util.text.CharArrayUtil#getChars(CharSequence, char[], int)
|
||||
* @see com.intellij.util.text.CharArrayUtil#fromSequenceWithoutCopying(CharSequence)
|
||||
* @see CharArrayExternalizable
|
||||
* @see CharArrayUtil#getChars(CharSequence, char[], int)
|
||||
* @see CharArrayUtil#fromSequenceWithoutCopying(CharSequence)
|
||||
*/
|
||||
public interface CharSequenceBackedByArray extends CharSequence {
|
||||
// NOT guaranteed to return the array of the length of the original charSequence.length() - may be more for performance reasons.
|
||||
|
||||
@@ -35,4 +35,8 @@ public abstract class ImmutableCharSequence implements CharSequence {
|
||||
public abstract ImmutableCharSequence delete(int start, int end);
|
||||
|
||||
public abstract ImmutableCharSequence subtext(int start, int end);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract String toString();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.*;
|
||||
*/
|
||||
public class TextRangeUtil {
|
||||
|
||||
private final static Comparator<TextRange> RANGE_COMPARATOR = new Comparator<TextRange>() {
|
||||
private static final Comparator<TextRange> RANGE_COMPARATOR = new Comparator<TextRange>() {
|
||||
@Override
|
||||
public int compare(TextRange range1, TextRange range2) {
|
||||
int startOffsetDiff = range1.getStartOffset() - range2.getStartOffset();
|
||||
@@ -47,11 +47,11 @@ public class TextRangeUtil {
|
||||
*/
|
||||
public static Iterable<TextRange> excludeRanges(@NotNull TextRange original, @NotNull List<TextRange> excludedRanges) {
|
||||
if (!excludedRanges.isEmpty()) {
|
||||
List<TextRange> enabledRanges = new ArrayList<TextRange>();
|
||||
if (excludedRanges.size() > 1) {
|
||||
Collections.sort(excludedRanges, RANGE_COMPARATOR);
|
||||
}
|
||||
int enabledRangeStart = original.getStartOffset();
|
||||
List<TextRange> enabledRanges = new ArrayList<TextRange>();
|
||||
for (TextRange excludedRange : excludedRanges) {
|
||||
if (excludedRange.getEndOffset() < enabledRangeStart) continue;
|
||||
int excludedRangeStart = excludedRange.getStartOffset();
|
||||
@@ -66,6 +66,6 @@ public class TextRangeUtil {
|
||||
}
|
||||
return enabledRanges;
|
||||
}
|
||||
return Arrays.asList(original);
|
||||
return Collections.singletonList(original);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class TextRanges implements Iterable<TextRange> {
|
||||
private final static Comparator<TextRange> START_COMP = new Comparator<TextRange>() {
|
||||
private static final Comparator<TextRange> START_COMP = new Comparator<TextRange>() {
|
||||
@Override
|
||||
public int compare(TextRange o1, TextRange o2) {
|
||||
return Comparing.compare(o1.getStartOffset(), o2.getStartOffset());
|
||||
}
|
||||
};
|
||||
private final static Comparator<TextRange> END_COMP = new Comparator<TextRange>() {
|
||||
private static final Comparator<TextRange> END_COMP = new Comparator<TextRange>() {
|
||||
@Override
|
||||
public int compare(TextRange o1, TextRange o2) {
|
||||
return Comparing.compare(o1.getEndOffset(), o2.getEndOffset());
|
||||
@@ -67,7 +67,7 @@ public class TextRanges implements Iterable<TextRange> {
|
||||
|
||||
public Iterator<TextRange> revIterator() {
|
||||
return new Iterator<TextRange>() {
|
||||
private ListIterator<TextRange> it = myRanges.listIterator(myRanges.size());
|
||||
private final ListIterator<TextRange> it = myRanges.listIterator(myRanges.size());
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
|
||||
@@ -40,7 +40,8 @@ public class UnsyncCharArrayReader extends Reader {
|
||||
public int read(@NotNull char[] cbuf, int off, int len) {
|
||||
if (off < 0 || off > cbuf.length || len < 0 || off + len > cbuf.length || off + len < 0) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else if (len == 0) {
|
||||
}
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+19
-37
@@ -66,7 +66,6 @@ import com.intellij.ui.content.ContentManager;
|
||||
import com.intellij.util.ContentUtilEx;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import org.jdom.Attribute;
|
||||
@@ -83,7 +82,7 @@ import java.util.List;
|
||||
@State(name = "ProjectLevelVcsManager", storages = @Storage(StoragePathMacros.WORKSPACE_FILE))
|
||||
public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx implements ProjectComponent, PersistentStateComponent<Element> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl");
|
||||
@NonNls public static final String SETTINGS_EDITED_MANUALLY = "settingsEditedManually";
|
||||
@NonNls private static final String SETTINGS_EDITED_MANUALLY = "settingsEditedManually";
|
||||
|
||||
private final ProjectLevelVcsManagerSerialization mySerialization;
|
||||
private final OptionsAndConfirmations myOptionsAndConfirmations;
|
||||
@@ -94,7 +93,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
|
||||
private ContentManager myContentManager;
|
||||
private ConsoleView myConsole;
|
||||
private Disposable myConsoleDisposer = new Disposable() {
|
||||
private final Disposable myConsoleDisposer = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (myConsole != null) {
|
||||
@@ -113,11 +112,11 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
@NonNls private static final String ELEMENT_ROOT_SETTINGS = "rootSettings";
|
||||
@NonNls private static final String ATTRIBUTE_CLASS = "class";
|
||||
|
||||
private boolean myMappingsLoaded = false;
|
||||
private boolean myHaveLegacyVcsConfiguration = false;
|
||||
private boolean myMappingsLoaded;
|
||||
private boolean myHaveLegacyVcsConfiguration;
|
||||
private final DefaultVcsRootPolicy myDefaultVcsRootPolicy;
|
||||
|
||||
private volatile int myBackgroundOperationCounter = 0;
|
||||
private volatile int myBackgroundOperationCounter;
|
||||
|
||||
private final Set<ActionKey> myBackgroundRunningTasks = ContainerUtil.newHashSet();
|
||||
|
||||
@@ -165,34 +164,21 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
myVcsHistoryCache = new VcsHistoryCache();
|
||||
myContentRevisionCache = new ContentRevisionCache();
|
||||
myVcsFileListenerContextHelper = vcsFileListenerContextHelper;
|
||||
VcsListener vcsListener = new VcsListener() {
|
||||
@Override
|
||||
public void directoryMappingChanged() {
|
||||
myVcsHistoryCache.clear();
|
||||
myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss());
|
||||
}
|
||||
VcsListener vcsListener = () -> {
|
||||
myVcsHistoryCache.clear();
|
||||
myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss());
|
||||
};
|
||||
myExcludedIndex = excludedFileIndex;
|
||||
MessageBusConnection connection = myProject.getMessageBus().connect();
|
||||
connection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
|
||||
connection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener);
|
||||
connection.subscribe(UpdatedFilesListener.UPDATED_FILES, new UpdatedFilesListener() {
|
||||
@Override
|
||||
public void consume(Set<String> strings) {
|
||||
myContentRevisionCache.clearCurrent(strings);
|
||||
}
|
||||
});
|
||||
connection.subscribe(UpdatedFilesListener.UPDATED_FILES, myContentRevisionCache::clearCurrent);
|
||||
myAnnotationLocalChangesListener = new VcsAnnotationLocalChangesListenerImpl(myProject, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
myOptionsAndConfirmations.init(new Convertor<String, VcsShowConfirmationOption.Value>() {
|
||||
@Override
|
||||
public VcsShowConfirmationOption.Value convert(String o) {
|
||||
return mySerialization.getInitOptionValue(o);
|
||||
}
|
||||
});
|
||||
myOptionsAndConfirmations.init(mySerialization::getInitOptionValue);
|
||||
}
|
||||
|
||||
public void registerVcs(AbstractVcs vcs) {
|
||||
@@ -534,7 +520,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasExplicitMapping(final VirtualFile vFile) {
|
||||
private boolean hasExplicitMapping(final VirtualFile vFile) {
|
||||
final VcsDirectoryMapping mapping = myMappings.getMappingFor(vFile);
|
||||
return mapping != null && !mapping.isDefaultMapping();
|
||||
}
|
||||
@@ -707,7 +693,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
myProject.getMessageBus().syncPublisher(VCS_CONFIGURATION_CHANGED).directoryMappingChanged();
|
||||
}
|
||||
|
||||
public void readDirectoryMappings(final Element element) {
|
||||
void readDirectoryMappings(final Element element) {
|
||||
myMappings.clear();
|
||||
|
||||
final List<VcsDirectoryMapping> mappingsList = new ArrayList<>();
|
||||
@@ -746,7 +732,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
myMappings.setDirectoryMappings(mappingsList);
|
||||
}
|
||||
|
||||
public void writeDirectoryMappings(@NotNull Element element) {
|
||||
void writeDirectoryMappings(@NotNull Element element) {
|
||||
if (myProject.isDefault()) {
|
||||
element.setAttribute(ATTRIBUTE_DEFAULT_PROJECT, Boolean.TRUE.toString());
|
||||
}
|
||||
@@ -853,15 +839,11 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
|
||||
@Override
|
||||
public boolean isFileInContent(@Nullable final VirtualFile vf) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
return vf != null && (myExcludedIndex.isInContent(vf) || isFileInBaseDir(vf) || vf.equals(myProject.getBaseDir()) ||
|
||||
hasExplicitMapping(vf) || isInDirectoryBasedRoot(vf)
|
||||
|| !Registry.is("ide.hide.excluded.files") && myExcludedIndex.isExcludedFile(vf))
|
||||
&& !isIgnored(vf);
|
||||
}
|
||||
});
|
||||
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>)() ->
|
||||
vf != null && (myExcludedIndex.isInContent(vf) || isFileInBaseDir(vf) || vf.equals(myProject.getBaseDir()) ||
|
||||
hasExplicitMapping(vf) || isInDirectoryBasedRoot(vf)
|
||||
|| !Registry.is("ide.hide.excluded.files") && myExcludedIndex.isExcludedFile(vf))
|
||||
&& !isIgnored(vf));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -904,7 +886,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
|
||||
private static class ActionKey {
|
||||
private final Object[] myObjects;
|
||||
|
||||
public ActionKey(@NotNull Object... objects) {
|
||||
ActionKey(@NotNull Object... objects) {
|
||||
myObjects = objects;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user