public final class Comment extends Object implements Writable
By default, comments are not written out. You can control this behavior with StyleWriter.writeAllComments(boolean)
.
Constructor and Description |
---|
Comment(CssAnnotation annotation)
Creates a new
Comment with the given CssAnnotation as the content. |
Comment(String content)
Creates a new
Comment with the given content. |
Modifier and Type | Method and Description |
---|---|
Optional<CssAnnotation> |
annotation()
Gets the
CssAnnotation within this comment, if there is one. |
Optional<CssAnnotation> |
annotation(String name)
Gets the
CssAnnotation with the given name, if there is one. |
String |
content()
Gets the content of the comment.
|
boolean |
hasAnnotation(CssAnnotation annotation)
Checks if this comment has a
CssAnnotation that equals the given one. |
boolean |
hasAnnotation(String name)
Checks if this comment has a
CssAnnotation with the given name. |
boolean |
isWritable()
Returns whether this unit should actually be written.
|
boolean |
startsWithBang()
Returns whether the comment starts with ! (this is strict, no whitespace allowed between the opening comment and the
bang).
|
String |
toString() |
void |
write(StyleWriter writer,
StyleAppendable appendable)
Outputs this
Writable 's string representation. |
public Comment(String content)
Comment
with the given content.content
- The content.public Comment(CssAnnotation annotation)
Comment
with the given CssAnnotation
as the content.annotation
- The annotation representing the comment.public String content()
public boolean hasAnnotation(String name)
CssAnnotation
with the given name.
CSS comment annotations are CSS comments that contain an annotation in the format of "@annotationName [optionalArgs]", for example "@noparse", "@browser ie7", etc...
Only one annotation per comment block is allowed.
name
- Check for an annotation with this name.CssAnnotation
was found with the given name.public boolean hasAnnotation(CssAnnotation annotation)
CssAnnotation
that equals the given one.
This will be true if the both the name and the args match exactly. See CssAnnotation.equals(Object)
. If you only
care about matching the comment name, see hasAnnotation(String)
instead.
annotation
- Check for an annotation that equals this one.Comment
was found that matches the given one.public Optional<CssAnnotation> annotation(String name)
CssAnnotation
with the given name, if there is one.
CSS comment annotations are CSS comments that contain an annotation in the format of "@annotationName [optionalArgs]", for example "@noparse", "@browser ie7", etc...
Only one annotation per comment block is allowed.
name
- Get the annotation with this name.CssAnnotation
, or an empty Optional
if not found.public Optional<CssAnnotation> annotation()
CssAnnotation
within this comment, if there is one.
CSS comment annotations are CSS comments that contain an annotation in the format of "@annotationName [optionalArgs]", for example "@noparse", "@browser ie7", etc...
Only one annotation per comment block is allowed.
CssAnnotation
, or an empty Optional
if not found.public boolean startsWithBang()
public boolean isWritable()
Writable
Usually this should just return true, however some units that are detachable or otherwise potentially invalid should first check their state and respond appropriately.
isWritable
in interface Writable
public void write(StyleWriter writer, StyleAppendable appendable) throws IOException
Writable
Writable
's string representation.
Important notes for implementation:
Do not use the StyleWriter
in an attempt to write direct content (Strings, chars, etc...). Use the StyleAppendable
.
The StyleWriter
should be used to make decisions based on writer settings (e.g., compressed vs. verbose output
mode), as well as for writing inner or child Writable
s. Do not call the this method method directly on inner
or child Writable
s! That would bypass any overrides that are set on the StyleWriter
. Use StyleWriter.writeInner(Writable, StyleAppendable)
instead.
write
in interface Writable
writer
- Writer to use for output settings and for writing inner Writable
s.appendable
- Append direct content to this StyleAppendable
.IOException
- If an I/O error occurs.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.