if (context.getChildCount() > 0
&& context.getChild(0) instanceof TerminalNode
&& ((TerminalNode) context.getChild(0)).getSymbol().getType() == JavaParser.LPAREN) {
TypeCast typeCast = createNode(context, TypeCast.class);
TypeContext typeContext = getChild(context, TypeContext.class);
if (typeContext != null) {
typeCast.setType(getAdapter(TypeAdapter.class).adapt(typeContext));
}
ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
if (expressionContext != null) {
typeCast.setExpression(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
}
return typeCast;
}
if (context.getChildCount() == 2
&& context.getChild(1) instanceof TerminalNode
&& POSTFIX_OPERATOR_MAP.containsKey(
((TerminalNode) context.getChild(1)).getSymbol().getType())) {
PostfixExpression postfixExpression = createNode(context, PostfixExpression.class);
postfixExpression.setOperator(
POSTFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(1)).getSymbol().getType()));
ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
if (expressionContext != null) {
postfixExpression.setExpression(
getAdapter(ExpressionAdapter.class).adapt(expressionContext));
}
return postfixExpression;
}
if (context.getChildCount() == 2
&& context.getChild(0) instanceof TerminalNode
&& PREFIX_OPERATOR_MAP.containsKey(
((TerminalNode) context.getChild(0)).getSymbol().getType())) {
PrefixExpression prefixExpression = createNode(context, PrefixExpression.class);
prefixExpression.setOperator(
PREFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(0)).getSymbol().getType()));
ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
if (expressionContext != null) {
prefixExpression.setExpression(
getAdapter(ExpressionAdapter.class).adapt(expressionContext));
}
return prefixExpression;
}
if (context.getChildCount() > 2
&& context.getChild(1) instanceof TerminalNode
&& INFIX_OPERATOR_MAP.containsKey(
((TerminalNode) context.getChild(1)).getSymbol().getType())
&& context.getChild(0) instanceof ExpressionContext
&& context.getChild(context.getChildCount() - 1) instanceof ExpressionContext) {
InfixExpression.Operator operator = null;
if (context.getChildCount() == 3) {
operator =
INFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(1)).getSymbol().getType());
} else if (context.getChildCount() == 4
&& isTerminalNode(context, 1, JavaParser.LT)
&& isTerminalNode(context, 2, JavaParser.LT)) {
operator = InfixExpression.Operator.LEFT_SHIFT;
} else if (context.getChildCount() == 4
&& isTerminalNode(context, 1, JavaParser.GT)
&& isTerminalNode(context, 2, JavaParser.GT)) {
operator = InfixExpression.Operator.SIGNED_RIGHT_SHIFT;
} else if (context.getChildCount() == 5
&& isTerminalNode(context, 1, JavaParser.GT)
&& isTerminalNode(context, 2, JavaParser.GT)
&& isTerminalNode(context, 3, JavaParser.GT)) {
operator = InfixExpression.Operator.UNSIGNED_RIGHT_SHIFT;
}
if (operator != null) {
InfixExpression infixExpression = createNode(context, InfixExpression.class);
infixExpression.setLeftHandSide(
getAdapter(ExpressionAdapter.class).adapt((ExpressionContext) context.getChild(0)));
infixExpression.setOperator(operator);
infixExpression.setRightHandSide(
getAdapter(ExpressionAdapter.class).adapt(
(ExpressionContext) context.getChild(context.getChildCount() - 1)));
return infixExpression;
}
}
if (hasTerminalNode(context, JavaParser.INSTANCEOF)) {
InstanceOf instanceOf = createNode(context, InstanceOf.class);
ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
if (expressionContext != null) {
instanceOf.setExpression(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
}
TypeContext typeContext = getChild(context, TypeContext.class);
if (typeContext != null) {
instanceOf.setType(getAdapter(TypeAdapter.class).adapt(typeContext));
}
return instanceOf;