Skip to content

Commit

Permalink
#96 Use AbstractDelegatingPlaceholder in Parsed* implementations
Browse files Browse the repository at this point in the history
To remove code duplication in Parsed* implementations
  • Loading branch information
Suseika committed Aug 20, 2015
1 parent a92a820 commit 9e8637e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractDelegatingPlaceholder implements Placeholder {
* Ctor.
*/
AbstractDelegatingPlaceholder() {

// Doesn't need to store anything, class' purpose is to delegate methods
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.tendiwa.inflectible;

import com.google.common.collect.ImmutableSet;
import org.tendiwa.inflectible.antlr.TemplateBundleParser;

/**
Expand All @@ -32,7 +31,8 @@
* @version $Id$
* @since 0.1
*/
public final class ParsedSinglePartPlaceholder implements Placeholder {
public final class ParsedSinglePartPlaceholder
extends AbstractDelegatingPlaceholder {
/**
* ANTLR parse tree of a placeholder.
*/
Expand All @@ -46,6 +46,7 @@ public final class ParsedSinglePartPlaceholder implements Placeholder {
ParsedSinglePartPlaceholder(
final TemplateBundleParser.SinglePartPlaceholderContext context
) {
super();
this.ctx = context;
}

Expand All @@ -54,7 +55,8 @@ public final class ParsedSinglePartPlaceholder implements Placeholder {
* {@link ParsedLexeme#ctx}.
* @return Lexeme from markup.
*/
private Placeholder delegate() {
@Override
public Placeholder delegate() {
return this.withCapitalizaton(
new PhFromArgument(
new ArgumentName(
Expand All @@ -64,7 +66,6 @@ private Placeholder delegate() {
);
}


// To be refactored in #47
/**
* Adds capitalization if it was declared in markup.
Expand All @@ -89,24 +90,4 @@ private Placeholder withCapitalizaton(final Placeholder placeholder) {
private String argumentIdentifier() {
return this.ctx.CAPITALIZABLE_ID().getText();
}

@Override
public Lexeme pickLexeme(
final ActualArguments arguments,
final Vocabulary vocabulary
) throws Exception {
return this.delegate().pickLexeme(arguments, vocabulary);
}

@Override
public ImmutableSet<Grammeme> grammaticalMeaning(
final ActualArguments arguments
) throws Exception {
return this.delegate().grammaticalMeaning(arguments);
}

@Override
public Spelling capitalize(final Spelling spelling) {
return this.delegate().capitalize(spelling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* @version $Id$
* @since 0.1
*/
final class ParsedTwoPartVariableConceptPlaceholder implements Placeholder {
final class ParsedTwoPartVariableConceptPlaceholder
extends AbstractDelegatingPlaceholder {
/**
* Grammar of the language of this placeholder.
*/
Expand All @@ -62,31 +63,12 @@ final class ParsedTwoPartVariableConceptPlaceholder implements Placeholder {
this.ctx = context;
}

@Override
public Lexeme pickLexeme(
final ActualArguments arguments,
final Vocabulary vocabulary
) throws Exception {
return this.delegate().pickLexeme(arguments, vocabulary);
}

@Override
public ImmutableSet<Grammeme> grammaticalMeaning(
final ActualArguments arguments
) throws Exception {
return this.delegate().grammaticalMeaning(arguments);
}

@Override
public Spelling capitalize(final Spelling spelling) {
return this.delegate().capitalize(spelling);
}

/**
* Creates the placeholder from ANTLR parse tree.
* @return Placeholder
*/
private Placeholder delegate() {
@Override
public Placeholder delegate() {
return
this.withCapitalization(
this.withAgreement(
Expand All @@ -99,6 +81,7 @@ private Placeholder delegate() {

/**
* Adds agreement to the placeholder if markup says so.
* @param placeholder Placeholder to decorate
* @return Placeholder decorated with {@link PhWithAgreement}, or the same
* placeholder if markup doesn't declare agreement here.
*/
Expand Down Expand Up @@ -127,6 +110,7 @@ private boolean hasAgreement() {

/**
* Adds capitalization to the placeholder if markup says so.
* @param placeholder Placeholder to decorate
* @return Placeholder decorated with {@link PhWithCapitalization}, or the
* same placeholder if markup doesn't declare capitalization here.
*/
Expand All @@ -142,6 +126,7 @@ private Placeholder withCapitalization(final Placeholder placeholder) {

/**
* Adds static grammatical meaning to the placeholder if markup says so.
* @param placeholder Placeholder to decorate
* @return Placeholder decorated with {@link PhWithGrammemes}, or the
* same placeholder if markup doesn't declare adding static grammatical
* meaning here
Expand Down

0 comments on commit 9e8637e

Please sign in to comment.