-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8339603: Seal the class hierarchy of Node, Camera, LightBase, Shape, Shape3D #1556
base: master
Are you sure you want to change the base?
Changes from 3 commits
c24aed5
38b7a22
ba6c542
8332d7e
4d3ba39
d5cd8cb
c7f8b72
1921be2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.sun.javafx.scene; | ||
|
||
import javafx.scene.Node; | ||
|
||
/** | ||
* This class only exists so that JavaFX code can extend the {@code Node} class across module | ||
* boundaries, as classes in other modules cannot be permitted subclasses. | ||
*/ | ||
public abstract non-sealed class AbstractNode extends Node {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.sun.javafx.scene.shape; | ||
|
||
import javafx.scene.shape.Shape; | ||
|
||
/** | ||
* This class only exists so that JavaFX code can extend the {@code Shape} class across module | ||
* boundaries, as classes in other modules cannot be permitted subclasses. | ||
*/ | ||
public abstract non-sealed class AbstractShape extends Shape {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,8 +79,10 @@ | |
import javafx.geometry.Point2D; | ||
import javafx.geometry.Point3D; | ||
import javafx.geometry.Rectangle2D; | ||
import javafx.scene.canvas.Canvas; | ||
import javafx.scene.effect.BlendMode; | ||
import javafx.scene.effect.Effect; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.image.WritableImage; | ||
import javafx.scene.input.ContextMenuEvent; | ||
import javafx.scene.input.DragEvent; | ||
|
@@ -98,6 +100,7 @@ | |
import javafx.scene.input.TouchEvent; | ||
import javafx.scene.input.TransferMode; | ||
import javafx.scene.input.ZoomEvent; | ||
import javafx.scene.shape.Shape; | ||
import javafx.scene.text.Font; | ||
import javafx.scene.transform.Rotate; | ||
import javafx.scene.transform.Transform; | ||
|
@@ -147,6 +150,7 @@ | |
import com.sun.javafx.geom.transform.GeneralTransform3D; | ||
import com.sun.javafx.geom.transform.NoninvertibleTransformException; | ||
import com.sun.javafx.perf.PerformanceTracker; | ||
import com.sun.javafx.scene.AbstractNode; | ||
import com.sun.javafx.scene.BoundsAccessor; | ||
import com.sun.javafx.scene.CameraHelper; | ||
import com.sun.javafx.scene.CssFlags; | ||
|
@@ -227,11 +231,6 @@ | |
* the {@link Platform#startup(Runnable)} method for more information. | ||
* </p> | ||
* | ||
* <p> | ||
* An application should not extend the Node class directly. Doing so may lead to | ||
* an UnsupportedOperationException being thrown. | ||
* </p> | ||
* | ||
* <h2><a id="StringID">String ID</a></h2> | ||
* <p> | ||
* Each node in the scene graph can be given a unique {@link #idProperty id}. This id is | ||
|
@@ -412,7 +411,9 @@ | |
* @since JavaFX 2.0 | ||
*/ | ||
@IDProperty("id") | ||
public abstract class Node implements EventTarget, Styleable { | ||
public abstract sealed class Node | ||
implements EventTarget, Styleable | ||
permits AbstractNode, Camera, LightBase, Parent, SubScene, Canvas, ImageView, Shape, Shape3D { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to use stronger wording in javadoc in regards to extending Nodes. should -> must, etc. (or, rather, 'cannot' and possibly explain why?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed the language that you can't extend those classes, as it is now redundant because it is enforced by the compiler. We shouldn't document obvious facts without providing any added value (for example, adding context and reasoning why it's the way it is). |
||
|
||
/* | ||
* Store the singleton instance of the NodeHelper subclass corresponding | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the right error type?
why change UnsupportedOperationException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
Camera
is sealed, this method cannot be called by user code.UnsupportedOperationException
would be okay if it could reasonably be called, but this is now an invariant that would signal a bug in JavaFX.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe an explanatory comment should be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically use
InternalError
for the case where there should be no possible reason for a particular case, but also useAssertionError
in some cases. Either is OK with me. I agree that a comment to the affect of "Should not ever get here" wouldn't be a bad idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment to
CameraHelper
andLightBaseHelper
.