summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Michael2012-04-02 09:33:19 (EDT)
committer Dani Megert2012-04-02 09:33:19 (EDT)
commitcfd27e285557bf393c955344ac00ab86a9c53c4b (patch)
tree501e9a5943a7bbdb9ccf35f2f1ed05b3ff6aad5e
parent32bb5a8cb659c30f2b9f7df2a96540d25a6b14f7 (diff)
downloadeclipse.jdt.ui-cfd27e285557bf393c955344ac00ab86a9c53c4b.zip
eclipse.jdt.ui-cfd27e285557bf393c955344ac00ab86a9c53c4b.tar.gz
eclipse.jdt.ui-cfd27e285557bf393c955344ac00ab86a9c53c4b.tar.bz2
Fixed bug 348368: [syntax highlighting] Add highlight for inheritedv20120402-1333
fields
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/SemanticHighlightingTest.java85
-rw-r--r--org.eclipse.jdt.text.tests/testResources/semanticHighlightingTest1/SHTest.java5
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java8
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightings.java90
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ColorSettingPreviewCode.txt6
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorColoringConfigurationBlock.java9
7 files changed, 160 insertions, 47 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/SemanticHighlightingTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/SemanticHighlightingTest.java
index e772c66..366f127 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/SemanticHighlightingTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/SemanticHighlightingTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Björn Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
+ * Björn Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
*******************************************************************************/
package org.eclipse.jdt.text.tests;
@@ -71,21 +72,33 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
public void testFieldHighlighting() throws Exception {
setUpSemanticHighlighting(SemanticHighlightings.FIELD);
Position[] expected= new Position[] {
- createPosition(3, 5, 5),
- createPosition(4, 12, 11),
- createPosition(5, 11, 10),
- createPosition(6, 18, 16),
- createPosition(22, 5, 15),
- createPosition(25, 2, 15),
- createPosition(31, 9, 6),
- createPosition(32, 6, 11),
- createPosition(32, 31, 5),
- createPosition(33, 6, 17),
+ createPosition( 3, 5, 5),
+ createPosition( 4, 12, 11),
+ createPosition( 5, 11, 10),
+ createPosition( 6, 18, 16),
+ createPosition(22, 5, 15),
+ createPosition(25, 2, 15),
+ createPosition(31, 9, 6),
+ createPosition(32, 6, 11),
+ createPosition(32, 31, 5),
+ createPosition(33, 6, 17),
createPosition(33, 32, 11),
- createPosition(34, 6, 16),
+ createPosition(34, 6, 16),
createPosition(34, 36, 10),
- createPosition(35, 6, 22),
+ createPosition(35, 6, 22),
createPosition(35, 37, 16),
+ createPosition(48, 6, 14),
+ createPosition(48, 22, 5),
+ };
+ Position[] actual= getSemanticHighlightingPositions();
+// System.out.println(toString(actual));
+ assertEqualPositions(expected, actual);
+ }
+
+ public void testInheritedFieldHighlighting() throws Exception {
+ setUpSemanticHighlighting(SemanticHighlightings.INHERITED_FIELD);
+ Position[] expected= new Position[] {
+ createPosition(48, 22, 5),
};
Position[] actual= getSemanticHighlightingPositions();
// System.out.println(toString(actual));
@@ -273,14 +286,16 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.ABSTRACT_CLASS);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
- createPosition(2, 15, 6),
- createPosition(31, 2, 6),
- createPosition(31, 17, 6),
- createPosition(32, 19, 6),
- createPosition(33, 25, 6),
- createPosition(34, 24, 6),
- createPosition(35, 30, 6),
- createPosition(39, 25, 6),
+ createPosition( 2, 15, 6),
+ createPosition(31, 2, 6),
+ createPosition(31, 17, 6),
+ createPosition(32, 19, 6),
+ createPosition(33, 25, 6),
+ createPosition(34, 24, 6),
+ createPosition(35, 30, 6),
+ createPosition(39, 25, 6),
+ createPosition(47, 23, 14),
+ createPosition(47, 46, 6),
};
// System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@@ -290,21 +305,23 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.CLASS);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
- createPosition(2, 15, 6),
- createPosition(14, 16, 9),
- createPosition(24, 1, 13),
+ createPosition( 2, 15, 6),
+ createPosition(14, 16, 9),
+ createPosition(24, 1, 13),
createPosition(27, 10, 10),
- createPosition(30, 7, 10),
+ createPosition(30, 7, 10),
createPosition(30, 26, 13),
- createPosition(31, 2, 6),
- createPosition(31, 17, 6),
- createPosition(32, 19, 6),
- createPosition(33, 25, 6),
- createPosition(34, 24, 6),
- createPosition(35, 30, 6),
- createPosition(39, 7, 7),
- createPosition(39, 25, 6),
- createPosition(41, 8, 6),
+ createPosition(31, 2, 6),
+ createPosition(31, 17, 6),
+ createPosition(32, 19, 6),
+ createPosition(33, 25, 6),
+ createPosition(34, 24, 6),
+ createPosition(35, 30, 6),
+ createPosition(39, 7, 7),
+ createPosition(39, 25, 6),
+ createPosition(41, 8, 6),
+ createPosition(47, 23, 14),
+ createPosition(47, 46, 6),
};
// System.out.println(toString(actual));
assertEqualPositions(expected, actual);
diff --git a/org.eclipse.jdt.text.tests/testResources/semanticHighlightingTest1/SHTest.java b/org.eclipse.jdt.text.tests/testResources/semanticHighlightingTest1/SHTest.java
index 384541d..7a83190 100644
--- a/org.eclipse.jdt.text.tests/testResources/semanticHighlightingTest1/SHTest.java
+++ b/org.eclipse.jdt.text.tests/testResources/semanticHighlightingTest1/SHTest.java
@@ -35,7 +35,7 @@ abstract class SHTest {
int parentFinalField= SHTest.this.finalField;
int parentStaticFinalField= SHTest.staticFinalField;
}
-
+
@SuppressWarnings(value="all")
class Generic<E extends Number> {
E method() {
@@ -45,4 +45,7 @@ abstract class SHTest {
return null;
}
}
+ static abstract class NestedSubClass extends SHTest {
+ int inheritedField= field;
+ }
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
index 1c7fd56..4a5de8d 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* 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
* Björn Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
+ * Björn Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
@@ -116,6 +117,7 @@ final class JavaEditorMessages extends NLS {
public static String SemanticHighlighting_field;
public static String SemanticHighlighting_staticField;
public static String SemanticHighlighting_staticFinalField;
+ public static String SemanticHighlighting_inheritedField;
public static String SemanticHighlighting_methodDeclaration;
public static String SemanticHighlighting_staticMethodInvocation;
public static String SemanticHighlighting_annotationElementReference;
@@ -161,10 +163,10 @@ final class JavaEditorMessages extends NLS {
public static String JavaElementReturnTypeHyperlink_hyperlinkText;
public static String JavaElementReturnTypeHyperlink_error_msg;
public static String JavaElementSuperImplementationHyperlink_hyperlinkText;
- public static String JavaElementSuperImplementationHyperlink_hyperlinkText_qualified;
+ public static String JavaElementSuperImplementationHyperlink_hyperlinkText_qualified;
static {
NLS.initializeMessages(BUNDLE_NAME, JavaEditorMessages.class);
}
-} \ No newline at end of file
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
index 02d40c4..d0f61ca 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2011 IBM Corporation and others.
+# Copyright (c) 2000, 2012 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
# 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
# Bjoern Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
+# Bjoern Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
###############################################################################
AddImportOnSelection_label=A&dd Import
@@ -104,6 +105,7 @@ SemanticHighlighting_job= Semantic Highlighting Job
SemanticHighlighting_field= Fields
SemanticHighlighting_staticField= Static fields
SemanticHighlighting_staticFinalField= Constants
+SemanticHighlighting_inheritedField= Inherited fields
SemanticHighlighting_methodDeclaration= Method declarations
SemanticHighlighting_staticMethodInvocation= Static method invocations
SemanticHighlighting_annotationElementReference= Annotation element references
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 2c889aa..7b8d257 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, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* 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
* Björn Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
+ * Björn Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
@@ -50,7 +51,6 @@ import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.ui.PreferenceConstants;
-
/**
* Semantic highlightings
*
@@ -191,6 +191,13 @@ public class SemanticHighlightings {
public static final String ABSTRACT_CLASS="abstractClass"; //$NON-NLS-1$
/**
+ * A named preference part that controls the highlighting of inherited fields.
+ *
+ * @since 3.8
+ */
+ public static final String INHERITED_FIELD="inheritedField"; //$NON-NLS-1$
+
+ /**
* Semantic highlightings
*/
private static SemanticHighlighting[] fgSemanticHighlightings;
@@ -1915,6 +1922,84 @@ public class SemanticHighlightings {
}
/**
+ * Semantic highlighting for inherited field access.
+ * @since 3.8
+ */
+ private static final class InheritedFieldHighlighting extends SemanticHighlighting {
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
+ */
+ @Override
+ public String getPreferenceKey() {
+ return INHERITED_FIELD;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
+ */
+ @Override
+ public RGB getDefaultDefaultTextColor() {
+ return new RGB(0, 0, 192);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
+ */
+ @Override
+ public boolean isBoldByDefault() {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
+ */
+ @Override
+ public boolean isItalicByDefault() {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
+ */
+ @Override
+ public boolean isEnabledByDefault() {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
+ */
+ @Override
+ public String getDisplayName() {
+ return JavaEditorMessages.SemanticHighlighting_inheritedField;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
+ */
+ @Override
+ public boolean consumes(final SemanticToken token) {
+ final SimpleName node= token.getNode();
+ if (node.isDeclaration()) {
+ return false;
+ }
+
+ final IBinding binding= token.getBinding();
+ if (binding == null || binding.getKind() != IBinding.VARIABLE) {
+ return false;
+ }
+
+ ITypeBinding currentType= Bindings.getBindingOfParentType(node);
+ ITypeBinding declaringType= ((IVariableBinding) binding).getDeclaringClass();
+ if (declaringType == null || currentType == declaringType)
+ return false;
+
+ return Bindings.isSuperType(declaringType, currentType);
+ }
+ }
+
+ /**
* A named preference that controls the given semantic highlighting's color.
*
* @param semanticHighlighting the semantic highlighting
@@ -1986,6 +2071,7 @@ public class SemanticHighlightings {
new AutoboxHighlighting(),
new StaticFinalFieldHighlighting(),
new StaticFieldHighlighting(),
+ new InheritedFieldHighlighting(),
new FieldHighlighting(),
new MethodDeclarationHighlighting(),
new StaticMethodInvocationHighlighting(),
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ColorSettingPreviewCode.txt b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ColorSettingPreviewCode.txt
index d9b08aa..4d5ef66 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ColorSettingPreviewCode.txt
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ColorSettingPreviewCode.txt
@@ -4,7 +4,7 @@
* @author author
* @deprecated use <code>OtherClass</code>
*/
-public class ClassName<E> implements InterfaceName<String> {
+public class ClassName<E> extends AnyClass implements InterfaceName<String> {
enum Color { RED, GREEN, BLUE };
/* This comment may span multiple lines. */
static Object staticField;
@@ -14,9 +14,9 @@ public class ClassName<E> implements InterfaceName<String> {
// TASK: refactor
@SuppressWarnings(value="all")
public int foo(Integer parameter) {
- abstractMethod();
+ abstractMethod(inheritedField);
int local= 42*hashCode();
staticMethod();
return bar(local) + parameter;
}
-} \ No newline at end of file
+}
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 32e945a..58f5e80 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, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* 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
* Björn Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
+ * Björn Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
@@ -897,8 +898,9 @@ class JavaEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
return new SemanticHighlightingManager.HighlightedRange[][] {
{ createHighlightedRange( 6, 13, 9, SemanticHighlightings.DEPRECATED_MEMBER), createHighlightedRange( 6, 13, 9, SemanticHighlightings.CLASS), },
{ createHighlightedRange( 6, 23, 1, SemanticHighlightings.TYPE_VARIABLE), createHighlightedRange( 6, 23, 1, SemanticHighlightings.TYPE_ARGUMENT), },
- { createHighlightedRange( 6, 37, 13, SemanticHighlightings.INTERFACE) },
- { createHighlightedRange( 6, 51, 6, SemanticHighlightings.TYPE_ARGUMENT), createHighlightedRange( 6, 51, 6, SemanticHighlightings.CLASS) },
+ { createHighlightedRange( 6, 34, 8, SemanticHighlightings.CLASS) },
+ { createHighlightedRange( 6, 54, 13, SemanticHighlightings.INTERFACE) },
+ { createHighlightedRange( 6, 68, 6, SemanticHighlightings.TYPE_ARGUMENT), createHighlightedRange( 6, 68, 6, SemanticHighlightings.CLASS) },
{ createHighlightedRange( 7, 6, 5, SemanticHighlightings.ENUM), },
{ createHighlightedRange( 7, 14, 3, SemanticHighlightings.STATIC_FINAL_FIELD), createHighlightedRange( 7, 14, 3, SemanticHighlightings.STATIC_FIELD), createHighlightedRange(7, 14, 3, SemanticHighlightings.FIELD) },
{ createHighlightedRange( 7, 19, 5, SemanticHighlightings.STATIC_FINAL_FIELD), createHighlightedRange( 7, 19, 5, SemanticHighlightings.STATIC_FIELD), createHighlightedRange(7, 19, 5, SemanticHighlightings.FIELD) },
@@ -915,6 +917,7 @@ class JavaEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
{ createHighlightedRange(15, 16, 7, SemanticHighlightings.CLASS) },
{ createHighlightedRange(15, 24, 9, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange(16, 2, 14, SemanticHighlightings.ABSTRACT_METHOD_INVOCATION), createHighlightedRange(16, 2, 14, SemanticHighlightings.METHOD) },
+ { createHighlightedRange(16, 17, 14, SemanticHighlightings.INHERITED_FIELD), createHighlightedRange(16, 17, 14, SemanticHighlightings.FIELD) },
{ createHighlightedRange(17, 6, 5, SemanticHighlightings.LOCAL_VARIABLE_DECLARATION) },
{ createHighlightedRange(17, 13, 2, SemanticHighlightings.NUMBER) },
{ createHighlightedRange(17, 16, 8, SemanticHighlightings.INHERITED_METHOD_INVOCATION), createHighlightedRange(17, 16, 8, SemanticHighlightings.METHOD) },