mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Removed unused classes
This commit is contained in:
-140
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.psi.codeStyle.autodetect;
|
||||
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ContinuationIndentDetector {
|
||||
private Stack<Bracket> myOpenedBrackets = ContainerUtil.newStack();
|
||||
|
||||
private final CharSequence myText;
|
||||
private final int myLength;
|
||||
private boolean myIncorrectBracketsOrder = false;
|
||||
|
||||
private Character myOpeningStringLiteralDelimiter = null;
|
||||
|
||||
public ContinuationIndentDetector(@NotNull CharSequence text) {
|
||||
myText = text;
|
||||
myLength = text.length();
|
||||
}
|
||||
|
||||
public void feedLineStartingAt(int startOffset) {
|
||||
if (myIncorrectBracketsOrder) return;
|
||||
|
||||
int lineEndOffset = CharArrayUtil.indexOf(myText, "\n", startOffset, myLength);
|
||||
if (lineEndOffset < 0) lineEndOffset = myLength;
|
||||
|
||||
for (int i = startOffset; i < lineEndOffset; i++) {
|
||||
final char currentChar = myText.charAt(i);
|
||||
|
||||
if (isStringLiteralDelimiter(currentChar)) {
|
||||
processStringLiteralDelimiter(currentChar);
|
||||
}
|
||||
else {
|
||||
Bracket bracket = Bracket.forChar(currentChar);
|
||||
if (bracket != null && myOpeningStringLiteralDelimiter == null) {
|
||||
processBracket(bracket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processStringLiteralDelimiter(char delimiter) {
|
||||
if (myOpeningStringLiteralDelimiter == null) {
|
||||
myOpeningStringLiteralDelimiter = delimiter;
|
||||
}
|
||||
else if (myOpeningStringLiteralDelimiter.charValue() == delimiter) {
|
||||
myOpeningStringLiteralDelimiter = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isStringLiteralDelimiter(char currentChar) {
|
||||
return currentChar == '\'' || currentChar == '\"';
|
||||
}
|
||||
|
||||
private void processBracket(@NotNull Bracket bracket) {
|
||||
if (bracket.isOpening()) {
|
||||
myOpenedBrackets.add(bracket);
|
||||
}
|
||||
else {
|
||||
if (!myOpenedBrackets.isEmpty() && bracket.isClosing(myOpenedBrackets.peek())) {
|
||||
myOpenedBrackets.pop();
|
||||
}
|
||||
else {
|
||||
myIncorrectBracketsOrder = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isContinuationIndent() {
|
||||
if (myIncorrectBracketsOrder || myOpenedBrackets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return myOpenedBrackets.peek() == Bracket.LPARENTH;
|
||||
}
|
||||
|
||||
|
||||
private enum Bracket {
|
||||
LBRACE('{') {
|
||||
@Override
|
||||
boolean isOpening() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
LPARENTH('(') {
|
||||
@Override
|
||||
boolean isOpening() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
RBRACE('}') {
|
||||
@Override
|
||||
public boolean isClosing(Bracket bracket) {
|
||||
return bracket == LBRACE;
|
||||
}
|
||||
},
|
||||
RPARENTH(')') {
|
||||
@Override
|
||||
public boolean isClosing(Bracket bracket) {
|
||||
return bracket == LPARENTH;
|
||||
}
|
||||
};
|
||||
|
||||
private final char myChar;
|
||||
|
||||
Bracket(char c) {
|
||||
myChar = c;
|
||||
}
|
||||
|
||||
public boolean isClosing(Bracket bracket) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isOpening() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static Bracket forChar(char c) {
|
||||
for (Bracket bracket : Bracket.values()) {
|
||||
if (bracket.myChar == c) return bracket;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.psi.codeStyle.autodetect;
|
||||
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LineIndentInfoBuilder {
|
||||
private static final int MAX_LINES_TO_PROCESS = 500;
|
||||
|
||||
private final CharSequence myText;
|
||||
private final int myLength;
|
||||
private final Commenter myCommenter;
|
||||
private ContinuationIndentDetector myContinuationIndentDetector;
|
||||
|
||||
public LineIndentInfoBuilder(@NotNull CharSequence text, @Nullable Language language) {
|
||||
myText = text;
|
||||
myLength = text.length();
|
||||
myContinuationIndentDetector = new ContinuationIndentDetector(text);
|
||||
myCommenter = language != null ? LanguageCommenters.INSTANCE.forLanguage(language) : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<LineIndentInfo> build() {
|
||||
List<LineIndentInfo> lineIndentInfos = ContainerUtil.newArrayList();
|
||||
|
||||
int lineStartOffset = 0;
|
||||
int currentLine = 0;
|
||||
|
||||
while (lineStartOffset < myText.length() && currentLine < MAX_LINES_TO_PROCESS) {
|
||||
int lineEndOffset = getLineEndOffset(lineStartOffset);
|
||||
int textStartOffset = CharArrayUtil.shiftForward(myText, lineStartOffset, lineEndOffset, " \t");
|
||||
|
||||
if (textStartOffset != lineEndOffset) {
|
||||
lineIndentInfos.add(createInfoFromWhiteSpaceRange(lineStartOffset, textStartOffset));
|
||||
} else {
|
||||
lineIndentInfos.add(LineIndentInfo.EMPTY_LINE);
|
||||
}
|
||||
|
||||
lineStartOffset = lineEndOffset + 1;
|
||||
currentLine++;
|
||||
}
|
||||
|
||||
return lineIndentInfos;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private LineIndentInfo createInfoFromWhiteSpaceRange(int lineStartOffset, int textStartOffset) {
|
||||
if (startsWithComment(textStartOffset)) {
|
||||
return LineIndentInfo.LINE_WITH_COMMENT;
|
||||
}
|
||||
else if (CharArrayUtil.indexOf(myText, "\t", lineStartOffset, textStartOffset) > 0) {
|
||||
myContinuationIndentDetector.feedLineStartingAt(lineStartOffset);
|
||||
return LineIndentInfo.LINE_WITH_TABS;
|
||||
}
|
||||
else {
|
||||
boolean isContinuationIndent = myContinuationIndentDetector.isContinuationIndent();
|
||||
myContinuationIndentDetector.feedLineStartingAt(lineStartOffset);
|
||||
return isContinuationIndent ? LineIndentInfo.LINE_WITH_CONTINUATION_INDENT
|
||||
: LineIndentInfo.newNormalIndent(textStartOffset - lineStartOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean startsWithComment(int textStartOffset) {
|
||||
if (myText.charAt(textStartOffset) == '*' || startsWithLineComment(textStartOffset)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean startsWithLineComment(int textStartOffset) {
|
||||
if (myCommenter == null) return false;
|
||||
|
||||
String lineCommentPrefix = myCommenter.getLineCommentPrefix();
|
||||
if (lineCommentPrefix != null && CharArrayUtil.regionMatches(myText, textStartOffset, lineCommentPrefix)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getLineEndOffset(int lineStartOffset) {
|
||||
int lineEndOffset = CharArrayUtil.indexOf(myText, "\n", lineStartOffset, myLength);
|
||||
if (lineEndOffset < 0) {
|
||||
lineEndOffset = myText.length();
|
||||
}
|
||||
return lineEndOffset;
|
||||
}
|
||||
}
|
||||
-173
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.psi.codeStyle.autodetect;
|
||||
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class ContinuationIndentDetectorTest extends TestCase {
|
||||
private ContinuationIndentDetector myContinuationIndentDetector;
|
||||
private List<Integer> myLineStartOffsets;
|
||||
|
||||
public void configure(String text) {
|
||||
myContinuationIndentDetector = new ContinuationIndentDetector(text);
|
||||
myLineStartOffsets = calculateLineStartOffsets(text);
|
||||
}
|
||||
|
||||
public void testContinuationIndentInsideParenth() {
|
||||
configure(
|
||||
"test(\n" +
|
||||
" \"aaaaa\" + \n" +
|
||||
" \"bbbbb\");\n" +
|
||||
"int a = 2;"
|
||||
);
|
||||
|
||||
doCheckLinesWithContinuationIndents(1, 2);
|
||||
}
|
||||
|
||||
public void testContinuationIndent_IfBracesWithinStringLiteral() {
|
||||
configure(
|
||||
"tester(\"{\",\n" +
|
||||
" \"welcome\",\n" +
|
||||
" \"my own\",\n" +
|
||||
" \"string literal\")\n"
|
||||
);
|
||||
|
||||
doCheckLinesWithContinuationIndents(1, 2, 3);
|
||||
}
|
||||
|
||||
public void testNoContinuationIndent_OnLineStartingWithRightParenth() {
|
||||
configure(
|
||||
"test(\n" +
|
||||
" \"aaaaa\" + \n" +
|
||||
" \"bbbbb\"\n" +
|
||||
");"
|
||||
);
|
||||
|
||||
doCheckLinesWithContinuationIndents(1, 2, 3);
|
||||
}
|
||||
|
||||
public void testNoContinuationIndents_BetweenBraces() {
|
||||
configure(
|
||||
"import java.lang.Override;\n" +
|
||||
"import java.lang.Runnable;\n" +
|
||||
"\n" +
|
||||
"class T {\n" +
|
||||
" \n" +
|
||||
" void test() {\n" +
|
||||
" int a;\n" +
|
||||
" int b;\n" +
|
||||
" Runnable runnable = new Runnable() {\n" +
|
||||
" @Override\n" +
|
||||
" public void run() {\n" +
|
||||
" System.out.println(\"AAA!\");\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
"}"
|
||||
);
|
||||
doCheckLinesWithContinuationIndents();
|
||||
}
|
||||
|
||||
public void testMixedBraces() {
|
||||
configure(
|
||||
"import java.lang.Runnable;\n" +
|
||||
"\n" +
|
||||
"class R {\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" void test() {\n" +
|
||||
" kuu(new Runnable() {\n" +
|
||||
" @Override\n" +
|
||||
" public void run() {\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" new Runnable() {\n" +
|
||||
" @Override\n" +
|
||||
" public void run() {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" );\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" void kuu(Runnable a, Runnable b) {\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
doCheckLinesWithContinuationIndents(11, 16);
|
||||
}
|
||||
|
||||
public void testClosingBracesAtLineStart() {
|
||||
configure("class Test {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" tree.put(\"Web Development\", Pair.create(PlatformImplIcons.WebDevelopment, Arrays.asList(\n" +
|
||||
" \"HTML:HtmlTools\",\n" +
|
||||
" \"com.intellij.css\",\n" +
|
||||
" \"JavaScript:JavaScript,JSIntentionPowerPack\",\n" +
|
||||
" \"com.jetbrains.restClient\"\n" +
|
||||
" )));\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
doCheckLinesWithContinuationIndents(3, 4, 5, 6, 7);
|
||||
}
|
||||
|
||||
public void testInsideParenth() {
|
||||
configure("@State(\n" +
|
||||
" name = \"AndroidRemoteDataBaseManager\",\n" +
|
||||
" storages = {\n" +
|
||||
" @Storage(\n" +
|
||||
" file = StoragePathMacros.APP_CONFIG + \"/androidRemoteDatabases.xml\"\n" +
|
||||
" )}\n" +
|
||||
")\n" +
|
||||
"class T {}");
|
||||
doCheckLinesWithContinuationIndents(1, 2, 4, 5, 6);
|
||||
}
|
||||
|
||||
private void doCheckLinesWithContinuationIndents(Integer... linesWithContinuationIndents) {
|
||||
Set<Integer> continuationLines = ContainerUtil.newHashSet(linesWithContinuationIndents);
|
||||
|
||||
for (int currentLine = 0; currentLine < myLineStartOffsets.size(); currentLine++) {
|
||||
Integer lineStartOffset = myLineStartOffsets.get(currentLine);
|
||||
boolean isContinuation = myContinuationIndentDetector.isContinuationIndent();
|
||||
if (continuationLines.contains(currentLine)) {
|
||||
assertTrue("Line " + currentLine + " should start with continuation indent", isContinuation);
|
||||
}
|
||||
else {
|
||||
assertTrue("Line " + currentLine + " should not start with continuation indent" ,!isContinuation);
|
||||
}
|
||||
myContinuationIndentDetector.feedLineStartingAt(lineStartOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> calculateLineStartOffsets(String text) {
|
||||
List<Integer> lineStartOffsets = ContainerUtil.newArrayList();
|
||||
lineStartOffsets.add(0);
|
||||
|
||||
int lineStart = 0;
|
||||
int lineFeed;
|
||||
while ((lineFeed = text.indexOf('\n', lineStart)) > 0) {
|
||||
lineStart = lineFeed + 1;
|
||||
lineStartOffsets.add(lineStart);
|
||||
}
|
||||
|
||||
return lineStartOffsets;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user