Skip to content

Commit

Permalink
Handle < > brackets unconditionally
Browse files Browse the repository at this point in the history
Remove checks whether running on Java 1.5+ to handle them as ECJ
mandates 1.8 thus this is always true.
Removed tests for pre 1.5 behavior and enable tests in
JavaPairMatcherTest that were not executed at all.
  • Loading branch information
akurtakov committed Dec 22, 2024
1 parent a34a835 commit b815dd4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -81,14 +81,14 @@ public class BracketInserterTest {
private static final String CU_NAME= "PR75423.java";
private static final String CU_CONTENTS= """
package com.example.bugs;
import java.lang.String;
import java.lang.Integer;
public class PR75423 {
String string;
Integer integer;
public static void main(String[] args) {
\s
}
Expand Down Expand Up @@ -119,6 +119,8 @@ void foo(String[] args) {
public void setUp() throws Exception {
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
store.setValue(PreferenceConstants.EDITOR_CLOSE_BRACKETS, true);
setUpProject(JavaCore.VERSION_1_8);
setUpEditor();
}

private void setUpProject(String sourceLevel) throws CoreException, JavaModelException {
Expand Down Expand Up @@ -147,7 +149,7 @@ private JavaEditor openJavaEditor(IPath path) {
try {
return (JavaEditor)EditorTestHelper.openInEditor(file, true);
} catch (PartInitException e) {
fail();
fail(e.getMessage());
return null;
}
}
Expand All @@ -167,8 +169,7 @@ public void tearDown() throws Exception {
}

@Test
public void testInsertClosingParenthesis() throws BadLocationException, JavaModelException, CoreException, JavaModelException, CoreException {
use14();
public void testInsertClosingParenthesis() throws BadLocationException {
setCaret(BODY_OFFSET);
type('(');

Expand All @@ -177,8 +178,7 @@ public void testInsertClosingParenthesis() throws BadLocationException, JavaMode
}

@Test
public void testDeletingParenthesis() throws JavaModelException, CoreException {
use14();
public void testDeletingParenthesis() {
setCaret(BODY_OFFSET);
type('(');
type(SWT.BS);
Expand All @@ -188,8 +188,7 @@ public void testDeletingParenthesis() throws JavaModelException, CoreException {
}

@Test
public void testMultipleParenthesisInsertion() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testMultipleParenthesisInsertion() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");

Expand All @@ -200,8 +199,7 @@ public void testMultipleParenthesisInsertion() throws BadLocationException, Java
}

@Test
public void testDeletingMultipleParenthesisInertion() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testDeletingMultipleParenthesisInertion() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");

Expand All @@ -227,8 +225,7 @@ public void testDeletingMultipleParenthesisInertion() throws BadLocationExceptio
}

@Test
public void testNoInsertInsideText() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testNoInsertInsideText() throws BadLocationException {
setCaret(ARGS_OFFSET);
type('(');

Expand All @@ -238,8 +235,7 @@ public void testNoInsertInsideText() throws BadLocationException, JavaModelExcep
}

@Test
public void testInsertInsideBrackets() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testInsertInsideBrackets() throws BadLocationException {
setCaret(BRACKETS_OFFSET);
type('(');

Expand All @@ -248,8 +244,7 @@ public void testInsertInsideBrackets() throws BadLocationException, JavaModelExc
}

@Test
public void testPeerEntry() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testPeerEntry() throws BadLocationException {
setCaret(BODY_OFFSET);
type("()");

Expand All @@ -259,17 +254,8 @@ public void testPeerEntry() throws BadLocationException, JavaModelException, Cor
assertFalse(LinkedModeModel.hasInstalledModel(fDocument));
}

// public void testLoop() throws Exception {
// for (int i= 0; i < 50; i++) {
// setUp();
// testExitOnTab();
// tearDown();
// }
// }
//
@Test
public void testMultiplePeerEntry() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testMultiplePeerEntry() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");

Expand All @@ -293,8 +279,7 @@ public void testMultiplePeerEntry() throws BadLocationException, JavaModelExcept
}

@Test
public void testExitOnTab() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testExitOnTab() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");
linkedType('\t', true, ILinkedModeListener.NONE);
Expand All @@ -317,8 +302,7 @@ public void testExitOnTab() throws BadLocationException, JavaModelException, Cor
}

@Test
public void testExitOnReturn() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testExitOnReturn() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");
linkedType(SWT.CR, true, ILinkedModeListener.UPDATE_CARET | ILinkedModeListener.EXIT_ALL);
Expand All @@ -330,8 +314,7 @@ public void testExitOnReturn() throws BadLocationException, JavaModelException,
}

@Test
public void testExitOnEsc() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testExitOnEsc() throws BadLocationException {
setCaret(BODY_OFFSET);
type("((((");
linkedType(SWT.ESC, true, ILinkedModeListener.EXIT_ALL);
Expand All @@ -343,8 +326,7 @@ public void testExitOnEsc() throws BadLocationException, JavaModelException, Cor
}

@Test
public void testInsertClosingQuote() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testInsertClosingQuote() throws BadLocationException {
setCaret(BODY_OFFSET);
type('"');

Expand All @@ -354,8 +336,7 @@ public void testInsertClosingQuote() throws BadLocationException, JavaModelExcep
}

@Test
public void testPreferences() throws BadLocationException, JavaModelException, CoreException {
use14();
public void testPreferences() throws BadLocationException {
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
store.setValue(PreferenceConstants.EDITOR_CLOSE_BRACKETS, false);

Expand All @@ -370,7 +351,6 @@ public void testPreferences() throws BadLocationException, JavaModelException, C

@Test
public void testAngleBracketsAsOperator() throws Exception {
use15();
setCaret(BODY_OFFSET);
type("test<");

Expand All @@ -381,23 +361,8 @@ public void testAngleBracketsAsOperator() throws Exception {
assertFalse(LinkedModeModel.hasInstalledModel(fDocument));
}

@Test
public void testAngleBracketsIn14Project() throws BadLocationException, JavaModelException, CoreException {
use14();
setCaret(BODY_OFFSET);
type("Test<");

assertEquals("Test<", fDocument.get(BODY_OFFSET, 5));
assertNotEquals(">", fDocument.get(BODY_OFFSET + 5, 1));
assertEquals(BODY_OFFSET + 5, getCaret());

assertFalse(LinkedModeModel.hasInstalledModel(fDocument));
}

@Test
public void testAngleBracketsIn15Project() throws Exception {
use15();

setCaret(BODY_OFFSET);
type("Test<");

Expand All @@ -407,8 +372,6 @@ public void testAngleBracketsIn15Project() throws Exception {

@Test
public void testAngleBracketsInFieldDecl15() throws Exception {
use15();

setCaret(FIELD_OFFSET);
type('<');

Expand All @@ -418,8 +381,6 @@ public void testAngleBracketsInFieldDecl15() throws Exception {

@Test
public void testAngleBracketsInsideMethodDecl15() throws Exception {
use15();

setCaret(MAIN_VOID_OFFSET);
type('<');

Expand All @@ -429,8 +390,6 @@ public void testAngleBracketsInsideMethodDecl15() throws Exception {

@Test
public void testAngleBracketsBeforeMethodDecl15() throws Exception {
use15();

setCaret(FOO_VOID_OFFSET);

type('<');
Expand All @@ -441,8 +400,6 @@ public void testAngleBracketsBeforeMethodDecl15() throws Exception {

@Test
public void testAngleBracketsBeforeTypeArgument15() throws Exception {
use15();

String PRE= "new ArrayList";
String POST= "String>();";

Expand All @@ -457,8 +414,6 @@ public void testAngleBracketsBeforeTypeArgument15() throws Exception {

@Test
public void testAngleBracketsBeforeWildcard15() throws Exception {
use15();

String PRE= "new ArrayList";
String POST= "? extends Number>();";

Expand All @@ -474,8 +429,6 @@ public void testAngleBracketsBeforeWildcard15() throws Exception {
@Test
public void testAngleBracketsAfterIdentifierOnFirstColumn1_15() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=347734
use15();

String PRE= "x";

fDocument.replace(FIRST_COLUMN_OFFSET, 0, PRE);
Expand All @@ -490,8 +443,6 @@ public void testAngleBracketsAfterIdentifierOnFirstColumn1_15() throws Exception
@Test
public void testAngleBracketsAfterIdentifierOnFirstColumn2_15() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=347734
use15();

String PRE= "List";

fDocument.replace(FIRST_COLUMN_OFFSET, 0, PRE);
Expand All @@ -514,16 +465,6 @@ private void assertSingleLinkedPosition(int offset) {
assertEquals(0, position.getLength());
}

private void use15() throws CoreException, JavaModelException {
setUpProject(JavaCore.VERSION_1_5);
setUpEditor();
}

private void use14() throws CoreException, JavaModelException {
setUpProject(JavaCore.VERSION_1_4);
setUpEditor();
}

/**
* Type characters into the styled text.
*
Expand Down
Loading

0 comments on commit b815dd4

Please sign in to comment.