Skip to content

Commit

Permalink
Fix or suppress deprecation warnings (asciidoctor#528)
Browse files Browse the repository at this point in the history
Plus some minor cleanup.
  • Loading branch information
apoluektov authored and abelsromero committed Dec 14, 2016
1 parent ae4cf8d commit e3b90f3
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public interface Asciidoctor {

public static final String STRUCTURE_MAX_LEVEL = "STRUCTURE_MAX_LEVEL";
String STRUCTURE_MAX_LEVEL = "STRUCTURE_MAX_LEVEL";

/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
Expand Down Expand Up @@ -656,7 +656,7 @@ String[] convertFiles(Collection<File> asciidoctorFiles,
* @author lordofthejars
*
*/
public static class Factory {
class Factory {

/**
* Creates a new instance of Asciidoctor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public AbstractBlockImpl(AbstractBlock blockDelegate, Ruby runtime) {
this.delegate = blockDelegate;
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String title() {
return getTitle();
Expand All @@ -36,6 +38,8 @@ public boolean isTitle() {
return RubyUtils.invokeRubyMethod(delegate, "title?", new Object[0], Boolean.class);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String style() {
return getStyle();
Expand All @@ -50,6 +54,8 @@ public String getCaption() {
return RubyUtils.invokeRubyMethod(delegate, "caption", new Object[0], String.class);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public List<AbstractBlock> blocks() {
return getBlocks();
Expand All @@ -74,11 +80,15 @@ public boolean isBlocks() {
return RubyUtils.invokeRubyMethod(delegate, "blocks?", new Object[0], Boolean.class);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public Object content() {
return getContent();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public Object getContent() {
return delegate.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public String id() {
return this.abstractNode.id();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String context() {
return getContext();
Expand All @@ -38,6 +40,8 @@ public String getContext() {
return this.abstractNode.getContext();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public AbstractNode parent() {
return getParent();
Expand All @@ -48,6 +52,8 @@ public AbstractNode getParent() {
return this.abstractNode.getParent();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public DocumentRuby document() {
return getDocument();
Expand Down Expand Up @@ -123,9 +129,11 @@ public String getRole() {
return this.abstractNode.getRole();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String role() {
return this.abstractNode.role();
return getRole();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface DocumentRuby extends AbstractBlock {
*
* @return page title
*/
@SuppressWarnings("deprecation")
@Deprecated
String title();

/**
Expand All @@ -47,6 +49,8 @@ public interface DocumentRuby extends AbstractBlock {
*
* @return blocks contained within current Document.
*/
@SuppressWarnings("deprecation")
@Deprecated
List<AbstractBlock> blocks();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
public interface Inline extends AbstractNode {

@Deprecated
public String render();
String render();

public String convert();
String convert();

public String getType();
String getType();

public String getText();
String getText();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public InlineImpl(Inline delegate, Ruby ruby) {
this.delegate = delegate;
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String render() {
return delegate.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ListImpl(ListNode delegate, Ruby rubyRuntime) {

@Override
public List<AbstractBlock> getItems() {
return blocks();
return getBlocks();
}

@Override
Expand All @@ -31,6 +31,8 @@ public boolean isItems() {
return isBlocks();
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public String render() {
return listDelegate.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public interface ListItem extends AbstractBlock {

public String getMarker();
String getMarker();

public String getText();
String getText();

public boolean hasText();
boolean hasText();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public interface ListNode extends AbstractBlock {
boolean hasItems();

@Deprecated
public String render();
String render();

public String convert();
String convert();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface Row {

public List<Cell> getCells();
List<Cell> getCells();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

public interface Table extends AbstractBlock {

public static enum HorizontalAlignment {
enum HorizontalAlignment {
LEFT, CENTER, RIGHT
}

public static enum VerticalAlignment {
enum VerticalAlignment {
TOP, BOTTOM, MIDDLE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<Row> getHeader() {
return rows.getHead();
}

public static interface Rows {
public interface Rows {
List<Row> getHead();

List<Row> getFoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,25 @@ private DocumentHeader toDocumentHeader(DocumentRuby documentRuby) {

Document document = new Document(documentRuby, rubyRuntime);

return DocumentHeader.createDocumentHeader((Title) document.doctitle(opts), documentRuby.title(),
return DocumentHeader.createDocumentHeader((Title) document.doctitle(opts), documentRuby.getTitle(),
documentRuby.getAttributes());
}

private StructuredDocument toDocument(DocumentRuby documentRuby, Ruby rubyRuntime, int maxDeepLevel) {

Document document = new Document(documentRuby, rubyRuntime);
List<ContentPart> contentParts = getContents(document.blocks(), 1, maxDeepLevel);
List<ContentPart> contentParts = getContents(document.getBlocks(), 1, maxDeepLevel);
return StructuredDocument.createStructuredDocument(toDocumentHeader(documentRuby), contentParts);
}

private List<ContentPart> getContents(List<AbstractBlock> blocks, int level, int maxDeepLevel) {
// finish getting childs if max structure level was riched
// finish getting children if max structure level was reached
if (level > maxDeepLevel) {
return null;
}
// if document has only one child don't treat as actual contentpart
// unless
// it has no childs
// it has no children
/*
* if (blocks.size() == 1 && blocks.get(0).blocks().size() > 0) { return getContents(blocks.get(0).blocks(), 0,
* maxDeepLevel); }
Expand All @@ -199,16 +199,16 @@ private List<ContentPart> getContents(List<AbstractBlock> blocks, int level, int
}

private ContentPart getContentPartFromBlock(AbstractBlock child, int level, int maxDeepLevel) {
Object content = child.content();
Object content = child.getContent();
String textContent;
if (content instanceof String) {
textContent = (String) content;
} else {
textContent = child.convert();
}
ContentPart contentPart = ContentPart.createContentPart(child.id(), level, child.context(), child.title(),
child.style(), child.role(), child.getAttributes(), textContent);
contentPart.setParts(getContents(child.blocks(), level + 1, maxDeepLevel));
ContentPart contentPart = ContentPart.createContentPart(child.id(), level, child.getContext(), child.getTitle(),
child.getStyle(), child.getRole(), child.getAttributes(), textContent);
contentPart.setParts(getContents(child.getBlocks(), level + 1, maxDeepLevel));
return contentPart;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class WhenAsciiDocIsRenderedToDocument {
@Test
public void should_return_section_blocks() {
Document document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>());
Section section = (Section) document.blocks().get(1);
Section section = (Section) document.getBlocks().get(1);
assertThat(section.index(), is(0));
assertThat(section.sectname(), is("sect1"));
assertThat(section.special(), is(false));
Expand Down Expand Up @@ -144,7 +144,7 @@ public void should_be_able_to_manipulate_attributes() {
@Test
public void should_be_able_to_get_roles() {
Document document = asciidoctor.load(ROLE, new HashMap<String, Object>());
AbstractBlock abstractBlock = document.blocks().get(0);
AbstractBlock abstractBlock = document.getBlocks().get(0);
assertThat(abstractBlock.getRole(), is("famous"));
assertThat(abstractBlock.hasRole("famous"), is(true));
//assertThat(abstractBlock.isRole(), is(true));
Expand All @@ -154,7 +154,7 @@ public void should_be_able_to_get_roles() {
@Test
public void should_be_able_to_get_reftext() {
Document document = asciidoctor.load(REFTEXT, new HashMap<String, Object>());
AbstractBlock abstractBlock = document.blocks().get(0);
AbstractBlock abstractBlock = document.getBlocks().get(0);
assertThat(abstractBlock.getReftext(), is("the first section"));
assertThat(abstractBlock.isReftext(), is(true));
}
Expand Down Expand Up @@ -217,9 +217,9 @@ public void should_load_a_document_from_File() throws FileNotFoundException {
.compact(true).asMap();
File inputFile = classpath.getResource("rendersample.asciidoc");
Document document = asciidoctor.loadFile(inputFile, options);
assertEquals(1, document.blocks().size());
assertThat(document.blocks().get(0), instanceOf(Section.class));
Section section = (Section) document.blocks().get(0);
assertEquals(1, document.getBlocks().size());
assertThat(document.getBlocks().get(0), instanceOf(Section.class));
Section section = (Section) document.getBlocks().get(0);
assertEquals(1, section.getBlocks().size());
assertEquals("<strong>Section A</strong> paragraph.", section.getBlocks().get(0).getContent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Object convert(AbstractNode node, String transform, Map<Object, Object> o
.append(section.getContent()).toString();
} else if (transform.equals("paragraph")) {
AbstractBlock block = (AbstractBlock) node;
String content = (String) block.content();
String content = (String) block.getContent();
return new StringBuilder(content.replaceAll(LINE_SEPARATOR, " ")).append(LINE_SEPARATOR);
} else if (node instanceof ListNode) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Document process(Document document) {

this.document = document;

final List<AbstractBlock> blocks = this.document.blocks();
final List<AbstractBlock> blocks = this.document.getBlocks();

for (int i = 0; i < blocks.size(); i++) {
final AbstractBlock currentBlock = blocks.get(i);
Expand Down

0 comments on commit e3b90f3

Please sign in to comment.