Bug 553421 - [14] syntax coloring for 'record' keyword

Change-Id: Ic05170e68cf5cab844048c8baacdb329a64cb72a
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java
index 7f57be4..89841a1 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2018, 2019 IBM Corporation and others.
+ * Copyright (c) 2018, 2020 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
  *     Red Hat Inc. - copied and modified from SemanticHighlightings
@@ -171,6 +175,11 @@
 	public static final String YIELD_KEYWORD= "yieldKeyword"; //$NON-NLS-1$
 
 	/**
+	 * A named preference part that controls the highlighting of 'record' keywords.
+	 */
+	public static final String RECORD_KEYWORD= "recordKeyword"; //$NON-NLS-1$
+
+	/**
 	 * Do not instantiate
 	 */
 	protected SemanticHighlightingsCore() {
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/util/ASTHelper.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/util/ASTHelper.java
index 12f33a2..9def80a 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/util/ASTHelper.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/util/ASTHelper.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2019 IBM Corporation and others.
+ * Copyright (c) 2019, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -29,6 +29,7 @@
 			case ASTNode.YIELD_STATEMENT:
 				return ast.apiLevel() >= AST.JLS14;
 			case ASTNode.TEXT_BLOCK:
+			case ASTNode.RECORD_DECLARATION:	
 				return ast.isPreviewEnabled();
 		}
 		return true;
@@ -49,4 +50,8 @@
 	public static boolean isSwitchCaseExpressionsSupportedInAST(AST ast) {
 		return isNodeTypeSupportedInAST(ast, ASTNode.SWITCH_CASE);
 	}
+	
+	public static boolean isRecordDeclarationNodeSupportedInAST(AST ast) {
+		return isNodeTypeSupportedInAST(ast, ASTNode.RECORD_DECLARATION);
+	}
 }
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java
index 965a9c7..f02dc2f 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 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
  *******************************************************************************/
@@ -40,6 +44,7 @@
 import org.eclipse.jdt.core.dom.ConstructorInvocation;
 import org.eclipse.jdt.core.dom.Expression;
 import org.eclipse.jdt.core.dom.IMethodBinding;
+import org.eclipse.jdt.core.dom.RecordDeclaration;
 import org.eclipse.jdt.core.dom.SimpleName;
 import org.eclipse.jdt.core.dom.SimpleType;
 import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
@@ -50,6 +55,7 @@
 import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingManager.HighlightedPosition;
 import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingManager.Highlighting;
 import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.DeprecatedMemberHighlighting;
+import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.RecordKeywordHighlighting;
 import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.VarKeywordHighlighting;
 import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.YieldKeywordHighlighting;
 import org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener;
@@ -163,6 +169,25 @@
 			}
 			return true;
 		}
+		
+		@Override
+		public boolean visit(RecordDeclaration node) {
+			AST ast= node.getAST();
+			if (ASTHelper.isRecordDeclarationNodeSupportedInAST(ast)) {
+				int offset= node.getRestrictedIdentifierStartPosition();
+				int length= 6; // length of 'record'
+				if (offset > -1 && length > 0) {
+					for (int i= 0; i < fJobSemanticHighlightings.length; i++) {
+						SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
+						if (semanticHighlighting instanceof RecordKeywordHighlighting) {
+							addPosition(offset, length, fJobHighlightings[i]);
+							return false;
+						}
+					}
+				}
+			}
+			return true;
+		}
 
 		/*
 		 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SimpleName)
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightings.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightings.java
index f45e09b..aef9a40 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightings.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightings.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 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
  *     Andre Soereng <andreis@fast.no> - [syntax highlighting] highlight numbers - https://bugs.eclipse.org/bugs/show_bug.cgi?id=63573
@@ -213,6 +217,11 @@
 	public static final String YIELD_KEYWORD= SemanticHighlightingsCore.YIELD_KEYWORD;
 
 	/**
+	 * A named preference part that controls the highlighting of 'record' keywords.
+	 */
+	public static final String RECORD_KEYWORD= SemanticHighlightingsCore.RECORD_KEYWORD;
+	
+	/**
 	 * Semantic highlightings
 	 */
 	private static SemanticHighlighting[] fgSemanticHighlightings;
@@ -1973,6 +1982,47 @@
 	}
 
 	/**
+	 * Semantic highlighting for 'record' keyword.
+	 */
+	static final class RecordKeywordHighlighting extends SemanticHighlighting {
+
+		@Override
+		public String getPreferenceKey() {
+			return RECORD_KEYWORD;
+		}
+
+		@Override
+		public RGB getDefaultDefaultTextColor() {
+			return new RGB(127, 0, 85);
+		}
+
+		@Override
+		public boolean isBoldByDefault() {
+			return true;
+		}
+
+		@Override
+		public boolean isItalicByDefault() {
+			return false;
+		}
+
+		@Override
+		public boolean isEnabledByDefault() {
+			return true;
+		}
+
+		@Override
+		public String getDisplayName() {
+			return PreferencesMessages.JavaEditorPreferencePage_recordKeyword;
+		}
+
+		@Override
+		public boolean consumes(SemanticToken token) {
+			return false;
+		}
+	}
+	
+	/**
 	 * Semantic highlighting for 'yield' keyword.
 	 */
 	static final class YieldKeywordHighlighting extends SemanticHighlighting {
@@ -2106,6 +2156,7 @@
 				new NumberHighlighting(),
 				new VarKeywordHighlighting(),
 				new YieldKeywordHighlighting(),
+				new RecordKeywordHighlighting()
 			};
 		return fgSemanticHighlightings;
 	}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorColoringConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorColoringConfigurationBlock.java
index ee44dfd..f90d662 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorColoringConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorColoringConfigurationBlock.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 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
  *     Andre Soereng <andreis@fast.no> - [syntax highlighting] highlight numbers - https://bugs.eclipse.org/bugs/show_bug.cgi?id=63573
@@ -269,7 +273,8 @@
 					List<HighlightingColorListItem> visibleChildren= new ArrayList<>();
 					for (HighlightingColorListItem listItem : subList) {
 						if (!listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) &&
-								!listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								!listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) &&
+								!listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							visibleChildren.add(listItem);
 						}
 					}
@@ -726,9 +731,9 @@
 				if (item.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_keywords)) {
 					for (HighlightingColorListItem listItem : fListModel) {
 						if (listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) ||
-								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) ||
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							PreferenceConverter.setValue(getPreferenceStore(), listItem.getColorKey(), fSyntaxForegroundColorEditor.getColorValue());
-							break;
 						}
 					}
 				}
@@ -747,9 +752,9 @@
 				if (item.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_keywords)) {
 					for (HighlightingColorListItem listItem : fListModel) {
 						if (listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) ||
-								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) ||
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							getPreferenceStore().setValue(listItem.getBoldKey(), fBoldCheckBox.getSelection());
-							break;
 						}
 					}
 				}
@@ -768,9 +773,9 @@
 				if (item.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_keywords)) {
 					for (HighlightingColorListItem listItem : fListModel) {
 						if (listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) ||
-								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) ||
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							getPreferenceStore().setValue(listItem.getItalicKey(), fItalicCheckBox.getSelection());
-							break;
 						}
 					}
 				}
@@ -788,9 +793,9 @@
 				if (item.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_keywords)) {
 					for (HighlightingColorListItem listItem : fListModel) {
 						if (listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) ||
-								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) ||
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							getPreferenceStore().setValue(listItem.getStrikethroughKey(), fStrikethroughCheckBox.getSelection());
-							break;
 						}
 					}
 				}
@@ -809,9 +814,9 @@
 				if (item.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_keywords)) {
 					for (HighlightingColorListItem listItem : fListModel) {
 						if (listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_varKeyword) ||
-								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword)) {
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_yieldKeyword) ||
+								listItem.getDisplayName().equals(PreferencesMessages.JavaEditorPreferencePage_recordKeyword)) {
 							getPreferenceStore().setValue(listItem.getUnderlineKey(), fUnderlineCheckBox.getSelection());
-							break;
 						}
 					}
 				}
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 aee29c7..3c7d95c 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -153,6 +153,7 @@
 	public static String JavaEditorPreferencePage_keywords;
 	public static String JavaEditorPreferencePage_varKeyword;
 	public static String JavaEditorPreferencePage_yieldKeyword;
+	public static String JavaEditorPreferencePage_recordKeyword;
 	public static String JavaEditorPreferencePage_strings;
 	public static String JavaEditorPreferencePage_others;
 	public static String JavaEditorPreferencePage_operators;
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 85f4f57..300526b 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
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2019 IBM Corporation and others.
+# Copyright (c) 2000, 2020 IBM Corporation and others.
 #
 # This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License 2.0
@@ -131,6 +131,7 @@
 JavaEditorPreferencePage_keywords=Keywords excluding 'return'
 JavaEditorPreferencePage_varKeyword=Keyword 'var'
 JavaEditorPreferencePage_yieldKeyword=Keyword 'yield'
+JavaEditorPreferencePage_recordKeyword=Keyword 'record'
 JavaEditorPreferencePage_strings=Strings
 JavaEditorPreferencePage_others=Others
 JavaEditorPreferencePage_operators=Operators