Skip to content

Commit

Permalink
fix a bunch of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Mar 29, 2019
1 parent 4cd344d commit fc007ef
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ public CSSCharsetRuleImpl(
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down Expand Up @@ -116,8 +114,9 @@ public String toString() {
}

/**
* @return the current css text
* {@inheritDoc}
*/
@Override
public String getCssText() {
final StringBuilder sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public CSSFontFaceRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final Abstr
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
final StringBuilder sb = new StringBuilder();
sb.append("@font-face {");
Expand All @@ -58,13 +59,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public CSSImportRuleImpl(
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
final StringBuilder sb = new StringBuilder();
sb.append("@import");
Expand All @@ -73,13 +74,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/gargoylesoftware/css/dom/CSSMediaRuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public CSSMediaRuleImpl(
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
final StringBuilder sb = new StringBuilder("@media ");

Expand All @@ -68,13 +69,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down Expand Up @@ -129,8 +128,7 @@ public CSSRuleListImpl getCssRules() {
public void insertRule(final String rule, final int index) throws DOMException {
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheet();

try {
final InputSource is = new InputSource(new StringReader(rule));
try (InputSource is = new InputSource(new StringReader(rule))) {
final CSSOMParser parser = new CSSOMParser();
parser.setParentStyleSheet(parentStyleSheet);
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public CSSPageRuleImpl(
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
final StringBuilder sb = new StringBuilder();

Expand All @@ -72,13 +73,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class CSSRuleListImpl implements Serializable {

private List<AbstractCSSRuleImpl> rules_ = new ArrayList<AbstractCSSRuleImpl>();
private List<AbstractCSSRuleImpl> rules_ = new ArrayList<>();

/**
* @return the rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CSSStyleDeclarationImpl implements Serializable {
private static final String PRIORITY_IMPORTANT = "important";

private AbstractCSSRuleImpl parentRule_;
private List<Property> properties_ = new ArrayList<Property>();
private List<Property> properties_ = new ArrayList<>();

/**
* Ctor.
Expand Down Expand Up @@ -77,8 +77,7 @@ public String getCssText() {
* @throws DOMException in case of error
*/
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
properties_.clear();
parser.parseStyleDeclaration(this, is);
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/gargoylesoftware/css/dom/CSSStyleRuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void setSelectors(final SelectorList selectors) {
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
final CSSStyleDeclarationImpl style = getStyle();
if (null == style) {
Expand All @@ -82,13 +83,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down Expand Up @@ -130,8 +129,7 @@ public String getSelectorText() {
* @throws DOMException in clase of error
*/
public void setSelectorText(final String selectorText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(selectorText));
try (InputSource is = new InputSource(new StringReader(selectorText))) {
final CSSOMParser parser = new CSSOMParser();
selectors_ = parser.parseSelectors(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public CSSRuleListImpl getCssRules() {
* @throws DOMException in case of error
*/
public void insertRule(final String rule, final int index) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(rule));
try (InputSource is = new InputSource(new StringReader(rule))) {
final CSSOMParser parser = new CSSOMParser();
parser.setParentStyleSheet(this);
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
Expand Down Expand Up @@ -260,8 +259,7 @@ public void setTitle(final String title) {
* @param mediaText the new media text
*/
public void setMediaText(final String mediaText) {
final InputSource source = new InputSource(new StringReader(mediaText));
try {
try (InputSource source = new InputSource(new StringReader(mediaText))) {
final CSSOMParser parser = new CSSOMParser();
final MediaQueryList sml = parser.parseMedia(source);
media_ = new MediaListImpl(sml);
Expand Down Expand Up @@ -402,7 +400,7 @@ private static final class SelectorIndex {
void add(final String key, final SelectorEntry selector) {
List<SelectorEntry> entry = keyToSelectors_.get(key);
if (entry == null) {
entry = new ArrayList<SelectorEntry>();
entry = new ArrayList<>();
keyToSelectors_.put(key, entry);
}
entry.add(selector);
Expand Down Expand Up @@ -522,7 +520,7 @@ static final class SelectorEntriesIterator implements Iterator<SelectorEntry> {
final String elementName,
final String[] classes) {

iterators_ = new LinkedList<Iterator<SelectorEntry>>();
iterators_ = new LinkedList<>();

List<SelectorEntry> selectors = index.elementSelectors_.get(null);
if (!selectors.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CSSStyleSheetListImpl {
*/
public List<CSSStyleSheetImpl> getCSSStyleSheets() {
if (cssStyleSheets_ == null) {
cssStyleSheets_ = new ArrayList<CSSStyleSheetImpl>();
cssStyleSheets_ = new ArrayList<>();
}
return cssStyleSheets_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public CSSUnknownRuleImpl(
/**
* {@inheritDoc}
*/
@Override
public String getCssText() {
if (null == text_) {
return "";
Expand All @@ -58,13 +59,11 @@ public String getCssText() {
}

/**
* Sets the css text.
* @param cssText the new css text
* @throws DOMException in case of error
* {@inheritDoc}
*/
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final AbstractCSSRuleImpl r = parser.parseRule(is);

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/gargoylesoftware/css/dom/CSSValueImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ else if (value.getLexicalUnitType() == LexicalUnitType.COUNTERS_FUNCTION) {
}
}

private List<CSSValueImpl> getValues(final LexicalUnit value) {
final List<CSSValueImpl> values = new ArrayList<CSSValueImpl>();
private static List<CSSValueImpl> getValues(final LexicalUnit value) {
final List<CSSValueImpl> values = new ArrayList<>();
LexicalUnit lu = value;
while (lu != null) {
values.add(new CSSValueImpl(lu, true));
Expand Down Expand Up @@ -255,8 +255,7 @@ public String getCssText() {
* @throws DOMException in case of error
*/
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
try (InputSource is = new InputSource(new StringReader(cssText))) {
final CSSOMParser parser = new CSSOMParser();
final CSSValueImpl v2 = parser.parsePropertyValue(is);
value_ = v2.value_;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/gargoylesoftware/css/dom/MediaListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class MediaListImpl extends AbstractLocatable implements Serializable {
* @param mediaList the media list
*/
public MediaListImpl(final MediaQueryList mediaList) {
mediaQueries_ = new ArrayList<MediaQuery>(10);
mediaQueries_ = new ArrayList<>(10);

setMediaList(mediaList);
if (mediaList != null) {
Expand Down Expand Up @@ -77,8 +77,7 @@ public String getMediaText() {
* @throws DOMException in case of error
*/
public void setMediaText(final String mediaText) throws DOMException {
final InputSource source = new InputSource(new StringReader(mediaText));
try {
try (InputSource source = new InputSource(new StringReader(mediaText))) {
final CSSOMParser parser = new CSSOMParser();
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
final MediaQueryList sml = parser.parseMedia(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public MediaQueryList parseMedia(final InputSource source) throws IOException {
return ml;
}

private CharStream getCharStream(final InputSource source) throws IOException {
private static CharStream getCharStream(final InputSource source) throws IOException {
if (source.getReader() != null) {
return new CssCharStream(source.getReader(), 1, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public CSSStyleDeclarationImpl parseStyleDeclaration(final InputSource source) t
* @throws IOException if the underlying SAC parser throws an IOException
*/
public void parseStyleDeclaration(final CSSStyleDeclarationImpl sd, final InputSource source) throws IOException {
final Stack<Object> nodeStack = new Stack<Object>();
final Stack<Object> nodeStack = new Stack<>();
nodeStack.push(sd);
final CSSOMHandler handler = new CSSOMHandler(nodeStack);
parser_.setDocumentHandler(handler);
Expand Down Expand Up @@ -207,7 +207,7 @@ private void setHref(final String href) {
}

CSSOMHandler() {
nodeStack_ = new Stack<Object>();
nodeStack_ = new Stack<>();
}

Object getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public MediaQuery(final String media) {
*/
public MediaQuery(final String media, final boolean isOnly, final boolean isNot) {
media_ = media;
properties_ = new ArrayList<Property>(10);
properties_ = new ArrayList<>(10);
isOnly_ = isOnly;
isNot_ = isNot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MediaQueryList extends AbstractLocatable {
* Ctor.
*/
public MediaQueryList() {
mediaQueries_ = new ArrayList<MediaQuery>();
mediaQueries_ = new ArrayList<>();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
*/
package com.gargoylesoftware.css.parser.selector;

import java.io.Serializable;

/**
* @author Ronald Brill
*/
public class ChildSelector extends AbstractSelector implements Serializable {
public class ChildSelector extends AbstractSelector {

private Selector ancestorSelector_;
private SimpleSelector simpleSelector_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
*/
package com.gargoylesoftware.css.parser.selector;

import java.io.Serializable;

/**
* @author Ronald Brill
*/
public class DescendantSelector extends AbstractSelector implements Serializable {
public class DescendantSelector extends AbstractSelector {

private final Selector ancestorSelector_;
private final SimpleSelector simpleSelector_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
*/
package com.gargoylesoftware.css.parser.selector;

import java.io.Serializable;

/**
* @author Ronald Brill
*/
public class DirectAdjacentSelector extends AbstractSelector implements Serializable {
public class DirectAdjacentSelector extends AbstractSelector {

private final Selector selector_; // child
private final SimpleSelector simpleSelector_;
Expand Down
Loading

0 comments on commit fc007ef

Please sign in to comment.