All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.tinyexpression.parser.MethodParametersParser Maven / Gradle / Ivy

There is a newer version: 1.4.4
Show newest version
package org.unlaxer.tinyexpression.parser;

import org.unlaxer.TokenPredicators;
import org.unlaxer.TypedToken;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.ascii.LeftParenthesisParser;
import org.unlaxer.parser.ascii.RightParenthesisParser;
import org.unlaxer.parser.combinator.Optional;
import org.unlaxer.tinyexpression.parser.javalang.JavaStyleDelimitedLazyChain;
import org.unlaxer.util.annotation.TokenExtractor;

public class MethodParametersParser extends JavaStyleDelimitedLazyChain{

  @Override
  public org.unlaxer.parser.Parsers getLazyParsers() {
    return new Parsers(
        Parser.get(LeftParenthesisParser.class),
        new Optional(
           MethodParametersElementParser.class
        ),
        Parser.get(RightParenthesisParser.class)
    );
  }
  
  @TokenExtractor
  public java.util.Optional> 
    extractTypedVariableParser(TypedToken thisParserParsed , String parameterName){

    return thisParserParsed.flatten().stream()
      .filter(TokenPredicators.parserImplements(TypedVariableParser.class))
      .map(token->token.typed(TypedVariableParser.class))
      .filter(typeToken->{
        TypedVariableParser parser = typeToken.getParser();
        String variableName = parser.getVariableName(typeToken);
        return variableName.equals(parameterName);
      })
      .map(typedToken->
        typedToken.newWithReplace(typedToken.getParser().getRootVariableParer()).typed(TypedVariableParser.class))
      .findFirst();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy