Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1663,18 +1663,22 @@ public Void visitMemberSelect(MemberSelectTree node, Void unused) {
public Void visitLiteral(LiteralTree node, Void unused) {
sync(node);
String sourceForNode = getSourceForNode(node, getCurrentPath());
// A negative numeric literal -n is usually represented as unary minus on n,
// but that doesn't work for integer or long MIN_VALUE. The parser works
// around that by representing it directly as a signed literal (with no
// unary minus), but the lexer still expects two tokens.
if (sourceForNode.startsWith("-")) {
if (isUnaryMinusLiteral(sourceForNode)) {
token("-");
sourceForNode = sourceForNode.substring(1).trim();
}
token(sourceForNode);
return null;
}

// A negative numeric literal -n is usually represented as unary minus on n,
// but that doesn't work for integer or long MIN_VALUE. The parser works
// around that by representing it directly as a signed literal (with no
// unary minus), but the lexer still expects two tokens.
private static boolean isUnaryMinusLiteral(String literalTreeSource) {
return literalTreeSource.startsWith("-");
}

private void visitPackage(ExpressionTree packageName, List<? extends AnnotationTree> packageAnnotations) {
if (!packageAnnotations.isEmpty()) {
for (AnnotationTree annotation : packageAnnotations) {
Expand Down Expand Up @@ -1759,10 +1763,10 @@ private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) {
default:
return false;
}
if (!(node.getExpression() instanceof UnaryTree)) {
JCTree.Tag tag = unaryTag(node.getExpression());
if (tag == null) {
return false;
}
JCTree.Tag tag = ((JCTree) node.getExpression()).getTag();
if (tag.isPostUnaryOp()) {
return false;
}
Expand All @@ -1772,6 +1776,17 @@ private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) {
return true;
}

private JCTree.Tag unaryTag(ExpressionTree expression) {
if (expression instanceof UnaryTree) {
return ((JCTree) expression).getTag();
}
if (expression instanceof LiteralTree
&& isUnaryMinusLiteral(getSourceForNode(expression, getCurrentPath()))) {
return JCTree.Tag.MINUS;
}
return null;
}

@Override
public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) {
sync(node);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class B183431894 {
int a = - -1;
int d = + +1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class B183431894 {
int a = - -1;
int d = + +1;
}
Loading