Skip to content

Commit

Permalink
Convert getTokenSource() methods to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jan 4, 2017
1 parent 3aecb11 commit 89950f9
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/BufferedTokenStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class BufferedTokenStream implements TokenStream {
* The {@link TokenSource} from which tokens for this stream are fetched.
*/
@NotNull
protected tokenSource: TokenSource;
private _tokenSource: TokenSource;

/**
* A collection of all tokens fetched from the token source. The list is
Expand Down Expand Up @@ -75,11 +75,11 @@ export class BufferedTokenStream implements TokenStream {
throw new Error("tokenSource cannot be null");
}

this.tokenSource = tokenSource;
this._tokenSource = tokenSource;
}

@Override
getTokenSource(): TokenSource {
get tokenSource(): TokenSource {
return this.tokenSource;
}

Expand Down Expand Up @@ -295,8 +295,8 @@ export class BufferedTokenStream implements TokenStream {
}

/** Reset this token stream by setting its token source. */
setTokenSource(tokenSource: TokenSource): void {
this.tokenSource = tokenSource;
set tokenSource(tokenSource: TokenSource) {
this._tokenSource = tokenSource;
this.tokens.length = 0;
this.p = -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CommonToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class CommonToken implements WritableToken {
result.source = oldToken.source;
} else {
result.text = oldToken.getText();
result.source = { source: oldToken.getTokenSource(), stream: oldToken.getInputStream() };
result.source = { source: oldToken.tokenSource, stream: oldToken.getInputStream() };
}

return result;
Expand Down Expand Up @@ -222,7 +222,7 @@ export class CommonToken implements WritableToken {
}

@Override
getTokenSource(): TokenSource | undefined {
get tokenSource(): TokenSource | undefined {
return this.source.source;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DefaultErrorStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class DefaultErrorStrategy implements ANTLRErrorStrategy {
current = lookback;
}

return this.constructToken(recognizer.getInputStream().getTokenSource(), expectedTokenType, tokenText, current);
return this.constructToken(recognizer.getInputStream().tokenSource, expectedTokenType, tokenText, current);
}

protected constructToken(
Expand All @@ -592,7 +592,7 @@ export class DefaultErrorStrategy implements ANTLRErrorStrategy {
tokenText: string,
current: Token): Token {
let factory: TokenFactory = tokenSource.getTokenFactory();
let x = current.getTokenSource();
let x = current.tokenSource;
let stream = x ? x.getInputStream() : undefined;

return factory.create(
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
}

getTokenFactory(): TokenFactory {
return this._input.getTokenSource().getTokenFactory();
return this._input.tokenSource.getTokenFactory();
}

/**
Expand Down Expand Up @@ -436,7 +436,7 @@ export abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
compileParseTreePattern(pattern: string, patternRuleIndex: number, lexer?: Lexer): ParseTreePattern {
if (!lexer) {
if (this.getInputStream()) {
let tokenSource = this.getInputStream().getTokenSource();
let tokenSource = this.getInputStream().tokenSource;
if (tokenSource instanceof Lexer) {
lexer = tokenSource;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ParserInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export class ParserInterpreter extends Parser {
throw new Error("Expected exception to have an offending token");
}

let source = tok.getTokenSource();
let source = tok.tokenSource;
let stream = source !== undefined ? source.getInputStream() : undefined;
let sourcePair = { source: source, stream: stream };

Expand All @@ -439,7 +439,7 @@ export class ParserInterpreter extends Parser {
this._ctx.addErrorNode(errToken);
}
else { // NoViableAlt
let source = tok.getTokenSource();
let source = tok.tokenSource;
let errToken: Token =
this.getTokenFactory().create(sourcePair,
Token.INVALID_TYPE, tok.getText(),
Expand Down
2 changes: 1 addition & 1 deletion src/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface Token {

/** Gets the {@link TokenSource} which created this token.
*/
getTokenSource(): TokenSource | undefined;
readonly tokenSource: TokenSource | undefined;

/**
* Gets the {@link CharStream} from which this token was derived.
Expand Down
2 changes: 1 addition & 1 deletion src/TokenStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface TokenStream extends IntStream {
* stream.
*/
//@NotNull
getTokenSource(): TokenSource;
readonly tokenSource: TokenSource;

/**
* Return the text of all tokens within the specified {@code interval}. This
Expand Down
8 changes: 4 additions & 4 deletions src/UnbufferedTokenStream.tssoon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// ConvertTo-TS run at 2016-10-04T11:26:58.9673509-07:00

export class UnbufferedTokenStream implements TokenStream {
protected tokenSource: TokenSource;
private _tokenSource: TokenSource;

/**
* A moving window buffer of the data being scanned. While there's a marker,
Expand Down Expand Up @@ -64,7 +64,7 @@ export class UnbufferedTokenStream implements TokenStream {
}

constructor1(tokenSource: TokenSource, bufferSize: number) {
this.tokenSource = tokenSource;
this._tokenSource = tokenSource;
this.tokens = new Token[bufferSize];
n = 0;
fill(1); // prime the pump
Expand Down Expand Up @@ -106,8 +106,8 @@ export class UnbufferedTokenStream implements TokenStream {
}

@Override
getTokenSource(): TokenSource {
return tokenSource;
get tokenSource(): TokenSource {
return this._tokenSource;
}

@NotNull
Expand Down
2 changes: 1 addition & 1 deletion src/tree/pattern/RuleTagToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class RuleTagToken implements Token {
* <p>The implementation for {@link RuleTagToken} always returns {@code null}.</p>
*/
@Override
getTokenSource(): TokenSource | undefined {
get tokenSource(): TokenSource | undefined {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion test/tool/BaseTest.tssoon
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ export abstract class BaseTest {
}

@Override
getTokenSource(): TokenSource {
get tokenSource(): TokenSource {
return null;
}

Expand Down

0 comments on commit 89950f9

Please sign in to comment.