Bug 550137 - [13] Merge issues with BETA branch: Impact of
PreviewEnabled check in DOM on JDT UI
Merge remote-tracking branch 'origin/master' into BETA_JAVA13
Conflicts:
org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
Change-Id: I7d62e789f524520609e714515af65576d089e601
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
diff --git a/.gitignore b/.gitignore
index c810fc5..e6df2c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,5 @@
core.*
Snap.*
# maven
-target/
+/*/target/
.DS_Store
diff --git a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java
index ea934dd..5078d25 100644
--- a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java
+++ b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -121,7 +125,6 @@
import org.eclipse.jdt.core.dom.ASTRequestor;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Block;
-import org.eclipse.jdt.core.dom.BreakStatement;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
@@ -129,15 +132,21 @@
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.SwitchExpression;
-import org.eclipse.jdt.core.dom.SwitchStatement;
+import org.eclipse.jdt.core.dom.YieldStatement;
import org.eclipse.jdt.core.manipulation.SharedASTProviderCore;
import org.eclipse.jdt.ui.JavaUI;
public class ASTView extends ViewPart implements IShowInSource, IShowInTargetList {
- static final int JLS_LATEST= AST.JLS12;
+ static final int JLS_LATEST= AST.JLS13;
+ private static final int JLS13= AST.JLS13;
+
+ /**
+ * @deprecated to get rid of deprecation warnings in code
+ */
+ @Deprecated
private static final int JLS12= AST.JLS12;
/**
@@ -398,28 +407,25 @@
}
}
- private static final class BreakStatementChecker extends ASTVisitor {
+ private static final class StatementChecker extends ASTVisitor {
@Override
- public boolean visit(BreakStatement node) {
+ public boolean visit(YieldStatement node) {
try {
- if (node != null && node.isImplicit() && isInSwitchExpressionOrStatement(node)) {
+ if (node != null && node.isImplicit() && isInSwitchExpression(node)) {
ASTNode parent= node.getParent();
List<Statement> statements= null;
if (parent instanceof Block) {
statements= ((Block) parent).statements();
} else if (parent instanceof SwitchExpression) {
statements= ((SwitchExpression) parent).statements();
- } else if (parent instanceof SwitchStatement) {
- statements= ((SwitchStatement) parent).statements();
}
if (statements == null) {
return true;
}
Expression exp= node.getExpression();
if (exp == null) {
- statements.remove(node);
- return false;
+ return true;
} else {
int index= statements.indexOf(node);
statements.remove(node);
@@ -437,11 +443,11 @@
return true;
}
- private boolean isInSwitchExpressionOrStatement(BreakStatement node) {
+ private boolean isInSwitchExpression(YieldStatement node) {
boolean result= false;
ASTNode parent= node;
while (parent != null) {
- if (parent instanceof SwitchStatement || parent instanceof SwitchExpression) {
+ if (parent instanceof SwitchExpression) {
result= true;
break;
}
@@ -537,6 +543,7 @@
case JLS10:
case JLS11:
case JLS12:
+ case JLS13:
fCurrentASTLevel= level;
}
} catch (NumberFormatException e) {
@@ -718,7 +725,7 @@
endTime= System.currentTimeMillis();
}
if (root != null) {
- root.accept(new BreakStatementChecker());
+ root.accept(new StatementChecker());
updateContentDescription(input, root, endTime - startTime);
}
return root;
@@ -1168,6 +1175,7 @@
new ASTLevelToggle("AST Level 1&0 (10)", JLS10), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&1 (11)", JLS11), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&2 (12)", JLS12), //$NON-NLS-1$
+ new ASTLevelToggle("AST Level 1&3 (13)", JLS13), //$NON-NLS-1$
};
fAddToTrayAction= new Action() {
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java
index a7e97f9..123a2f4 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java
@@ -7,6 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -23,7 +28,6 @@
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AnnotatableType;
-import org.eclipse.jdt.core.dom.BreakStatement;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ContinueStatement;
@@ -62,6 +66,7 @@
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeMethodReference;
import org.eclipse.jdt.core.dom.UsesDirective;
+import org.eclipse.jdt.core.dom.YieldStatement;
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
@@ -304,9 +309,8 @@
}
@Override
- public boolean visit(BreakStatement node) {
- AST ast= node.getAST();
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ public boolean visit(YieldStatement node) {
+ if (node.getAST().isPreviewEnabled()) {
evalQualifyingExpression(node.getExpression(), null);
}
return false;
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java
index 18911c8..1883642 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -33,7 +37,7 @@
* <p>Clients can make the following assumptions about the AST:</p>
* <ul>
* <li>the AST has a {@link ITypeRoot} as source: {@link CompilationUnit#getTypeRoot()} is not null.</li>
- * <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS12 API level 12} or higher</li>
+ * <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS13 API level 13} or higher</li>
* <li>the AST has bindings resolved ({@link AST#hasResolvedBindings()})</li>
* <li>{@link AST#hasStatementsRecovery() statement} and {@link AST#hasBindingsRecovery() bindings}
* recovery are enabled
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
index fa38c34..5adb4f9 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
@@ -395,6 +399,7 @@
public static String ReorgCorrectionsSubProcessor_50_compliance_changeProjectJREToDefault_description;
public static String ReorgCorrectionsSubProcessor_50_compliance_changeWorkspaceJRE_description;
public static String ReorgCorrectionsSubProcessor_50_compliance_changeProjectJRE_description;
+ public static String ReorgCorrectionsSubProcessor_combine_two_quickfixes;
public static String ModifierCorrectionSubProcessor_default_visibility_label;
public static String UnresolvedElementsSubProcessor_change_to_static_import_description;
public static String ReorgCorrectionsSubProcessor_configure_buildpath_label;
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
index c792e7c..784c446 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
@@ -8,6 +8,10 @@
#
# SPDX-License-Identifier: EPL-2.0
#
+# This is an implementation of an early-draft specification developed under the Java
+# Community Process (JCP) and is made available for testing and evaluation purposes
+# only. The code is not compatible with any specification of the JCP.
+#
# Contributors:
# IBM Corporation - initial API and implementation
# Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
@@ -80,6 +84,7 @@
ReorgCorrectionsSubProcessor_project_seup_fix_info=Evaluates project setup fixes to resolve the reference to the missing element ''{0}''
ReorgCorrectionsSubProcessor_open_required_project_description=Open required project ''{0}''
ReorgCorrectionsSubProcessor_open_required_projects_description=Open required projects ''{0}''
+ReorgCorrectionsSubProcessor_combine_two_quickfixes={0} and {1}
LocalCorrectionsSubProcessor_surroundwith_trycatch_description=Surround with try/catch
LocalCorrectionsSubProcessor_surroundwith_trycatch_var_description=Change type of ''{0}'' to ''{1}'' and surround with try/catch
@@ -482,8 +487,8 @@
NullAnnotationsCorrectionProcessor_create_packageInfo_with_defaultnullness=Add package-info.java with ''@{0}''
PreviewFeaturesSubProcessor_enable_preview_features=Enable preview features on project properties
PreviewFeaturesSubProcessor_enable_preview_features_workspace=Enable preview features on workspace preferences
-PreviewFeaturesSubProcessor_enable_preview_features_info=Enable preview features on Java > Compiler properties page
-PreviewFeaturesSubProcessor_enable_preview_features_workspace_info=Enable preview features on Java > Compiler preference page
+PreviewFeaturesSubProcessor_enable_preview_features_info=<p>Enable preview features on Java > Compiler properties page
+PreviewFeaturesSubProcessor_enable_preview_features_workspace_info=<p>Enable preview features on Java > Compiler preference page
PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features=Open compiler preferences or properties
PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features_info=Open Java > Compiler properties or preference page to enable preview features
PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features=Open project compiler properties
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
index 6c94e0c..63c4019 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -296,8 +300,7 @@
break;
case ASTNode.SWITCH_CASE:
SwitchCase switchCase= (SwitchCase) parent;
- AST ast= switchCase.getAST();
- if (node.equals(switchCase.getExpression()) || (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled() && switchCase.expressions().contains(node))) {
+ if (node.equals(switchCase.getExpression()) || (switchCase.getAST().isPreviewEnabled() && switchCase.expressions().contains(node))) {
ASTNode caseParent= switchCase.getParent();
if (caseParent instanceof SwitchStatement) {
return ((SwitchStatement) caseParent).getExpression().resolveTypeBinding();
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
index 0fb5091..d839530 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -46,8 +50,8 @@
*/
@Deprecated
private static final int JLS9= AST.JLS9;
-
- private static final int JLS12= AST.JLS12;
+
+ private static final int JLS13= AST.JLS13;
/**
* The string buffer into which the serialized representation of the AST is
@@ -366,23 +370,16 @@
return false;
}
+ /*
+ * @see ASTVisitor#visit(BreakStatement)
+ */
@Override
public boolean visit(BreakStatement node) {
- int apiLevel= node.getAST().apiLevel();
- if (apiLevel == JLS12 && node.getAST().isPreviewEnabled() && node.isImplicit() && node.getExpression() == null) {
- return false;
- }
this.fBuffer.append("break");//$NON-NLS-1$
if (node.getLabel() != null) {
this.fBuffer.append(" ");//$NON-NLS-1$
node.getLabel().accept(this);
}
- if (apiLevel == JLS12 && node.getAST().isPreviewEnabled()) {
- if (node.getExpression() != null) {
- this.fBuffer.append(" ");//$NON-NLS-1$
- node.getExpression().accept(this);
- }
- }
this.fBuffer.append(";");//$NON-NLS-1$
return false;
}
@@ -1539,7 +1536,7 @@
@Override
public boolean visit(SwitchCase node) {
- if (node.getAST().apiLevel() >= JLS12) {
+ if (node.getAST().isPreviewEnabled()) {
if (node.isDefault()) {
this.fBuffer.append("default");//$NON-NLS-1$
this.fBuffer.append(node.isSwitchLabeledRule() ? " ->" : ":");//$NON-NLS-1$ //$NON-NLS-2$
@@ -1565,6 +1562,20 @@
}
@Override
+ public boolean visit(YieldStatement node) {
+ if (node.getAST().apiLevel() == JLS13 && node.isImplicit() && node.getExpression() == null) {
+ return false;
+ }
+ this.fBuffer.append("yield"); //$NON-NLS-1$
+ if (node.getExpression() != null) {
+ this.fBuffer.append(" ");//$NON-NLS-1$
+ node.getExpression().accept(this);
+ }
+ this.fBuffer.append(";");//$NON-NLS-1$
+ return false;
+ }
+
+ @Override
public boolean visit(SwitchStatement node) {
visitSwitchNode(node);
return false;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java
index 8b38454..b4cda89 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -838,6 +842,10 @@
return visitNode(node);
}
@Override
+ public boolean visit(TextBlock node) {
+ return visitNode(node);
+ }
+ @Override
public boolean visit(UnionType node) {
return visitNode(node);
}
@@ -865,4 +873,8 @@
public boolean visit(WildcardType node) {
return visitNode(node);
}
+ @Override
+ public boolean visit(YieldStatement node) {
+ return visitNode(node);
+ }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java
index a67524b..56d18e2 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java
@@ -7,6 +7,10 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -479,6 +483,16 @@
endVisit((Expression)node);
}
+ @Override
+ public boolean visit(YieldStatement node) {
+ return visit((Statement)node);
+ }
+
+ @Override
+ public void endVisit(YieldStatement node) {
+ endVisit((Statement)node);
+ }
+
//---- Begin MethodReference Hierarchy ----------------------------------
public boolean visit(MethodReference node) {
return visit((Expression)node);
@@ -620,7 +634,7 @@
public void endVisit(StringLiteral node) {
endVisit((Expression)node);
}
-
+
@Override
public boolean visit(SuperFieldAccess node) {
return visit((Expression)node);
@@ -635,6 +649,11 @@
public boolean visit(SuperMethodInvocation node) {
return visit((Expression)node);
}
+
+ @Override
+ public boolean visit(TextBlock node) {
+ return visit((Expression)node);
+ }
@Override
public void endVisit(SuperMethodInvocation node) {
@@ -642,6 +661,11 @@
}
@Override
+ public void endVisit(TextBlock node) {
+ endVisit((Expression)node);
+ }
+
+ @Override
public boolean visit(ThisExpression node) {
return visit((Expression)node);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/IASTSharedValues.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/IASTSharedValues.java
index 59dedfb..fcb3f99 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/IASTSharedValues.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/IASTSharedValues.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -21,7 +25,7 @@
* This value is subject to change with every release. JDT-UI-internal code typically supports
* the latest available {@link AST#apiLevel() AST level} exclusively.
*/
- public static final int SHARED_AST_LEVEL= AST.JLS12;
+ public static final int SHARED_AST_LEVEL= AST.JLS13;
public static final boolean SHARED_AST_STATEMENT_RECOVERY= true;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
index 5208c1c..068ce55 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
@@ -7,6 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -18,7 +23,6 @@
import java.util.HashSet;
import java.util.List;
-import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
@@ -724,8 +728,7 @@
public boolean visit(SwitchCase node) {
// switch on enum allows to use enum constants without qualification
if (hasFlag(VARIABLES, fFlags) && !node.isDefault()) {
- AST ast= node.getAST();
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (node.getAST().isPreviewEnabled()) {
List<Expression> expressions= node.expressions();
for (Expression expression : expressions) {
visitExpression(node, expression);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
index 079e585..64a0972 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -48,7 +52,6 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
-import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
@@ -387,8 +390,7 @@
public static boolean isEnumCase(ASTNode node) {
if (node instanceof SwitchCase) {
final SwitchCase caze= (SwitchCase) node;
- AST ast= node.getAST();
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (node.getAST().isPreviewEnabled()) {
List<Expression> expressions= caze.expressions();
boolean isEnumConst= true;
for (Expression expression : expressions) {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
index bd246cd..daef8d5 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
@@ -77,7 +81,7 @@
*/
public static final String VERSION_LATEST;
static {
- VERSION_LATEST= JavaCore.VERSION_12; // make sure it is not inlined
+ VERSION_LATEST= JavaCore.VERSION_13; // make sure it is not inlined
}
public static final int VALIDATE_EDIT_CHANGED_CONTENT= 10003;
@@ -824,6 +828,10 @@
return !isVersionLessThan(compliance, JavaCore.VERSION_12);
}
+ public static boolean is13OrHigher(String compliance) {
+ return !isVersionLessThan(compliance, JavaCore.VERSION_13);
+ }
+
/**
* Checks if the given project or workspace has source compliance 1.5 or greater.
*
@@ -890,6 +898,16 @@
return is12OrHigher(getSourceCompliance(project));
}
+ /**
+ * Checks if the given project or workspace has source compliance 13 or greater.
+ *
+ * @param project the project to test or <code>null</code> to test the workspace settings
+ * @return <code>true</code> if the given project or workspace has source compliance 13 or greater.
+ */
+ public static boolean is13OrHigher(IJavaProject project) {
+ return is13OrHigher(getSourceCompliance(project));
+ }
+
private static String getSourceCompliance(IJavaProject project) {
return project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE);
}
@@ -923,6 +941,8 @@
String version= vMInstall.getJavaVersion();
if (version == null) {
return defaultCompliance;
+ } else if (version.startsWith(JavaCore.VERSION_13)) {
+ return JavaCore.VERSION_13;
} else if (version.startsWith(JavaCore.VERSION_12)) {
return JavaCore.VERSION_12;
} else if (version.startsWith(JavaCore.VERSION_11)) {
@@ -961,7 +981,9 @@
// fallback:
String desc= executionEnvironment.getId();
- if (desc.indexOf(JavaCore.VERSION_12) != -1) {
+ if (desc.indexOf(JavaCore.VERSION_13) != -1) {
+ return JavaCore.VERSION_13;
+ } else if (desc.indexOf(JavaCore.VERSION_12) != -1) {
return JavaCore.VERSION_12;
} else if (desc.indexOf(JavaCore.VERSION_11) != -1) {
return JavaCore.VERSION_11;
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java
index d95f6aa..4aa02f6 100644
--- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java
+++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java
@@ -7,6 +7,10 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* David Saff (saff@mit.edu) - initial API and implementation
@@ -208,7 +212,7 @@
if (CoreTestSearchEngine.hasSuiteMethod(type)) { // since JUnit 4.3.1
return true;
}
- ASTParser parser= ASTParser.newParser(AST.JLS12);
+ ASTParser parser= ASTParser.newParser(AST.JLS13);
/* TODO: When bug 156352 is fixed:
parser.setProject(type.getJavaProject());
IBinding[] bindings= parser.createBindings(new IJavaElement[] { type }, monitor);
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit5TestFinder.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit5TestFinder.java
index 563865e..d420c75 100644
--- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit5TestFinder.java
+++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit5TestFinder.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -257,7 +261,7 @@
if (CoreTestSearchEngine.hasSuiteMethod(type)) { // since JUnit 4.3.1
return true;
}
- ASTParser parser= ASTParser.newParser(AST.JLS12);
+ ASTParser parser= ASTParser.newParser(AST.JLS13);
if (type.getCompilationUnit() != null) {
parser.setSource(type.getCompilationUnit());
} else if (!isAvailable(type.getSourceRange())) { // class file with no source
diff --git a/org.eclipse.jdt.junit/forceQualifierUpdate.txt b/org.eclipse.jdt.junit/forceQualifierUpdate.txt
index 5fd5b28..b4baf4b 100644
--- a/org.eclipse.jdt.junit/forceQualifierUpdate.txt
+++ b/org.eclipse.jdt.junit/forceQualifierUpdate.txt
@@ -1,4 +1,5 @@
# To force a version qualifier update, add the bug here
+Bug 549784: Comparator errors in Y20190801-0900
Bug 545576: [12] Push Java 12 work to master
Bug 509973 - Comparator errors in I20170105-0320
Bug 539509 - Comparator errors in jdt.ui bundles in I20180926-0830
diff --git a/org.eclipse.jdt.text.tests/forceQualifierUpdate.txt b/org.eclipse.jdt.text.tests/forceQualifierUpdate.txt
index bbee91d..9914b4c 100644
--- a/org.eclipse.jdt.text.tests/forceQualifierUpdate.txt
+++ b/org.eclipse.jdt.text.tests/forceQualifierUpdate.txt
@@ -1,4 +1,5 @@
# To force a version qualifier update, add the bug here
+Bug 549784: Comparator errors in Y20190801-0900
Bug 545576: [12] Push Java 12 work to master
BETA_JAVA9 merge into R4_7_maintenance
Adopt change of IASTSharedValues.SHARED_AST_LEVEL to 10
diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java
index f871dda..932983f 100644
--- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java
+++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
@@ -102,6 +106,7 @@
public static final IPath RT_STUBS_9= new Path("testresources/rtstubs9.jar");
public static final IPath RT_STUBS_10= new Path("testresources/rtstubs10.jar");
public static final IPath RT_STUBS_12= new Path("testresources/rtstubs12.jar");
+ public static final IPath RT_STUBS13= new Path("testresources/rtstubs13.jar");
public static final IPath JUNIT_SRC_381= new Path("testresources/junit381-noUI-src.zip");
public static final String JUNIT_SRC_ENCODING= "ISO-8859-1";
@@ -227,7 +232,7 @@
}
/**
- * Sets the compiler options to 10 for the given project.
+ * Sets the compiler options to 12 for the given project.
*
* @param project the java project
* @param enable_preview_feature sets enable-preview compliance project option based on the value specified.
@@ -242,6 +247,23 @@
}
project.setOptions(options);
}
+
+ /**
+ * Sets the compiler options to 13 for the given project.
+ *
+ * @param project the java project
+ * @param enable_preview_feature sets enable-preview compliance project option based on the value specified.
+ * @since 3.19
+ */
+ public static void set13CompilerOptions(IJavaProject project, boolean enable_preview_feature) {
+ Map<String, String> options= project.getOptions(false);
+ set13_CompilerOptions(options);
+ if (enable_preview_feature) {
+ options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ }
+ project.setOptions(options);
+ }
/**
* Sets the compiler options to 1.8 for the given project.
@@ -322,6 +344,15 @@
public static void set12CompilerOptions(Map<String, String> options) {
JavaCore.setComplianceOptions(JavaCore.VERSION_12, options);
}
+
+ /**
+ * Sets the compiler options to 13.
+ *
+ * @param options the compiler options to configure
+ */
+ public static void set13_CompilerOptions(Map<String, String> options) {
+ JavaCore.setComplianceOptions(JavaCore.VERSION_13, options);
+ }
/**
* Sets the compiler options to 1.8
diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java
index 10696fb..10c6b4a 100644
--- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java
+++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -100,6 +104,8 @@
//9:
"java.lang.module",
"java.nio.file.spi",
+ //13:
+ "java.lang.constant"
};
private static final String SETTINGS_ID_STUBS_PROJECT= "stubsProject";
diff --git a/org.eclipse.jdt.ui.tests/testresources/rtstubs13.jar b/org.eclipse.jdt.ui.tests/testresources/rtstubs13.jar
new file mode 100644
index 0000000..1055d6f
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests/testresources/rtstubs13.jar
Binary files differ
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java
index a192663..8f7928c 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 IBM Corporation and others.
+ * Copyright (c) 2015, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,6 +7,10 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* Stephan Herrmann - Contribution for Bug 403917 - [1.8] Render TYPE_USE annotations in Javadoc hover/view
@@ -56,7 +60,7 @@
}
protected String getBindingLabel(IJavaElement elem, long flags) {
- ASTParser parser= ASTParser.newParser(AST.JLS12);
+ ASTParser parser= ASTParser.newParser(AST.JLS13);
parser.setResolveBindings(true);
parser.setProject(fJProject1);
IBinding binding= parser.createBindings(new IJavaElement[]{elem}, null)[0];
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java
new file mode 100644
index 0000000..cf23fd1
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.ui.tests.core;
+
+import org.eclipse.jdt.testplugin.JavaProjectHelper;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+import org.eclipse.jdt.internal.core.ClasspathEntry;
+
+import junit.framework.Test;
+
+public class Java13ProjectTestSetup extends ProjectTestSetup {
+
+ public static final String PROJECT_NAME13= "TestSetupProject13";
+
+ private boolean enable_preview_feature;
+
+ public static IJavaProject getProject() {
+ IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME13);
+ return JavaCore.create(project);
+ }
+
+ public static IClasspathEntry[] getDefaultClasspath() throws CoreException {
+ IPath[] rtJarPath= JavaProjectHelper.findRtJar(JavaProjectHelper.RT_STUBS13);
+ IClasspathAttribute[] extraAttributes= { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, Boolean.TRUE.toString()) };
+ return new IClasspathEntry[] { JavaCore.newLibraryEntry(rtJarPath[0], rtJarPath[1], rtJarPath[2], ClasspathEntry.NO_ACCESS_RULES, extraAttributes, true) };
+ }
+
+ public Java13ProjectTestSetup(Test test, boolean enable_preview_feature) {
+ super(test);
+ this.enable_preview_feature= enable_preview_feature;
+ }
+
+ @Override
+ protected boolean projectExists() {
+ return getProject().exists();
+ }
+
+ @Override
+ protected IJavaProject createAndInitializeProject() throws CoreException {
+ IJavaProject javaProject= JavaProjectHelper.createJavaProject(PROJECT_NAME13, "bin");
+ javaProject.setRawClasspath(getDefaultClasspath(), null);
+ JavaProjectHelper.set12CompilerOptions(javaProject, enable_preview_feature);
+ return javaProject;
+ }
+
+}
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java
index 4ae8db4..030d48e 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Jens Reimann - add method to convert a collection of previews
@@ -86,7 +90,7 @@
TestSuite suite= new TestSuite(QuickFixTest.class.getName());
suite.addTest(QuickFixTest9.suite());
suite.addTest(QuickFixTest18.suite());
- suite.addTest(QuickFixTest12.suite());
+ suite.addTest(QuickFixTest13.suite());
suite.addTest(SerialVersionQuickFixTest.suite());
suite.addTest(UtilitiesTest.suite());
suite.addTest(UnresolvedTypesQuickFixTest.suite());
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest13.java
similarity index 80%
rename from org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java
rename to org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest13.java
index 046e84d..9b03423 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest13.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -25,7 +29,10 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.ui.tests.core.Java12ProjectTestSetup;
+import org.eclipse.jdt.internal.corext.util.Messages;
+
+import org.eclipse.jdt.ui.tests.core.Java10ProjectTestSetup;
+import org.eclipse.jdt.ui.tests.core.Java13ProjectTestSetup;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal;
@@ -34,24 +41,24 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-public class QuickFixTest12 extends QuickFixTest {
+public class QuickFixTest13 extends QuickFixTest {
- private static final Class<QuickFixTest12> THIS= QuickFixTest12.class;
+ private static final Class<QuickFixTest13> THIS= QuickFixTest13.class;
private IJavaProject fJProject1;
private IPackageFragmentRoot fSourceFolder;
- public QuickFixTest12(String name) {
+ public QuickFixTest13(String name) {
super(name);
}
public static Test suite() {
- return new Java12ProjectTestSetup(new TestSuite(THIS), true);
+ return new Java13ProjectTestSetup(new TestSuite(THIS), true);
}
public static Test setUpTest(Test test) {
- Test testToReturn= new Java12ProjectTestSetup(test, true);
+ Test testToReturn= new Java13ProjectTestSetup(test, true);
return testToReturn;
}
@@ -70,20 +77,19 @@
}
public void testEnablePreviewsAndOpenCompilerPropertiesProposals() throws Exception {
-
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, false);
-
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, false);
+
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
-
+
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -91,10 +97,10 @@
buf.append(" String foo(Day day) {\n");
buf.append(" int x = 0;\n");
buf.append(" var today = switch(day){\n");
- buf.append(" case SATURDAY, SUNDAY: break \"Weekend day\";\n");
+ buf.append(" case SATURDAY, SUNDAY: yield \"Weekend day\";\n");
buf.append(" case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY: {\n");
buf.append(" var kind = \"Working day\";\n");
- buf.append(" break kind;\n");
+ buf.append(" yield kind;\n");
buf.append(" }\n");
buf.append(" default: {\n");
buf.append(" var kind = day.name();\n");
@@ -106,7 +112,7 @@
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
buf= new StringBuffer();
buf= new StringBuffer();
buf.append("package test;\n");
@@ -120,32 +126,31 @@
buf.append(" SATURDAY\n");
buf.append("}\n");
pack.createCompilationUnit("Day.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
- ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 7, null);
-
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 11, null);
+
assertNumberOfProposals(proposals, 2);
String label1= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features;
assertProposalExists(proposals, label1);
String label2= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features;
assertProposalExists(proposals, label2);
}
-
- public void testNoEnablePreviewProposal() throws Exception {
-
+
+ public void testGetNeedHigherComplianceProposalsAndEnablePreviewsProposal() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
-
+ fJProject1.setRawClasspath(Java10ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set12CompilerOptions(fJProject1, false);
+
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
-
+
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -153,10 +158,10 @@
buf.append(" String foo(Day day) {\n");
buf.append(" int x = 0;\n");
buf.append(" var today = switch(day){\n");
- buf.append(" case SATURDAY, SUNDAY: break \"Weekend day\";\n");
+ buf.append(" case SATURDAY, SUNDAY: yield \"Weekend day\";\n");
buf.append(" case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY: {\n");
buf.append(" var kind = \"Working day\";\n");
- buf.append(" break kind;\n");
+ buf.append(" yield kind;\n");
buf.append(" }\n");
buf.append(" default: {\n");
buf.append(" var kind = day.name();\n");
@@ -168,7 +173,7 @@
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
buf= new StringBuffer();
buf= new StringBuffer();
buf.append("package test;\n");
@@ -182,25 +187,86 @@
buf.append(" SATURDAY\n");
buf.append("}\n");
pack.createCompilationUnit("Day.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
- ArrayList<ICompletionProposal> proposals= collectAllCorrections(cu, astRoot, 0);
-
- assertNumberOfProposals(proposals, 0);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 10, null);
+
+ assertNumberOfProposals(proposals, 1);
+ String label1= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_change_project_compliance_description, "13");
+ String label2= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features;
+ String label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_combine_two_quickfixes, new String[] {label1, label2});
+ assertProposalExists(proposals, label);
}
- public void testAddDefaultCaseSwitchStatement1() throws Exception {
+ public void testNoEnablePreviewProposal() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
+
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
+
+ IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class Cls {\n");
+ buf.append(" String foo(Day day) {\n");
+ buf.append(" int x = 0;\n");
+ buf.append(" var today = switch(day){\n");
+ buf.append(" case SATURDAY, SUNDAY: yield \"Weekend day\";\n");
+ buf.append(" case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY: {\n");
+ buf.append(" var kind = \"Working day\";\n");
+ buf.append(" yield kind;\n");
+ buf.append(" }\n");
+ buf.append(" default: {\n");
+ buf.append(" var kind = day.name();\n");
+ buf.append(" System.out.println(kind + x);\n");
+ buf.append(" throw new IllegalArgumentException(\"Invalid day: \" + kind);\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" return today;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
+
+ buf= new StringBuffer();
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public enum Day {\n");
+ buf.append(" SUNDAY,\n");
+ buf.append(" MONDAY,\n");
+ buf.append(" TUESDAY,\n");
+ buf.append(" WEDNESDAY,\n");
+ buf.append(" THURSDAY,\n");
+ buf.append(" FRIDAY,\n");
+ buf.append(" SATURDAY\n");
+ buf.append("}\n");
+ pack.createCompilationUnit("Day.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<ICompletionProposal> proposals= collectAllCorrections(cu, astRoot, 0);
+
+ assertNumberOfProposals(proposals, 0);
+ }
+ public void testAddDefaultCaseSwitchStatement1() throws Exception {
+ fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
+
+ StringBuffer buf= new StringBuffer();
+ buf.append("module test {\n");
+ buf.append("}\n");
+ IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
+ def.createCompilationUnit("module-info.java", buf.toString(), false, null);
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -217,15 +283,15 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
@@ -242,22 +308,22 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddDefaultCaseSwitchStatement2() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -274,15 +340,15 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
@@ -300,22 +366,22 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddDefaultCaseSwitchStatement3() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -330,15 +396,15 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 7);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(1);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
@@ -354,22 +420,22 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddMissingCaseSwitchStatement1() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -386,15 +452,15 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
@@ -413,22 +479,22 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddDefaultCaseSwitchExpression1() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -439,21 +505,21 @@
buf.append(" case 70 -> 7;\n");
buf.append(" case 80 -> 8;\n");
buf.append(" case 90, 900 -> {\n");
- buf.append(" break 9;\n");
+ buf.append(" yield 9;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
@@ -463,29 +529,29 @@
buf.append(" case 70 -> 7;\n");
buf.append(" case 80 -> 8;\n");
buf.append(" case 90, 900 -> {\n");
- buf.append(" break 9;\n");
+ buf.append(" yield 9;\n");
buf.append(" }\n");
buf.append(" default -> throw new IllegalArgumentException(\"Unexpected value: \" + input);\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddDefaultCaseSwitchExpression2() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -493,39 +559,39 @@
buf.append(" public static void bar4(int input) {\n");
buf.append(" int num = switch (input) {\n");
buf.append(" case 60, 600:\n");
- buf.append(" break 6;\n");
+ buf.append(" yield 6;\n");
buf.append(" case 70:\n");
- buf.append(" break 7;\n");
+ buf.append(" yield 7;\n");
buf.append(" case 80:\n");
- buf.append(" break 8;\n");
+ buf.append(" yield 8;\n");
buf.append(" case 90, 900:\n");
- buf.append(" break 9;\n");
+ buf.append(" yield 9;\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
buf.append(" public static void bar4(int input) {\n");
buf.append(" int num = switch (input) {\n");
buf.append(" case 60, 600:\n");
- buf.append(" break 6;\n");
+ buf.append(" yield 6;\n");
buf.append(" case 70:\n");
- buf.append(" break 7;\n");
+ buf.append(" yield 7;\n");
buf.append(" case 80:\n");
- buf.append(" break 8;\n");
+ buf.append(" yield 8;\n");
buf.append(" case 90, 900:\n");
- buf.append(" break 9;\n");
+ buf.append(" yield 9;\n");
buf.append(" default :\n");
buf.append(" throw new IllegalArgumentException(\n");
buf.append(" \"Unexpected value: \" + input);\n");
@@ -533,22 +599,22 @@
buf.append(" }\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
public void testAddMissingCaseSwitchExpression() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
- fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
- JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fJProject1.setRawClasspath(Java13ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set13CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
-
+
StringBuffer buf= new StringBuffer();
buf.append("module test {\n");
buf.append("}\n");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit("module-info.java", buf.toString(), false, null);
-
+
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
buf= new StringBuffer();
buf.append("package test;\n");
@@ -556,11 +622,11 @@
buf.append(" public void bar1(Day day) {\n");
buf.append(" int len = switch (day) {\n");
buf.append(" case MONDAY, FRIDAY:\n");
- buf.append(" break 6;\n");
+ buf.append(" yield 6;\n");
buf.append(" case TUESDAY:\n");
- buf.append(" break 7;\n");
+ buf.append(" yield 7;\n");
buf.append(" case THURSDAY, SATURDAY:\n");
- buf.append(" break 8;\n");
+ buf.append(" yield 8;\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
@@ -568,26 +634,26 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
-
+
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
-
+
CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
String preview= getPreviewContent(proposal);
-
+
buf= new StringBuffer();
buf.append("package test;\n");
buf.append("public class Cls {\n");
buf.append(" public void bar1(Day day) {\n");
buf.append(" int len = switch (day) {\n");
buf.append(" case MONDAY, FRIDAY:\n");
- buf.append(" break 6;\n");
+ buf.append(" yield 6;\n");
buf.append(" case TUESDAY:\n");
- buf.append(" break 7;\n");
+ buf.append(" yield 7;\n");
buf.append(" case THURSDAY, SATURDAY:\n");
- buf.append(" break 8;\n");
+ buf.append(" yield 8;\n");
buf.append(" case SUNDAY :\n");
buf.append(" throw new UnsupportedOperationException(\n");
buf.append(" \"Unimplemented case: \" + day);\n");
@@ -604,7 +670,7 @@
buf.append(" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n");
buf.append("}\n");
String expected= buf.toString();
-
+
assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
diff --git a/org.eclipse.jdt.ui/.settings/.api_filters b/org.eclipse.jdt.ui/.settings/.api_filters
index 8363dfc..cc58423 100644
--- a/org.eclipse.jdt.ui/.settings/.api_filters
+++ b/org.eclipse.jdt.ui/.settings/.api_filters
@@ -160,4 +160,12 @@
</message_arguments>
</filter>
</resource>
+ <resource path="ui/org/eclipse/jdt/ui/text/IJavaPartitions.java" type="org.eclipse.jdt.ui.text.IJavaPartitions">
+ <filter id="403767336">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.ui.text.IJavaPartitions"/>
+ <message_argument value="JAVA_MULTI_LINE_STRING"/>
+ </message_arguments>
+ </filter>
+ </resource>
</component>
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaFormatter.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaFormatter.java
index 4f0dff5..9d01015 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaFormatter.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaFormatter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -51,6 +55,7 @@
import org.eclipse.jdt.internal.ui.javaeditor.IndentUtil;
import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitioner;
/**
* A template editor using the Java formatter to format a template buffer.
@@ -86,11 +91,11 @@
* @throws MalformedTreeException
* @throws BadLocationException
*/
- public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException {
+ public VariableTracker(TemplateBuffer buffer, IJavaProject project) throws MalformedTreeException, BadLocationException {
Assert.isLegal(buffer != null);
fBuffer= buffer;
fDocument= new Document(fBuffer.getString());
- installJavaStuff(fDocument);
+ installJavaStuff(fDocument, project);
fDocument.addPositionCategory(CATEGORY);
fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY));
fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument);
@@ -100,17 +105,19 @@
* Installs a java partitioner with <code>document</code>.
*
* @param document the document
+ * @param project the project associated with the document
*/
- private static void installJavaStuff(Document document) {
+ private static void installJavaStuff(Document document, IJavaProject project) {
String[] types= new String[] {
IJavaPartitions.JAVA_DOC,
IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
IJavaPartitions.JAVA_STRING,
IJavaPartitions.JAVA_CHARACTER,
+ IJavaPartitions.JAVA_MULTI_LINE_STRING,
IDocument.DEFAULT_CONTENT_TYPE
};
- FastPartitioner partitioner= new FastPartitioner(new FastJavaPartitionScanner(), types);
+ FastPartitioner partitioner= new FastJavaPartitioner(new FastJavaPartitionScanner(project), types);
partitioner.connect(document);
document.setDocumentPartitioner(IJavaPartitions.JAVA_PARTITIONING, partitioner);
}
@@ -260,7 +267,7 @@
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
- VariableTracker tracker= new VariableTracker(buffer);
+ VariableTracker tracker= new VariableTracker(buffer, fProject);
IDocument document= tracker.getDocument();
internalFormat(document, context);
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/StubCreator.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/StubCreator.java
index 0bd3f8d..632aff8 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/StubCreator.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/StubCreator.java
@@ -8,14 +8,20 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.binary;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import org.eclipse.core.runtime.Assert;
@@ -111,10 +117,18 @@
}
protected void appendFlags(final IMember member) throws JavaModelException {
- if (member instanceof IAnnotatable)
- for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) {
- appendAnnotation(annotation);
+ if (member instanceof IAnnotatable) {
+ IAnnotation[] annotations= ((IAnnotatable) member).getAnnotations();
+ Set<IAnnotation> annotationSet= new HashSet<>();
+ for (IAnnotation annotation : annotations) {
+ if (!annotationSet.contains(annotation)) {
+ appendAnnotation(annotation);
+ annotationSet.add(annotation);
+ }
}
+ annotationSet.clear();
+ annotationSet= null;
+ }
int flags= member.getFlags();
final int kind= member.getElementType();
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
index 6d4b252..22a4870 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Eicher (Avaloq Evolution AG) - block selection mode
@@ -54,6 +58,10 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.jdt.core.formatter.IndentManipulation;
+
+import org.eclipse.jdt.internal.core.manipulation.util.Strings;
+import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
import org.eclipse.jdt.ui.text.IJavaPartitions;
@@ -118,6 +126,10 @@
*/
private final boolean fIsTabAction;
+ public static String TEXT_BLOCK_STR= "\"\"\""; //$NON-NLS-1$
+ public static String SPACE_STR= " "; //$NON-NLS-1$
+ public static String EMPTY_STR= ""; //$NON-NLS-1$
+
/**
* Creates a new instance.
*
@@ -345,6 +357,43 @@
removeIndentations(slashes, getTabSize(project), computed);
indent= document.get(offset, wsStart - offset) + computed;
}
+ } else if (IJavaPartitions.JAVA_MULTI_LINE_STRING.equals(type)) {
+ String fullStrNoTrim= document.get(currentLine.getOffset(), currentLine.getLength());
+ String fullStr= document.get(currentLine.getOffset(), currentLine.getLength()).trim();
+ int length= IndentManipulation.measureIndentInSpaces(fullStrNoTrim, CodeFormatterUtil.getTabWidth(project));
+ int partitionOffset= partition.getOffset();
+ IRegion PartitionStartline= document.getLineInformationOfOffset(partitionOffset);
+ String PartitionStartStrNoTrim= document.get(PartitionStartline.getOffset(), PartitionStartline.getLength());
+ int startIndex= PartitionStartStrNoTrim.lastIndexOf(TEXT_BLOCK_STR);
+ if (!fullStrNoTrim.equals(PartitionStartStrNoTrim) && startIndex != -1) {
+ int partitionStartLength= measureLengthInSpaces(PartitionStartStrNoTrim.substring(0, startIndex), CodeFormatterUtil.getTabWidth(project));
+ boolean calculateIndent= false;
+ String str= EMPTY_STR;
+ int strLength= 0;
+ if (partitionStartLength > length) {
+ calculateIndent= true;
+ strLength= length;
+ } else if (fullStr.startsWith(TEXT_BLOCK_STR) && partitionStartLength != length) {
+ calculateIndent= true;
+ strLength= partitionStartLength;
+ } else {
+ indent= getLineIndentation(document, currentLine.getOffset());
+ }
+ if (calculateIndent) {
+ for (int i= 0; i < strLength; i++) {
+ str+= SPACE_STR;
+ }
+ int units= Strings.computeIndentUnits(str, project);
+ String newStr= CodeFormatterUtil.createIndentString(units, project);
+ int newLength= IndentManipulation.measureIndentInSpaces(newStr, CodeFormatterUtil.getTabWidth(project));
+ if (newLength < partitionStartLength) {
+ for (int i= newLength; i < partitionStartLength; i++) {
+ newStr+= SPACE_STR;
+ }
+ }
+ indent= newStr;
+ }
+ }
}
}
@@ -371,6 +420,56 @@
return new ReplaceData(offset, end, indent);
}
+ private static String getLineIndentation(IDocument document, int offset) throws BadLocationException {
+ // find start of line
+ int adjustedOffset= (offset == document.getLength() ? offset - 1 : offset);
+ IRegion line= document.getLineInformationOfOffset(adjustedOffset);
+ int start= line.getOffset();
+
+ // find white spaces
+ int end= findEndOfWhiteSpace(document, start, offset + line.getLength());
+
+ return document.get(start, end - start);
+ }
+
+ private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException {
+ while (offset < end) {
+ char c= document.getChar(offset);
+ if (c != ' ' && c != '\t') {
+ return offset;
+ }
+ offset++;
+ }
+ return end;
+ }
+
+ public static int measureLengthInSpaces(CharSequence line, int tabWidth) {
+ if (tabWidth < 0 || line == null) {
+ throw new IllegalArgumentException();
+ }
+
+ int length= 0;
+ int max= line.length();
+ for (int i= 0; i < max; i++) {
+ char ch= line.charAt(i);
+ if (ch == '\t') {
+ length= calculateSpaceEquivalents(tabWidth, length);
+ } else {
+ length++;
+ }
+ }
+ return length;
+ }
+
+ private static int calculateSpaceEquivalents(int tabWidth, int spaceEquivalents) {
+ if (tabWidth == 0) {
+ return spaceEquivalents;
+ }
+ int remainder= spaceEquivalents % tabWidth;
+ spaceEquivalents+= tabWidth - remainder;
+ return spaceEquivalents;
+ }
+
/**
* Removes <code>count</code> indentations from start
* of <code>buffer</code>. The size of a space character
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/EditorUtility.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/EditorUtility.java
index c99a770..6003939 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/EditorUtility.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/EditorUtility.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -605,6 +609,41 @@
}
/**
+ * Returns the Java project for a given text editor or <code>null</code> if no corresponding
+ * Java project exists.
+ *
+ * @param editor the text editor
+ *
+ * @return the corresponding Java project
+ *
+ * @since 3.19
+ */
+ public static IJavaProject getJavaProject(ITextEditor editor) {
+ if (editor == null)
+ return null;
+
+ IJavaElement element= null;
+ IEditorInput input= editor.getEditorInput();
+ IDocumentProvider provider= editor.getDocumentProvider();
+ if (provider instanceof ICompilationUnitDocumentProvider) {
+ ICompilationUnitDocumentProvider cudp= (ICompilationUnitDocumentProvider) provider;
+ element= cudp.getWorkingCopy(input);
+ } else if (input instanceof IClassFileEditorInput) {
+ IClassFileEditorInput cfei= (IClassFileEditorInput) input;
+ element= cfei.getClassFile();
+ }
+
+ if (element == null) {
+ if (input != null) {
+ return EditorUtility.getJavaProject(input);
+ }
+ return null;
+ }
+
+ return element.getJavaProject();
+ }
+
+ /**
* Returns an array of all editors that have an unsaved content. If the identical content is
* presented in more than one editor, only one of those editor parts is part of the result.
* @param skipNonResourceEditors if <code>true</code>, editors whose inputs do not adapt to {@link IResource}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
index 850e23a..831f97c 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Eicher <eclipse@tom.eicher.name> - [formatting] 'Format Element' in JavaDoc does also format method body - https://bugs.eclipse.org/bugs/show_bug.cgi?id=238746
@@ -204,6 +208,7 @@
import org.eclipse.jdt.ui.actions.JavaSearchActionGroup;
import org.eclipse.jdt.ui.actions.OpenEditorActionGroup;
import org.eclipse.jdt.ui.actions.OpenViewActionGroup;
+import org.eclipse.jdt.ui.text.IJavaPartitionerManager;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
import org.eclipse.jdt.ui.text.JavaTextTools;
@@ -233,6 +238,7 @@
import org.eclipse.jdt.internal.ui.text.DocumentCharacterIterator;
import org.eclipse.jdt.internal.ui.text.JavaChangeHover;
import org.eclipse.jdt.internal.ui.text.JavaPairMatcher;
+import org.eclipse.jdt.internal.ui.text.JavaPartitionerManager;
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
import org.eclipse.jdt.internal.ui.text.JavaWordIterator;
import org.eclipse.jdt.internal.ui.text.PreferencesAdapter;
@@ -2599,6 +2605,7 @@
SourceViewerConfiguration sourceViewerConfiguration= getSourceViewerConfiguration();
if (sourceViewerConfiguration == null || sourceViewerConfiguration instanceof JavaSourceViewerConfiguration) {
JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
+ setEditorInfoInPartitionerManager(this);
setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING));
}
@@ -2677,6 +2684,8 @@
fBreadcrumb= null;
}
+ clearEditorInfoInPartitionerManager(this);
+
uninstallJavaCodeMining();
super.dispose();
@@ -4363,4 +4372,22 @@
return PreferenceConstants.EDITOR_CODEMINING_ENABLED.equals(property) || property.startsWith(PreferenceConstants.EDITOR_JAVA_CODEMINING_PREFIX);
}
+ private void clearEditorInfoInPartitionerManager(JavaEditor editor) {
+ JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
+ IJavaPartitionerManager pManager= textTools.getJavaPartitionerManager();
+ if (pManager instanceof JavaPartitionerManager) {
+ JavaPartitionerManager jpManager= (JavaPartitionerManager) pManager;
+ jpManager.clearEditorInfo(editor);
+ }
+ }
+
+ private void setEditorInfoInPartitionerManager(JavaEditor editor) {
+ JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
+ IJavaPartitionerManager pManager= textTools.getJavaPartitionerManager();
+ if (pManager instanceof JavaPartitionerManager) {
+ JavaPartitionerManager jpManager= (JavaPartitionerManager) pManager;
+ jpManager.setEditorInfo(editor);
+ }
+ }
+
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
index 51488a6..64897f1 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Jesper S Møller - Bug 529432 - Allow JDT UI to target Java 10
@@ -140,6 +144,8 @@
private static final String VERSION_10= JavaCore.VERSION_10;
private static final String VERSION_11= JavaCore.VERSION_11;
private static final String VERSION_12 = JavaCore.VERSION_12;
+ private static final String VERSION_13 = JavaCore.VERSION_13;
+ private static final String VERSION_LATEST = JavaCore.latestSupportedJavaVersion();
private static final String VERSION_JSR14= "jsr14"; //$NON-NLS-1$
private static final String ERROR= JavaCore.ERROR;
@@ -296,7 +302,7 @@
private Composite createComplianceTabContent(Composite folder) {
final String[] complianceVersions= new String[] { VERSION_1_3, VERSION_1_4,
- VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12 };
+ VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13 };
final String[] complianceLabels= new String[] {
PreferencesMessages.ComplianceConfigurationBlock_version13,
PreferencesMessages.ComplianceConfigurationBlock_version14,
@@ -308,10 +314,11 @@
PreferencesMessages.ComplianceConfigurationBlock_version10,
PreferencesMessages.ComplianceConfigurationBlock_version_11,
PreferencesMessages.ComplianceConfigurationBlock_version_12,
+ PreferencesMessages.ComplianceConfigurationBlock_version_13,
};
String[] targetVersions= new String[] { VERSION_CLDC_1_1, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4,
- VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12 };
+ VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13 };
String[] targetLabels= new String[] {
PreferencesMessages.ComplianceConfigurationBlock_versionCLDC11,
PreferencesMessages.ComplianceConfigurationBlock_version11,
@@ -326,6 +333,7 @@
PreferencesMessages.ComplianceConfigurationBlock_version10,
PreferencesMessages.ComplianceConfigurationBlock_version_11,
PreferencesMessages.ComplianceConfigurationBlock_version_12,
+ PreferencesMessages.ComplianceConfigurationBlock_version_13,
};
if (ComplianceConfigurationBlock.VERSION_JSR14.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) {
targetVersions= append(targetVersions, ComplianceConfigurationBlock.VERSION_JSR14);
@@ -333,7 +341,7 @@
}
String[] sourceVersions= new String[] { VERSION_1_3, VERSION_1_4,
- VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12 };
+ VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10, VERSION_11, VERSION_12, VERSION_13 };
String[] sourceLabels= new String[] {
PreferencesMessages.ComplianceConfigurationBlock_version13,
PreferencesMessages.ComplianceConfigurationBlock_version14,
@@ -345,6 +353,7 @@
PreferencesMessages.ComplianceConfigurationBlock_version10,
PreferencesMessages.ComplianceConfigurationBlock_version_11,
PreferencesMessages.ComplianceConfigurationBlock_version_12,
+ PreferencesMessages.ComplianceConfigurationBlock_version_13,
};
final ScrolledPageContent sc1 = new ScrolledPageContent(folder);
@@ -419,7 +428,7 @@
PreferencesMessages.ComplianceConfigurationBlock_ignore
};
- label= PreferencesMessages.ComplianceConfigurationBlock_enable_preview_label;
+ label= Messages.format(PreferencesMessages.ComplianceConfigurationBlock_enable_preview_label, new String[] { getVersionLabel(VERSION_LATEST) });
fEnablePreviewCheck= addCheckBox(group, label, PREF_ENABLE_PREVIEW, new String[] { ENABLED, DISABLED }, indent);
label= PreferencesMessages.ComplianceConfigurationBlock_enable_preview_severity_label;
fReportPreviewCombo= addComboBox(group, label, PREF_PB_REPORT_PREVIEW, warningInfoIgnore, warningInfoIgnoreLabels, indent * 2);
@@ -778,13 +787,13 @@
}
}
- //TODO: Remove once Java SE 11 has been shipped:
- //String selectedCompliance= getValue(PREF_COMPLIANCE);
- //if (VERSION_12.equals(selectedCompliance)) {
- //fJRE50InfoText.setText(
- // "This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."); //$NON-NLS-1$
- //isVisible= true;
- //}
+ //TODO: Comment once Java SE 13 has been shipped:
+ String selectedCompliance= getValue(PREF_COMPLIANCE);
+ if (VERSION_13.equals(selectedCompliance)) {
+ fJRE50InfoText.setText(
+ "This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."); //$NON-NLS-1$
+ isVisible= true;
+ }
fJRE50InfoText.setVisible(isVisible);
fJRE50InfoImage.setImage(isVisible ? image : null);
@@ -1005,15 +1014,15 @@
if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) {
String compatibility= getValue(PREF_SOURCE_COMPATIBILITY);
- boolean isLessThan11= JavaModelUtil.isVersionLessThan(compatibility, VERSION_11);
- updateRememberedComplianceOption(PREF_ENABLE_PREVIEW, IDX_ENABLE_PREVIEW, !isLessThan11, null);
+ boolean isLessThanLatest= JavaModelUtil.isVersionLessThan(compatibility, VERSION_LATEST);
+ updateRememberedComplianceOption(PREF_ENABLE_PREVIEW, IDX_ENABLE_PREVIEW, !isLessThanLatest, null);
updateRememberedComplianceOption(PREF_PB_REPORT_PREVIEW, IDX_REPORT_PREVIEW, fEnablePreviewCheck.isEnabled() && fEnablePreviewCheck.getSelection(), WARNING);
}
}
private void updatePreviewControls() {
String compliance= getValue(PREF_COMPLIANCE);
- if (JavaCore.compareJavaVersions(compliance, JavaCore.VERSION_10) <= 0) {
+ if (JavaCore.compareJavaVersions(compliance, VERSION_LATEST) < 0) {
fEnablePreviewCheck.setSelection(false);
fReportPreviewCombo.select(0);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
index 3050e5a..33786f3 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class
@@ -833,6 +837,7 @@
public static String ComplianceConfigurationBlock_version10;
public static String ComplianceConfigurationBlock_version_11;
public static String ComplianceConfigurationBlock_version_12;
+ public static String ComplianceConfigurationBlock_version_13;
public static String ComplianceConfigurationBlock_versionCLDC11;
public static String ComplianceConfigurationBlock_src_greater_compliance;
public static String ComplianceConfigurationBlock_classfile_greater_compliance;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
index f7eb4d8..192ff86 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
@@ -8,6 +8,10 @@
#
# SPDX-License-Identifier: EPL-2.0
#
+# This is an implementation of an early-draft specification developed under the Java
+# Community Process (JCP) and is made available for testing and evaluation purposes
+# only. The code is not compatible with any specification of the JCP.
+#
# Contributors:
# IBM Corporation - initial API and implementation
# John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class
@@ -587,6 +591,7 @@
ComplianceConfigurationBlock_version10=10
ComplianceConfigurationBlock_version_11=11
ComplianceConfigurationBlock_version_12=12
+ComplianceConfigurationBlock_version_13=13 (BETA)
ComplianceConfigurationBlock_versionCLDC11=CLDC 1.1
ComplianceConfigurationBlock_needsbuild_title=Compiler Settings Changed
@@ -602,7 +607,7 @@
ComplianceConfigurationBlock_codegen_method_parameters_attr=&Store information about method parameters (usable via reflection)
ComplianceConfigurationBlock_compiler_compliance_label=Comp&iler compliance level:
ComplianceConfigurationBlock_default_settings_label=Use defaul&t compliance settings
-ComplianceConfigurationBlock_enable_preview_label=Enable &preview features
+ComplianceConfigurationBlock_enable_preview_label=Enable &preview features for Java {0}
ComplianceConfigurationBlock_enable_preview_severity_label=Preview features with se&verity level:
ComplianceConfigurationBlock_source_compatibility_label=Source co&mpatibility:
ComplianceConfigurationBlock_codegen_targetplatform_label=Ge&nerated .class files compatibility:
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitionScanner.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitionScanner.java
index 5178380..b59c238 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitionScanner.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitionScanner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,20 +8,37 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+
import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.text.correction.PreviewFeaturesSubProcessor;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
/**
* This scanner recognizes the JavaDoc comments, Java multi line comments, Java single line comments,
@@ -36,6 +53,7 @@
private static final int JAVADOC= 3;
private static final int CHARACTER= 4;
private static final int STRING= 5;
+ private static final int MULTI_LINE_STRING= 6;
// beginning of prefixes and postfixes
private static final int NONE= 0;
@@ -45,6 +63,7 @@
private static final int SLASH_STAR_STAR= 4; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int STAR= 5; // postfix for MULTI_LINE_COMMENT or JAVADOC
private static final int CARRIAGE_RETURN=6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
+ private static final int TRIPLE_QUOTE= 9; // prefix for TextBlock.
/** The scanner. */
private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000); // faster implementation
@@ -66,13 +85,16 @@
private int fJavaOffset;
private int fJavaLength;
+ private IJavaProject fJavaProject;
+
private final IToken[] fTokens= new IToken[] {
new Token(null),
new Token(JAVA_SINGLE_LINE_COMMENT),
new Token(JAVA_MULTI_LINE_COMMENT),
new Token(JAVA_DOC),
new Token(JAVA_CHARACTER),
- new Token(JAVA_STRING)
+ new Token(JAVA_STRING),
+ new Token(JAVA_MULTI_LINE_STRING)
};
public FastJavaPartitionScanner(boolean emulate) {
@@ -83,6 +105,11 @@
this(false);
}
+ public FastJavaPartitionScanner(IJavaProject javaProject) {
+ this(false);
+ fJavaProject= javaProject;
+ }
+
/*
* @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
*/
@@ -276,14 +303,27 @@
}
case '"':
- fLast= NONE; // ignore fLast
- if (fTokenLength > 0)
- return preFix(JAVA, STRING, NONE, 1);
+ boolean isTextBlockBeginning= scanForTextBlockBeginning();
+ if (isTextBlockBeginning) {
+ if (fTokenLength - getLastLength(fLast) > 0)
+ return preFix(JAVA, MULTI_LINE_STRING, TRIPLE_QUOTE, 3);
+ else {
+ preFix(JAVA, MULTI_LINE_STRING, TRIPLE_QUOTE, 3);
+ fTokenOffset+= fTokenLength;
+ fTokenLength= fPrefixLength;
+ break;
+ }
+ }
else {
- preFix(JAVA, STRING, NONE, 1);
- fTokenOffset += fTokenLength;
- fTokenLength= fPrefixLength;
- break;
+ fLast= NONE; // ignore fLast
+ if (fTokenLength > 0)
+ return preFix(JAVA, STRING, NONE, 1);
+ else {
+ preFix(JAVA, STRING, NONE, 1);
+ fTokenOffset += fTokenLength;
+ fTokenLength= fPrefixLength;
+ break;
+ }
}
default:
@@ -355,6 +395,9 @@
case '\\':
fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
fTokenLength++;
+ if (scanForUnicodeSlash()) {
+ fTokenLength= fTokenLength + 5;
+ }
break;
case '\"':
@@ -377,6 +420,9 @@
case '\\':
fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
fTokenLength++;
+ if (scanForUnicodeSlash()) {
+ fTokenLength= fTokenLength + 5;
+ }
break;
case '\'':
@@ -393,10 +439,164 @@
break;
}
break;
+
+ case MULTI_LINE_STRING:
+ switch (ch) {
+ case '\\':
+ fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
+ fTokenLength++;
+ if (scanForUnicodeSlash()) {
+ fTokenLength= fTokenLength + 5;
+ }
+ break;
+ case '\"':
+ if (fLast == BACKSLASH) {
+ consume();
+ break;
+ } else if (scanForTextBlockClose()) {
+ fTokenLength= fTokenLength + 2;
+ return postFix(MULTI_LINE_STRING);
+ } else {
+ consume();
+ break;
+ }
+ default:
+ consume();
+ break;
+ }
+ break;
}
}
}
+ private boolean scanForUnicodeSlash() {
+ int count= 0;
+ boolean isUnicodeSlash= false;
+ try {
+ int ch= fScanner.read();
+ count++;
+ if (ch == 'u') {
+ ch= fScanner.read();
+ count++;
+ if (ch == '0') {
+ ch= fScanner.read();
+ count++;
+ if (ch == '0') {
+ ch= fScanner.read();
+ count++;
+ if (ch == '5') {
+ ch= fScanner.read();
+ count++;
+ if (ch == 'C') {
+ isUnicodeSlash= true;
+ }
+ }
+ }
+ }
+ }
+ if (ch == ICharacterScanner.EOF) {
+ count--;
+ }
+ } catch (IndexOutOfBoundsException e) {
+ //let it return false;
+ } finally {
+ if (!isUnicodeSlash) {
+ for (int i= count; i > 0; i--) {
+ fScanner.unread();
+ }
+ }
+ }
+ return isUnicodeSlash;
+ }
+
+ private boolean scanForTextBlockBeginning() {
+ if (!isEnablePreviewsAllowed()) {
+ return false;
+ }
+ int count= 0;
+ boolean isTextBlockBeginning= false;
+ try {
+ // Don't change the position and current character unless we are certain
+ // to be dealing with a text block. For producing all errors like before
+ // in case of a valid """ but missing \r or \n, just return false and not
+ // throw any error.
+ count++;
+ int ch= fScanner.read();
+ if (ch == '\"') {
+ count++;
+ ch= fScanner.read();
+ if (ch == '\"') {
+ count++;
+ ch= fScanner.read();
+ while (Character.isWhitespace(ch)) {
+ switch (ch) {
+ case 10: /* \ u000a: LINE FEED */
+ case 13: /* \ u000d: CARRIAGE RETURN */
+ isTextBlockBeginning= true;
+ break;
+ case ICharacterScanner.EOF:
+ count--;
+ break;
+ default:
+ count++;
+ ch= fScanner.read();
+ break;
+ }
+ if (isTextBlockBeginning) {
+ break;
+ }
+ }
+ } else if (ch == ICharacterScanner.EOF) {
+ count--;
+ }
+ } else if (ch == ICharacterScanner.EOF) {
+ count--;
+ }
+ } catch (IndexOutOfBoundsException e) {
+ //let it return false;
+ } finally {
+ int ignore= 0;
+ if (isTextBlockBeginning) {
+ ignore= 2;
+ }
+ for (int i= count - ignore; i > 0; i--) {
+ fScanner.unread();
+ }
+ }
+ return isTextBlockBeginning;
+ }
+
+ private boolean scanForTextBlockClose() {
+ int count= 0;
+ boolean isTextBlockEnd= false;
+ try {
+ count++;
+ int ch= fScanner.read();
+ if (ch == '\"') {
+ count++;
+ ch= fScanner.read();
+ if (ch == '\"') {
+ isTextBlockEnd= true;
+ } else if (ch == ICharacterScanner.EOF) {
+ count--;
+ }
+
+ } else if (ch == ICharacterScanner.EOF) {
+ count--;
+ }
+ } catch (IndexOutOfBoundsException e) {
+ //let it return false;
+ } finally {
+ if (!isTextBlockEnd) {
+ for (int i= count; i > 0; i--) {
+ fScanner.unread();
+ }
+ }
+
+ }
+ return isTextBlockEnd;
+ }
+
private static final int getLastLength(int last) {
switch (last) {
default:
@@ -416,6 +616,8 @@
case SLASH_STAR_STAR:
return 3;
+ case TRIPLE_QUOTE:
+ return 3;
}
}
@@ -474,6 +676,9 @@
else if (contentType.equals(JAVA_CHARACTER))
return CHARACTER;
+ else if (contentType.equals(JAVA_MULTI_LINE_STRING))
+ return MULTI_LINE_STRING;
+
else
return JAVA;
}
@@ -540,4 +745,36 @@
return fTokenOffset;
}
+ private void setJavaProject() {
+ if (fJavaProject == null) {
+ IWorkbenchPage page= JavaPlugin.getActivePage();
+ if (page != null) {
+ IEditorPart part= page.getActiveEditor();
+ if (part != null) {
+ IEditorInput editorInput= part.getEditorInput();
+ if (editorInput != null) {
+ fJavaProject= EditorUtility.getJavaProject(editorInput);
+ }
+ }
+ if (fJavaProject == null) {
+ ISelection selection= page.getSelection();
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Object obj= ((IStructuredSelection) selection).getFirstElement();
+ if (obj instanceof IJavaElement) {
+ fJavaProject= ((IJavaElement) obj).getJavaProject();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isEnablePreviewsAllowed() {
+ boolean isAllowed= false;
+ setJavaProject();
+ if (fJavaProject != null) {
+ isAllowed= PreviewFeaturesSubProcessor.isPreviewFeatureEnabled(fJavaProject);
+ }
+ return isAllowed;
+ }
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitioner.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitioner.java
new file mode 100644
index 0000000..63db1a1
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/FastJavaPartitioner.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.text;
+
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+
+public class FastJavaPartitioner extends FastPartitioner {
+
+
+ private boolean fIsPreviewEnabled= false;
+
+ public FastJavaPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
+ super(scanner, legalContentTypes);
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ fIsPreviewEnabled= isEnablePreviewsAllowed();
+ }
+
+ @Override
+ public void documentAboutToBeChanged(DocumentEvent e) {
+ super.documentAboutToBeChanged(e);
+ if (hasPreviewEnabledValueChanged()) {
+ clearManagingPositionCategory();
+ connect(fDocument, false);
+ }
+ }
+
+ @Override
+ public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
+ if (hasPreviewEnabledValueChanged()) {
+ clearManagingPositionCategory();
+ connect(fDocument, false);
+ }
+ return super.computePartitioning(offset, length, includeZeroLengthPartitions);
+ }
+
+ public void cleanAndReConnectDocumentIfNecessary() {
+ if (hasPreviewEnabledValueChanged()) {
+ clearManagingPositionCategory();
+ connect(fDocument, false);
+ }
+ }
+
+ public boolean hasPreviewEnabledValueChanged() {
+ boolean previewEnabledFlagChanged= false;
+ boolean enablePreviewsAllowed= isEnablePreviewsAllowed();
+ if (enablePreviewsAllowed != fIsPreviewEnabled) {
+ previewEnabledFlagChanged= true;
+ }
+ return previewEnabledFlagChanged;
+ }
+
+ private boolean isEnablePreviewsAllowed() {
+ boolean isEnablePreviewsAllowed= false;
+ if (fScanner instanceof FastJavaPartitionScanner) {
+ isEnablePreviewsAllowed= ((FastJavaPartitionScanner) fScanner).isEnablePreviewsAllowed();
+ } else {
+ isEnablePreviewsAllowed= false;
+ }
+ return isEnablePreviewsAllowed;
+ }
+
+ private void clearManagingPositionCategory() {
+ String[] categories= getManagingPositionCategories();
+ for (String category : categories) {
+ try {
+ fDocument.removePositionCategory(category);
+ } catch (BadPositionCategoryException e) {
+ // do nothing
+ }
+ }
+ clearPositionCache();
+ }
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPartitionerManager.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPartitionerManager.java
new file mode 100644
index 0000000..b96ecec
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPartitionerManager.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.text;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+
+import org.eclipse.ui.texteditor.ITextEditor;
+
+import org.eclipse.jdt.ui.text.IJavaPartitionerManager;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+
+public class JavaPartitionerManager implements IJavaPartitionerManager {
+
+ private final static String[] LEGAL_CONTENT_TYPES= new String[] {
+ IJavaPartitions.JAVA_DOC,
+ IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
+ IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
+ IJavaPartitions.JAVA_STRING,
+ IJavaPartitions.JAVA_CHARACTER,
+ IJavaPartitions.JAVA_MULTI_LINE_STRING
+ };
+
+ private static ITextEditor fEditor;
+
+ private Map<ITextEditor, IDocumentPartitioner> fEditorPartitionerMap;
+
+ private Set<FastJavaPartitioner> fPartitionerSet;
+
+ public JavaPartitionerManager() {
+ fEditorPartitionerMap= new HashMap<>();
+ fPartitionerSet= new HashSet<>();
+ }
+
+ @Override
+ public IPartitionTokenScanner getPartitionScanner() {
+ return new FastJavaPartitionScanner(EditorUtility.getJavaProject(fEditor));
+ }
+
+ /**
+ * Factory method for creating a Java-specific document partitioner using this object's
+ * partitions scanner. This method is a convenience method.
+ *
+ * @return a newly created Java document partitioner
+ */
+ @Override
+ public IDocumentPartitioner createDocumentPartitioner() {
+ FastJavaPartitioner partitioner= new FastJavaPartitioner(getPartitionScanner(), LEGAL_CONTENT_TYPES);
+ fPartitionerSet.add(partitioner);
+ return partitioner;
+ }
+
+ public void clearEditorInfo(ITextEditor editor) {
+ if (editor != null) {
+ IDocumentPartitioner partitioner= fEditorPartitionerMap.get(editor);
+ fEditorPartitionerMap.remove(editor);
+ if (editor == fEditor) {
+ fEditor= null;
+ }
+ fPartitionerSet.remove(partitioner);
+ }
+ }
+
+ public void dispose() {
+ fEditor= null;
+ if (fEditorPartitionerMap != null) {
+ fEditorPartitionerMap.clear();
+ fEditorPartitionerMap= null;
+ }
+ if (fPartitionerSet != null) {
+ fPartitionerSet.clear();
+ fPartitionerSet= null;
+ }
+ }
+
+ public void setEditorInfo(ITextEditor editor) {
+ fEditor= editor;
+ }
+
+ @SuppressWarnings("unused")
+ public boolean affectsBehavior(PropertyChangeEvent event) {
+ boolean affectsBehavior= false;
+ if (fPartitionerSet != null) {
+ for (FastJavaPartitioner partitioner : fPartitionerSet) {
+ if (partitioner.hasPreviewEnabledValueChanged()) {
+ affectsBehavior= true;
+ break;
+ }
+ }
+ }
+ return affectsBehavior;
+ }
+
+ @SuppressWarnings("unused")
+ public void adaptToPreferenceChange(PropertyChangeEvent event) {
+ if (fPartitionerSet != null) {
+ for (FastJavaPartitioner partitioner : fPartitionerSet) {
+ if (partitioner.hasPreviewEnabledValueChanged()) {
+ partitioner.cleanAndReConnectDocumentIfNecessary();
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java
index 7283c0e..da8966e 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* Konstantin Scheglov (scheglov_ke@nlmk.ru) - initial API and implementation
* (reports 71244 & 74746: New Quick Assist's [quick assist])
@@ -2454,7 +2458,7 @@
Statement statement= iter.next();
if (statement instanceof SwitchCase) {
SwitchCase switchCase= (SwitchCase) statement;
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled() && switchCase.expressions().size() > 1) {
+ if (ast.isPreviewEnabled() && switchCase.expressions().size() > 1) {
return false;
}
// special case: pass through
@@ -2556,7 +2560,7 @@
private static Expression createSwitchCaseCondition(AST ast, ASTRewrite rewrite, ImportRewrite importRewrite, ImportRewriteContext importRewriteContext, Name switchExpression,
SwitchCase switchCase, boolean isStringsInSwitch, boolean preserveNPE) {
Expression expression= null;
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
if (switchCase.expressions().size() == 1) {
expression= (Expression) switchCase.expressions().get(0);
}
@@ -2903,7 +2907,7 @@
ASTNode astNode= caseExpressions.get(i);
switchCaseStatements[i]= ast.newSwitchCase();
Expression copyTarget= (Expression) rewrite.createCopyTarget(astNode);
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
switchCaseStatements[i].expressions().add(copyTarget);
} else {
switchCaseStatements[i].setExpression(copyTarget);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
index a39ef15..24d05bd 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Renaud Waldura <renaud+eclipse@waldura.com> - Access to static proposal
@@ -1792,8 +1796,7 @@
Statement curr= statements.get(i);
if (curr instanceof SwitchCase) {
SwitchCase switchCase= (SwitchCase) curr;
- AST ast= switchCase.getAST();
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (switchCase.getAST().isPreviewEnabled()) {
List<Expression> expressions= switchCase.expressions();
if (expressions.size() == 0) {
hasDefault= true;
@@ -1836,8 +1839,7 @@
Statement curr= statements.get(i);
if (curr instanceof SwitchCase) {
SwitchCase switchCase= (SwitchCase) curr;
- AST ast= switchCase.getAST();
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (switchCase.getAST().isPreviewEnabled()) {
if (switchCase.expressions().size() == 0) {
defaultIndex= i;
break;
@@ -1869,7 +1871,7 @@
SwitchCase newSwitchCase= ast.newSwitchCase();
String enumConstName= enumConstNames.get(i);
Name newName= ast.newName(enumConstName);
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
newSwitchCase.expressions().add(newName);
} else {
newSwitchCase.setExpression(newName);
@@ -1877,7 +1879,7 @@
listRewrite.insertAt(newSwitchCase, defaultIndex, null);
defaultIndex++;
if (!hasDefault) {
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
if (statements.size() > 0) {
Statement firstStatement= statements.get(0);
SwitchCase switchCase= (SwitchCase) firstStatement;
@@ -1905,7 +1907,7 @@
listRewrite.insertAt(newSwitchCase, defaultIndex, null);
defaultIndex++;
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
if (statements.size() > 0) {
Statement firstStatement= statements.get(0);
SwitchCase switchCase= (SwitchCase) firstStatement;
@@ -2001,7 +2003,7 @@
SwitchCase newSwitchCase= ast.newSwitchCase();
listRewrite.insertLast(newSwitchCase, null);
- if (ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled()) {
+ if (ast.isPreviewEnabled()) {
if (statements.size() > 0) {
Statement firstStatement= statements.get(0);
SwitchCase switchCase= (SwitchCase) firstStatement;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
index 76520c4..f27c0de 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -41,6 +45,7 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.Messages;
import org.eclipse.jdt.ui.JavaElementLabels;
@@ -62,6 +67,7 @@
public class PreviewFeaturesSubProcessor {
private static final String CONFIGURE_COMPILER_PROBLEM_SEVERITY_DIALOG_ID= "configure_compiler_settings_dialog_id"; //$NON-NLS-1$
+ private static final String ENABLED= "enabled"; //$NON-NLS-1$
private static class EnablePreviewFeatureProposal extends ChangeCorrectionProposal implements IWorkspaceRunnable {
@@ -127,14 +133,8 @@
public static void getOpenCompliancePageToEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) {
- IProject project= null;
IJavaProject javaProject= context.getCompilationUnit().getJavaProject();
- if (javaProject != null) {
- project= javaProject.getProject();
- }
-
- Key[] keys= ComplianceConfigurationBlock.getKeys(javaProject != null);
- boolean hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+ boolean hasProjectSpecificOptions= hasProjectSpecificOptions(javaProject);
String label= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features;
if (hasProjectSpecificOptions) {
@@ -210,9 +210,7 @@
public static void getEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) {
IJavaProject javaProject= context.getCompilationUnit().getJavaProject();
if (javaProject != null) {
- IProject project= javaProject.getProject();
- Key[] keys= ComplianceConfigurationBlock.getKeys(true);
- boolean changeOnWorkspace = !OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+ boolean changeOnWorkspace= !hasProjectSpecificOptions(javaProject);
String label= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features;
if (changeOnWorkspace) {
label= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_workspace;
@@ -225,11 +223,42 @@
public static void getNeedHigherComplianceProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
String[] args= problem.getProblemArguments();
if (args != null && args.length > 0) {
+ String supportedVersion= JavaCore.VERSION_13;
String arg= args[1];
- if (arg == "12") { //$NON-NLS-1$
- String version= JavaCore.VERSION_12;
- ReorgCorrectionsSubProcessor.getNeedHigherComplianceProposals(context, problem, proposals, version);
+ if (arg.equals(supportedVersion)) {
+ ReorgCorrectionsSubProcessor.getNeedHigherComplianceProposals(context, problem, proposals, true, supportedVersion);
}
}
}
+
+ public static boolean hasProjectSpecificOptions(IJavaProject javaProject) {
+ boolean hasProjectSpecificOptions= false;
+ if (javaProject != null) {
+ IProject project= javaProject.getProject();
+ Key[] keys= ComplianceConfigurationBlock.getKeys(true);
+ hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+ }
+ return hasProjectSpecificOptions;
+ }
+
+ public static boolean isPreviewFeatureEnabled(IJavaProject javaProject) {
+ boolean isPreviewFeatureEnabled= false;
+ if (javaProject != null && JavaModelUtil.is13OrHigher(javaProject)) {
+ IProject project= javaProject.getProject();
+ Key[] keys= ComplianceConfigurationBlock.getKeys(true);
+ boolean hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+ if (hasProjectSpecificOptions) {
+ String option= javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ if (option != null && option.equals(ENABLED)) {
+ isPreviewFeatureEnabled= true;
+ }
+ } else {
+ String option= JavaCore.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES);
+ if (option != null && option.equals(ENABLED)) {
+ isPreviewFeatureEnabled= true;
+ }
+ }
+ }
+ return isPreviewFeatureEnabled;
+ }
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
index 826c7d6..b0b1b15 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Sebastian Davids <sdavids@gmx.de> - Bug 37432 getInvertEqualsProposal
@@ -4263,11 +4267,9 @@
private boolean getSplitSwitchLabelProposal(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> proposals) {
AST ast= coveringNode.getAST();
- // Only continue if level is JLS12 with preview enabled and selected node, or its parent is a SwitchCase
- if (!(ast.apiLevel() >= AST.JLS12 && ast.isPreviewEnabled())) {
- return false;
- }
- if (!(coveringNode instanceof SwitchCase || coveringNode.getParent() instanceof SwitchCase)) {
+ // Only continue if AST has preview enabled and selected node, or its parent is a SwitchCase
+ if (!ast.isPreviewEnabled() ||
+ !(coveringNode instanceof SwitchCase || coveringNode.getParent() instanceof SwitchCase)) {
return false;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
index 18ca912..688ff00 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
@@ -302,8 +306,9 @@
case IProblem.ServiceImplDefaultConstructorNotPublic:
case IProblem.PreviewFeatureDisabled:
case IProblem.PreviewFeatureNotSupported:
- case IProblem.SwitchExpressionMissingEnumConstantCase:
- case IProblem.SwitchExpressionMissingDefaultCase:
+ case IProblem.SwitchExpressionsYieldMissingEnumConstantCase:
+ case IProblem.SwitchExpressionsYieldMissingDefaultCase:
+ case IProblem.PreviewFeaturesNotAllowed:
case IProblem.UninitializedBlankFinalField:
return true;
default:
@@ -732,11 +737,11 @@
break;
case IProblem.MissingEnumConstantCase:
case IProblem.MissingEnumDefaultCase:
- case IProblem.SwitchExpressionMissingEnumConstantCase:
+ case IProblem.SwitchExpressionsYieldMissingEnumConstantCase:
LocalCorrectionsSubProcessor.getMissingEnumConstantCaseProposals(context, problem, proposals);
break;
case IProblem.MissingDefaultCase:
- case IProblem.SwitchExpressionMissingDefaultCase:
+ case IProblem.SwitchExpressionsYieldMissingDefaultCase:
LocalCorrectionsSubProcessor.addMissingDefaultCaseProposal(context, problem, proposals);
break;
case IProblem.MissingEnumConstantCaseDespiteDefault:
@@ -857,6 +862,7 @@
PreviewFeaturesSubProcessor.getOpenCompliancePageToEnablePreviewFeaturesProposal(context, proposals);
break;
case IProblem.PreviewFeatureNotSupported:
+ case IProblem.PreviewFeaturesNotAllowed:
PreviewFeaturesSubProcessor.getNeedHigherComplianceProposals(context, problem, proposals);
break;
default:
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReorgCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReorgCorrectionsSubProcessor.java
index e1031aa..54f12d3 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReorgCorrectionsSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReorgCorrectionsSubProcessor.java
@@ -7,6 +7,10 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -379,17 +383,23 @@
private final IJavaProject fProject;
private final boolean fChangeOnWorkspace;
private final String fRequiredVersion;
+ private final boolean fEnablePreviews;
private Job fUpdateJob;
private boolean fRequiredJREFound;
public ChangeToRequiredCompilerCompliance(String name, IJavaProject project, boolean changeOnWorkspace, String requiredVersion, int relevance) {
+ this(name, project, changeOnWorkspace, requiredVersion, false, relevance);
+ }
+
+ public ChangeToRequiredCompilerCompliance(String name, IJavaProject project, boolean changeOnWorkspace, String requiredVersion, boolean enablePreviews, int relevance) {
super(name, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE));
fProject= project;
fChangeOnWorkspace= changeOnWorkspace;
fRequiredVersion= requiredVersion;
fUpdateJob= null;
fRequiredJREFound= false;
+ fEnablePreviews= enablePreviews;
}
private boolean isRequiredOrGreaterVMInstall(IVMInstall install) {
@@ -482,6 +492,13 @@
} catch (CoreException e) {
// ignore
}
+ if (fEnablePreviews) {
+ if (fChangeOnWorkspace) {
+ message.append(CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_workspace_info);
+ } else {
+ message.append(CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_info);
+ }
+ }
return message.toString();
}
@@ -500,6 +517,9 @@
if (fChangeOnWorkspace) {
Hashtable<String, String> map= JavaCore.getOptions();
JavaModelUtil.setComplianceOptions(map, fRequiredVersion);
+ if (fEnablePreviews) {
+ map.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ }
JavaCore.setOptions(map);
} else {
Map<String, String> map= fProject.getOptions(false);
@@ -509,6 +529,9 @@
// options have been added -> ensure that all compliance options from preference page set
JavaModelUtil.setDefaultClassfileOptions(map, fRequiredVersion);
}
+ if (fEnablePreviews) {
+ map.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ }
fProject.setOptions(map);
}
try {
@@ -540,14 +563,36 @@
* @param requiredVersion the minimal required Java compiler version
*/
public static void getNeedHigherComplianceProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals, String requiredVersion) {
- IJavaProject project= context.getCompilationUnit().getJavaProject();
+ getNeedHigherComplianceProposals(context, problem, proposals, false, requiredVersion);
+ }
+ /**
+ * Adds a proposal to increase the compiler compliance level as well as set --enable-previews
+ * option.
+ *
+ * @param context the context
+ * @param problem the current problem
+ * @param proposals the resulting proposals
+ * @param enablePreviews --enable-previews option will be enabled if set to true
+ * @param requiredVersion the minimal required Java compiler version
+ */
+ static void getNeedHigherComplianceProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals, boolean enablePreviews, String requiredVersion) {
+ IJavaProject project= context.getCompilationUnit().getJavaProject();
String label1= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_change_project_compliance_description, requiredVersion);
- proposals.add(new ChangeToRequiredCompilerCompliance(label1, project, false, requiredVersion, IProposalRelevance.CHANGE_PROJECT_COMPLIANCE));
+ if (enablePreviews) {
+ label1= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_combine_two_quickfixes, new String[] {label1, CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features});
+ proposals.add(new ChangeToRequiredCompilerCompliance(label1, project, false, requiredVersion, enablePreviews, IProposalRelevance.CHANGE_PROJECT_COMPLIANCE));
+ } else {
+ proposals.add(new ChangeToRequiredCompilerCompliance(label1, project, false, requiredVersion, IProposalRelevance.CHANGE_PROJECT_COMPLIANCE));
+ }
+
if (project.getOption(JavaCore.COMPILER_COMPLIANCE, false) == null) {
String label2= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_change_workspace_compliance_description, requiredVersion);
- proposals.add(new ChangeToRequiredCompilerCompliance(label2, project, true, requiredVersion, IProposalRelevance.CHANGE_WORKSPACE_COMPLIANCE));
+ if (enablePreviews) {
+ label2= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_combine_two_quickfixes, new String[] {label2, CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_workspace});
+ }
+ proposals.add(new ChangeToRequiredCompilerCompliance(label2, project, true, requiredVersion, enablePreviews, IProposalRelevance.CHANGE_WORKSPACE_COMPLIANCE));
}
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java
index 00c56ae..3ca3dc1 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Nikolay Metchev - Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=29909
@@ -66,6 +70,7 @@
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitioner;
import org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner;
import org.eclipse.jdt.internal.ui.text.JavaIndenter;
import org.eclipse.jdt.internal.ui.text.Symbols;
@@ -628,16 +633,17 @@
*
* @param document the document
*/
- private static void installJavaStuff(Document document) {
+ private void installJavaStuff(Document document) {
String[] types= new String[] {
IJavaPartitions.JAVA_DOC,
IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
IJavaPartitions.JAVA_STRING,
IJavaPartitions.JAVA_CHARACTER,
+ IJavaPartitions.JAVA_MULTI_LINE_STRING,
IDocument.DEFAULT_CONTENT_TYPE
};
- FastPartitioner partitioner= new FastPartitioner(new FastJavaPartitionScanner(), types);
+ FastPartitioner partitioner= new FastJavaPartitioner(new FastJavaPartitionScanner(fProject), types);
partitioner.connect(document);
document.setDocumentPartitioner(IJavaPartitions.JAVA_PARTITIONING, partitioner);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMultiLineStringAutoIndentStrategy.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMultiLineStringAutoIndentStrategy.java
new file mode 100644
index 0000000..5c59da3
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMultiLineStringAutoIndentStrategy.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.text.java;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextUtilities;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.formatter.IndentManipulation;
+
+import org.eclipse.jdt.internal.core.manipulation.util.Strings;
+import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
+
+import org.eclipse.jdt.ui.PreferenceConstants;
+
+import org.eclipse.jdt.internal.ui.actions.IndentAction;
+import org.eclipse.jdt.internal.ui.text.correction.PreviewFeaturesSubProcessor;
+
+public class JavaMultiLineStringAutoIndentStrategy extends JavaStringAutoIndentStrategy {
+
+ public JavaMultiLineStringAutoIndentStrategy(String partitioning, IJavaProject project) {
+ super(partitioning, project);
+ }
+
+ private void javaMultiLineStringIndentAfterNewLine(IDocument document, DocumentCommand command) throws BadLocationException {
+
+ ITypedRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, true);
+ int offset= partition.getOffset();
+ int length= partition.getLength();
+
+ if (command.offset == offset + length && document.getChar(offset + length - 1) == '\"')
+ return;
+
+ String indentation= getLineIndentation(document, command.offset);
+ String delimiter= TextUtilities.getDefaultLineDelimiter(document);
+
+ IRegion line= document.getLineInformationOfOffset(offset);
+ String fullStr= document.get(line.getOffset(), line.getLength()).trim();
+ String fullTextBlockText= document.get(offset, length).trim();
+ boolean hasTextBlockEnded= PreviewFeaturesSubProcessor.isPreviewFeatureEnabled(fProject) && fullTextBlockText.endsWith(IndentAction.TEXT_BLOCK_STR);
+ boolean isTextBlock= PreviewFeaturesSubProcessor.isPreviewFeatureEnabled(fProject) && fullStr.endsWith(IndentAction.TEXT_BLOCK_STR);
+ boolean isLineDelimiter= isLineDelimiter(document, command.text);
+ if (isEditorWrapStrings() && isLineDelimiter && isTextBlock) {
+ if (isTextBlock) {
+ indentation= getIndentation(document, command.offset);
+ if (hasTextBlockEnded) {
+ command.text= command.text + indentation;
+ } else {
+ command.text= command.text + indentation;
+ if (isCloseStringsPreferenceSet()) {
+ command.caretOffset= command.offset + command.text.length();
+ command.shiftsCaret= false;
+ command.text= command.text + System.lineSeparator() + getIndentation(document, offset) + IndentAction.TEXT_BLOCK_STR + ";"; //$NON-NLS-1$
+ }
+ }
+ } else {
+ command.text= command.text + indentation;
+ }
+ } else if (command.text.length() > 1 && !isLineDelimiter && isEditorEscapeStrings()) {
+ command.text= getModifiedText(command.text, indentation, delimiter, isEditorEscapeStringsNonAscii());
+ }
+ }
+
+ private String getIndentation(IDocument document, int offset) throws BadLocationException {
+ IRegion line= document.getLineInformationOfOffset(offset);
+ String fullStrNoTrim= document.get(line.getOffset(), line.getLength());
+ String indentation= getLineIndentation(document, offset);
+ int startIndex= fullStrNoTrim.lastIndexOf(IndentAction.TEXT_BLOCK_STR);
+ if (fullStrNoTrim.endsWith(IndentAction.TEXT_BLOCK_STR) && startIndex != -1) {
+ int length= IndentAction.measureLengthInSpaces(fullStrNoTrim.substring(0, startIndex), CodeFormatterUtil.getTabWidth(fProject));
+ String str= IndentAction.EMPTY_STR;
+ for (int i= 0; i < length; i++) {
+ str+= IndentAction.SPACE_STR;
+ }
+ int units= Strings.computeIndentUnits(str, fProject);
+ String newStr= CodeFormatterUtil.createIndentString(units, fProject);
+ int newLength= IndentManipulation.measureIndentInSpaces(newStr, CodeFormatterUtil.getTabWidth(fProject));
+ if (newLength < length) {
+ for (int i= newLength; i < length; i++) {
+ newStr+= IndentAction.SPACE_STR;
+ }
+ }
+ indentation= newStr;
+ }
+ return indentation;
+ }
+
+ /**
+ * The input string will contain line delimiter.
+ *
+ * @param inputString the given input string
+ * @param indentation the indentation
+ * @param delimiter the line delimiter
+ * @return the display string
+ */
+ @Override
+ protected String displayString(String inputString, String indentation, String delimiter, boolean escapeNonAscii) {
+
+ int length= inputString.length();
+ StringBuilder buffer= new StringBuilder(length);
+ StringTokenizer tokenizer= new StringTokenizer(inputString, "\n\r", true); //$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String token= tokenizer.nextToken();
+ if (token.equals("\r")) { //$NON-NLS-1$
+ buffer.append('\r');
+ if (tokenizer.hasMoreTokens()) {
+ token= tokenizer.nextToken();
+ if (token.equals("\n")) { //$NON-NLS-1$
+ buffer.append('\n');
+ continue;
+ }
+ } else {
+ continue;
+ }
+ } else if (token.equals("\n")) { //$NON-NLS-1$
+ buffer.append('\n');
+ continue;
+ }
+
+ StringBuilder tokenBuffer= new StringBuilder();
+ for (int i= 0; i < token.length(); i++) {
+ char c= token.charAt(i);
+ switch (c) {
+ default:
+ if (escapeNonAscii && (c < 0x20 || c >= 0x80)) {
+ String hex= "0123456789ABCDEF"; //$NON-NLS-1$
+ tokenBuffer.append('\\');
+ tokenBuffer.append('u');
+ tokenBuffer.append(hex.charAt((c >> 12) & 0xF));
+ tokenBuffer.append(hex.charAt((c >> 8) & 0xF));
+ tokenBuffer.append(hex.charAt((c >> 4) & 0xF));
+ tokenBuffer.append(hex.charAt(c & 0xF));
+ } else {
+ tokenBuffer.append(c);
+ }
+ }
+ }
+ buffer.append(tokenBuffer);
+ }
+ return buffer.toString();
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IAutoIndentStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
+ */
+ @Override
+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+ try {
+ if (command.text == null)
+ return;
+ if (isSmartMode()) {
+ javaMultiLineStringIndentAfterNewLine(document, command);
+ }
+ } catch (BadLocationException e) {
+ }
+ }
+
+ private boolean isCloseStringsPreferenceSet() {
+ boolean isSet= false;
+ if (fProject != null) {
+ IPreferenceStore store= PreferenceConstants.getPreferenceStore();
+ if (store != null) {
+ isSet= store.getBoolean(PreferenceConstants.EDITOR_CLOSE_STRINGS);
+ }
+ }
+ return isSet;
+ }
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaStringAutoIndentStrategy.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaStringAutoIndentStrategy.java
index 9753729..6b5d8f6 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaStringAutoIndentStrategy.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaStringAutoIndentStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -49,8 +49,8 @@
*/
public class JavaStringAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
- private String fPartitioning;
- private IJavaProject fProject;
+ protected String fPartitioning;
+ protected IJavaProject fProject;
/**
* The input string doesn't contain any line delimiter.
@@ -60,7 +60,7 @@
* @param delimiter the line delimiter
* @return the display string
*/
- private String displayString(String inputString, String indentation, String delimiter, boolean escapeNonAscii) {
+ protected String displayString(String inputString, String indentation, String delimiter, boolean escapeNonAscii) {
int length = inputString.length();
StringBuilder buffer = new StringBuilder(length);
@@ -151,14 +151,14 @@
fProject= project;
}
- private boolean isLineDelimiter(IDocument document, String text) {
+ protected boolean isLineDelimiter(IDocument document, String text) {
String[] delimiters= document.getLegalLineDelimiters();
if (delimiters != null)
return TextUtilities.equals(delimiters, text) > -1;
return false;
}
- private String getLineIndentation(IDocument document, int offset) throws BadLocationException {
+ protected String getLineIndentation(IDocument document, int offset) throws BadLocationException {
// find start of line
int adjustedOffset= (offset == document.getLength() ? offset - 1 : offset);
@@ -171,7 +171,7 @@
return document.get(start, end - start);
}
- private String getModifiedText(String string, String indentation, String delimiter, boolean escapeNonAscii) {
+ protected String getModifiedText(String string, String indentation, String delimiter, boolean escapeNonAscii) {
return displayString(string, indentation, delimiter, escapeNonAscii);
}
@@ -204,17 +204,17 @@
}
}
- private boolean isEditorWrapStrings() {
+ protected boolean isEditorWrapStrings() {
IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
return preferenceStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS);
}
- private boolean isEditorEscapeStrings() {
+ protected boolean isEditorEscapeStrings() {
IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
return preferenceStore.getBoolean(PreferenceConstants.EDITOR_ESCAPE_STRINGS);
}
- private boolean isEditorEscapeStringsNonAscii() {
+ protected boolean isEditorEscapeStringsNonAscii() {
IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
return preferenceStore.getBoolean(PreferenceConstants.EDITOR_ESCAPE_STRINGS_NON_ASCII);
}
@@ -254,7 +254,7 @@
*
* @return two tabs or equivalent number of spaces
*/
- private String getExtraIndentAfterNewLine() {
+ protected String getExtraIndentAfterNewLine() {
// read settings
int formatterContinuationIndentationSize= getContinuationIndentationSize();
int binaryAlignmentValue= getBinaryOperatorAlignmentStyle();
@@ -271,7 +271,7 @@
return CodeFormatterUtil.createIndentString(indentSize, fProject);
}
- private boolean isSmartMode() {
+ protected boolean isSmartMode() {
IWorkbenchPage page= JavaPlugin.getActivePage();
if (page != null) {
IEditorPart part= page.getActiveEditor();
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/SharedASTProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/SharedASTProvider.java
index 284876c..bdf3e11 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/SharedASTProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/SharedASTProvider.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -33,7 +37,7 @@
* <p>Clients can make the following assumptions about the AST:</p>
* <ul>
* <li>the AST has a {@link ITypeRoot} as source: {@link CompilationUnit#getTypeRoot()} is not null.</li>
- * <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS12 API level 12} or higher</li>
+ * <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS13 API level 13} or higher</li>
* <li>the AST has bindings resolved ({@link AST#hasResolvedBindings()})</li>
* <li>{@link AST#hasStatementsRecovery() statement} and {@link AST#hasBindingsRecovery() bindings}
* recovery are enabled
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitionerManager.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitionerManager.java
new file mode 100644
index 0000000..c71da03
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitionerManager.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.ui.text;
+
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+
+/**
+ * This IDocumentPartitioner Manager manages the creation of the IDocumentPartitioner
+ * and the corresponding IPartitionTokenScanner.
+ *
+ * @since 3.19
+ */
+public interface IJavaPartitionerManager {
+
+ /**
+ * Returns a scanner which is configured to scan
+ * Java-specific partitions, which are multi-line comments,
+ * Javadoc comments, and regular Java source code.
+ *
+ * @return a Java partition scanner
+ */
+ public IPartitionTokenScanner getPartitionScanner();
+
+ /**
+ * Factory method for creating a Java-specific document partitioner
+ * using the partitions scanner. This method is a
+ * convenience method.
+ *
+ * @return a newly created Java document partitioner
+ */
+ public IDocumentPartitioner createDocumentPartitioner();
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitions.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitions.java
index bc991fc..30f2e38 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitions.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/IJavaPartitions.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -49,4 +53,10 @@
* The identifier of the Java character partition content type.
*/
String JAVA_CHARACTER= "__java_character"; //$NON-NLS-1$
+
+ /**
+ * The identifier multi-line (JEP 355: Text Block) String partition content type.
+ * @since 3.19
+ */
+ String JAVA_MULTI_LINE_STRING= "__java_multiline_string"; //$NON-NLS-1$
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java
index 226d0c5..6c803cc 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -55,17 +55,13 @@
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.IEditorInput;
-
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
-import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
-import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
@@ -77,8 +73,7 @@
import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
-import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
-import org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.text.AbstractJavaScanner;
import org.eclipse.jdt.internal.ui.text.ContentAssistPreference;
import org.eclipse.jdt.internal.ui.text.HTMLAnnotationHover;
@@ -97,6 +92,7 @@
import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor;
import org.eclipse.jdt.internal.ui.text.java.JavaDoubleClickSelector;
import org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy;
+import org.eclipse.jdt.internal.ui.text.java.JavaMultiLineStringAutoIndentStrategy;
import org.eclipse.jdt.internal.ui.text.java.JavaStringAutoIndentStrategy;
import org.eclipse.jdt.internal.ui.text.java.JavadocDoubleClickStrategy;
import org.eclipse.jdt.internal.ui.text.java.PartitionDoubleClickSelector;
@@ -424,6 +420,9 @@
reconciler.setDamager(dr, IJavaPartitions.JAVA_CHARACTER);
reconciler.setRepairer(dr, IJavaPartitions.JAVA_CHARACTER);
+ dr= new DefaultDamagerRepairer(getStringScanner());
+ reconciler.setDamager(dr, IJavaPartitions.JAVA_MULTI_LINE_STRING);
+ reconciler.setRepairer(dr, IJavaPartitions.JAVA_MULTI_LINE_STRING);
return reconciler;
}
@@ -456,6 +455,9 @@
ContentAssistProcessor javadocProcessor= new JavadocCompletionProcessor(getEditor(), assistant);
assistant.setContentAssistProcessor(javadocProcessor, IJavaPartitions.JAVA_DOC);
+ ContentAssistProcessor multiLineStringProcessor= new JavaCompletionProcessor(getEditor(), assistant, IJavaPartitions.JAVA_MULTI_LINE_STRING);
+ assistant.setContentAssistProcessor(multiLineStringProcessor, IJavaPartitions.JAVA_MULTI_LINE_STRING);
+
ContentAssistPreference.configure(assistant, fPreferenceStore);
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
@@ -514,11 +516,13 @@
if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType))
return new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning) };
else if (IJavaPartitions.JAVA_STRING.equals(contentType))
- return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning, getProject()) };
+ return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning, EditorUtility.getJavaProject(fTextEditor)) };
else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
- return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) };
+ return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, EditorUtility.getJavaProject(fTextEditor), sourceViewer) };
+ else if (IJavaPartitions.JAVA_MULTI_LINE_STRING.equals(contentType))
+ return new IAutoEditStrategy[] { new JavaMultiLineStringAutoIndentStrategy(partitioning, EditorUtility.getJavaProject(fTextEditor)) };
else
- return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) };
+ return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, EditorUtility.getJavaProject(fTextEditor), sourceViewer) };
}
/*
@@ -534,6 +538,8 @@
return new PartitionDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), 0, 0);
else if (IJavaPartitions.JAVA_STRING.equals(contentType) || IJavaPartitions.JAVA_CHARACTER.equals(contentType))
return new PartitionDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), 1, 1);
+ else if (IJavaPartitions.JAVA_MULTI_LINE_STRING.equals(contentType))
+ return new PartitionDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), 3, 3, 3);
if (fJavaDoubleClickSelector == null) {
fJavaDoubleClickSelector= new JavaDoubleClickSelector();
fJavaDoubleClickSelector.setSourceVersion(fPreferenceStore.getString(JavaCore.COMPILER_SOURCE));
@@ -555,7 +561,7 @@
*/
@Override
public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
- IJavaProject project= getProject();
+ IJavaProject project= EditorUtility.getJavaProject(fTextEditor);
final int tabWidth= CodeFormatterUtil.getTabWidth(project);
final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
boolean allowTabs= tabWidth <= indentWidth;
@@ -619,34 +625,12 @@
return new String(spaceChars);
}
- private IJavaProject getProject() {
- ITextEditor editor= getEditor();
- if (editor == null)
- return null;
-
- IJavaElement element= null;
- IEditorInput input= editor.getEditorInput();
- IDocumentProvider provider= editor.getDocumentProvider();
- if (provider instanceof ICompilationUnitDocumentProvider) {
- ICompilationUnitDocumentProvider cudp= (ICompilationUnitDocumentProvider) provider;
- element= cudp.getWorkingCopy(input);
- } else if (input instanceof IClassFileEditorInput) {
- IClassFileEditorInput cfei= (IClassFileEditorInput) input;
- element= cfei.getClassFile();
- }
-
- if (element == null)
- return null;
-
- return element.getJavaProject();
- }
-
/*
* @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
*/
@Override
public int getTabWidth(ISourceViewer sourceViewer) {
- return CodeFormatterUtil.getTabWidth(getProject());
+ return CodeFormatterUtil.getTabWidth(EditorUtility.getJavaProject(fTextEditor));
}
/*
@@ -742,7 +726,8 @@
IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
IJavaPartitions.JAVA_STRING,
- IJavaPartitions.JAVA_CHARACTER
+ IJavaPartitions.JAVA_CHARACTER,
+ IJavaPartitions.JAVA_MULTI_LINE_STRING
};
}
@@ -875,6 +860,7 @@
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
+ presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_STRING);
presenter.setSizeConstraints(50, 20, true, false);
return presenter;
}
@@ -919,6 +905,7 @@
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
+ presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_STRING);
presenter.setSizeConstraints(50, 20, true, false);
return presenter;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaTextTools.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaTextTools.java
index aba1aeb..acbfb23 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaTextTools.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaTextTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -22,13 +26,12 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.internal.ui.text.JavaColorManager;
import org.eclipse.jdt.internal.ui.text.JavaCommentScanner;
+import org.eclipse.jdt.internal.ui.text.JavaPartitionerManager;
import org.eclipse.jdt.internal.ui.text.SingleTokenJavaScanner;
import org.eclipse.jdt.internal.ui.text.java.JavaCodeScanner;
import org.eclipse.jdt.internal.ui.text.javadoc.JavaDocScanner;
@@ -48,18 +51,6 @@
public class JavaTextTools {
/**
- * Array with legal content types.
- * @since 3.0
- */
- private final static String[] LEGAL_CONTENT_TYPES= new String[] {
- IJavaPartitions.JAVA_DOC,
- IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
- IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
- IJavaPartitions.JAVA_STRING,
- IJavaPartitions.JAVA_CHARACTER
- };
-
- /**
* This tools' preference listener.
*/
private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
@@ -95,6 +86,7 @@
/** The preference change listener */
private PreferenceListener fPreferenceListener= new PreferenceListener();
+ private JavaPartitionerManager fJavaPartitionerManager;
/**
* Creates a new Java text tools collection.
@@ -173,6 +165,7 @@
fSinglelineCommentScanner= new JavaCommentScanner(fColorManager, store, coreStore, IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT);
fStringScanner= new SingleTokenJavaScanner(fColorManager, store, IJavaColorConstants.JAVA_STRING);
fJavaDocScanner= new JavaDocScanner(fColorManager, store, coreStore);
+ fJavaPartitionerManager= new JavaPartitionerManager();
}
/**
@@ -202,6 +195,11 @@
fPreferenceListener= null;
}
+
+ if (fJavaPartitionerManager != null) {
+ fJavaPartitionerManager.dispose();
+ fJavaPartitionerManager= null;
+ }
}
/**
@@ -220,6 +218,17 @@
}
/**
+ * Returns a java partitioner manager which is to be
+ * used for Java text viewers
+ *
+ * @return a java partitioner manager
+ * @since 3.19
+ */
+ public IJavaPartitionerManager getJavaPartitionerManager() {
+ return fJavaPartitionerManager;
+ }
+
+ /**
* Returns a scanner which is configured to scan Java source code.
*
* @return a Java source code scanner
@@ -288,7 +297,7 @@
* @return a Java partition scanner
*/
public IPartitionTokenScanner getPartitionScanner() {
- return new FastJavaPartitionScanner();
+ return fJavaPartitionerManager.getPartitionScanner();
}
/**
@@ -299,7 +308,7 @@
* @return a newly created Java document partitioner
*/
public IDocumentPartitioner createDocumentPartitioner() {
- return new FastPartitioner(getPartitionScanner(), LEGAL_CONTENT_TYPES);
+ return fJavaPartitionerManager.createDocumentPartitioner();
}
/**
@@ -355,6 +364,9 @@
fStringScanner.adaptToPreferenceChange(event);
if (fJavaDocScanner.affectsBehavior(event))
fJavaDocScanner.adaptToPreferenceChange(event);
+ if (fJavaPartitionerManager.affectsBehavior(event)) {
+ fJavaPartitionerManager.adaptToPreferenceChange(event);
+ }
}
/**
diff --git a/pom.xml b/pom.xml
index 802b425..ac3412f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,10 @@
<profiles>
<profile>
<id>build-individual-bundles</id>
+ <properties>
+ <eclipse-p2-repo.url>http://download.eclipse.org/eclipse/updates/4.13-Y-builds</eclipse-p2-repo.url>
+ <skipAPIAnalysis>true</skipAPIAnalysis>
+ </properties>
<repositories>
<repository>
<releases>
@@ -48,6 +52,26 @@
<url>https://repo.eclipse.org/content/repositories/eclipse/</url>
</repository>
</repositories>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho.extras</groupId>
+ <artifactId>tycho-p2-extras-plugin</artifactId>
+ <version>${tycho.version}</version>
+ <executions>
+ <execution> <!-- Checks versions are properly bumped from one stream to the other -->
+ <id>compare-attached-artifacts-with-release</id>
+ <goals>
+ <goal>compare-version-with-baselines</goal>
+ </goals>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</profile>
</profiles>