From 9e8637eb7488c1db4ed6573b1b5324954119d748 Mon Sep 17 00:00:00 2001 From: Suseika Date: Thu, 20 Aug 2015 17:57:33 +0500 Subject: [PATCH] #96 Use AbstractDelegatingPlaceholder in Parsed* implementations To remove code duplication in Parsed* implementations --- .../AbstractDelegatingPlaceholder.java | 2 +- .../ParsedSinglePartPlaceholder.java | 29 ++++--------------- ...rsedTwoPartVariableConceptPlaceholder.java | 29 +++++-------------- 3 files changed, 13 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/tendiwa/inflectible/AbstractDelegatingPlaceholder.java b/src/main/java/org/tendiwa/inflectible/AbstractDelegatingPlaceholder.java index 7223e23..1841972 100644 --- a/src/main/java/org/tendiwa/inflectible/AbstractDelegatingPlaceholder.java +++ b/src/main/java/org/tendiwa/inflectible/AbstractDelegatingPlaceholder.java @@ -36,7 +36,7 @@ public abstract class AbstractDelegatingPlaceholder implements Placeholder { * Ctor. */ AbstractDelegatingPlaceholder() { - + // Doesn't need to store anything, class' purpose is to delegate methods } /** diff --git a/src/main/java/org/tendiwa/inflectible/ParsedSinglePartPlaceholder.java b/src/main/java/org/tendiwa/inflectible/ParsedSinglePartPlaceholder.java index 8fabd2e..e68cf19 100644 --- a/src/main/java/org/tendiwa/inflectible/ParsedSinglePartPlaceholder.java +++ b/src/main/java/org/tendiwa/inflectible/ParsedSinglePartPlaceholder.java @@ -23,7 +23,6 @@ */ package org.tendiwa.inflectible; -import com.google.common.collect.ImmutableSet; import org.tendiwa.inflectible.antlr.TemplateBundleParser; /** @@ -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. */ @@ -46,6 +46,7 @@ public final class ParsedSinglePartPlaceholder implements Placeholder { ParsedSinglePartPlaceholder( final TemplateBundleParser.SinglePartPlaceholderContext context ) { + super(); this.ctx = context; } @@ -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( @@ -64,7 +66,6 @@ private Placeholder delegate() { ); } - // To be refactored in #47 /** * Adds capitalization if it was declared in markup. @@ -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 grammaticalMeaning( - final ActualArguments arguments - ) throws Exception { - return this.delegate().grammaticalMeaning(arguments); - } - - @Override - public Spelling capitalize(final Spelling spelling) { - return this.delegate().capitalize(spelling); - } } diff --git a/src/main/java/org/tendiwa/inflectible/ParsedTwoPartVariableConceptPlaceholder.java b/src/main/java/org/tendiwa/inflectible/ParsedTwoPartVariableConceptPlaceholder.java index 0d77410..10742fb 100644 --- a/src/main/java/org/tendiwa/inflectible/ParsedTwoPartVariableConceptPlaceholder.java +++ b/src/main/java/org/tendiwa/inflectible/ParsedTwoPartVariableConceptPlaceholder.java @@ -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. */ @@ -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 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( @@ -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. */ @@ -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. */ @@ -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