use of org.eclipse.jdt.internal.compiler.ast.Literal in project lombok by rzwitserloot.
the class EclipseHandlerUtil method copyAnnotationMemberValue0.
private static Expression copyAnnotationMemberValue0(Expression in) {
int s = in.sourceStart, e = in.sourceEnd;
if (in instanceof FalseLiteral)
return new FalseLiteral(s, e);
if (in instanceof TrueLiteral)
return new TrueLiteral(s, e);
if (in instanceof NullLiteral)
return new NullLiteral(s, e);
if (in instanceof CharLiteral)
return new CharLiteral(((Literal) in).source(), s, e);
if (in instanceof DoubleLiteral)
return new DoubleLiteral(((Literal) in).source(), s, e);
if (in instanceof FloatLiteral)
return new FloatLiteral(((Literal) in).source(), s, e);
if (in instanceof IntLiteral)
return IntLiteral.buildIntLiteral(((Literal) in).source(), s, e);
if (in instanceof LongLiteral)
return LongLiteral.buildLongLiteral(((Literal) in).source(), s, e);
if (in instanceof StringLiteral)
return new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
if (in instanceof ExtendedStringLiteral) {
StringLiteral str = new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
StringLiteral empty = new StringLiteral(new char[0], s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
return new ExtendedStringLiteral(str, empty);
}
if (in instanceof StringLiteralConcatenation) {
Expression[] literals = ((StringLiteralConcatenation) in).literals;
// 0 and 1 len shouldn't happen.
if (literals.length == 0)
return new StringLiteral(new char[0], s, e, 0);
if (literals.length == 1)
return copyAnnotationMemberValue0(literals[0]);
StringLiteralConcatenation c = new StringLiteralConcatenation((StringLiteral) literals[0], (StringLiteral) literals[1]);
for (int i = 2; i < literals.length; i++) c = c.extendsWith((StringLiteral) literals[i]);
return c;
}
if (in instanceof SingleNameReference) {
SingleNameReference snr = (SingleNameReference) in;
return new SingleNameReference(snr.token, pos(in));
}
if (in instanceof QualifiedNameReference) {
QualifiedNameReference qnr = (QualifiedNameReference) in;
return new QualifiedNameReference(qnr.tokens, poss(in, qnr.tokens.length), s, e);
}
// class refs
if (in instanceof ClassLiteralAccess)
return new ClassLiteralAccess(e, copyType(((ClassLiteralAccess) in).type));
// arrays
if (in instanceof ArrayInitializer) {
ArrayInitializer out = new ArrayInitializer();
out.sourceStart = s;
out.sourceEnd = e;
out.bits = in.bits;
out.implicitConversion = in.implicitConversion;
out.statementEnd = e;
Expression[] exprs = ((ArrayInitializer) in).expressions;
if (exprs != null) {
Expression[] copy = new Expression[exprs.length];
for (int i = 0; i < exprs.length; i++) copy[i] = copyAnnotationMemberValue(exprs[i]);
out.expressions = copy;
}
return out;
}
if (in instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) in;
BinaryExpression out = new BinaryExpression(be);
out.left = copyAnnotationMemberValue(be.left);
out.right = copyAnnotationMemberValue(be.right);
out.sourceStart = s;
out.sourceEnd = e;
out.statementEnd = e;
return out;
}
return in;
}
use of org.eclipse.jdt.internal.compiler.ast.Literal in project bazel-jdt-java-toolchain by salesforce.
the class ProblemReporter method expressionNonNullComparison.
/**
* @param expr expression being compared for null or nonnull
* @param checkForNull true if checking for null, false if checking for nonnull
*/
public boolean expressionNonNullComparison(Expression expr, boolean checkForNull) {
int problemId = 0;
Binding binding = null;
String[] arguments = null;
int start = 0, end = 0;
Expression location = expr;
if (expr.resolvedType != null) {
long tagBits = expr.resolvedType.tagBits & TagBits.AnnotationNullMASK;
if (tagBits == TagBits.AnnotationNonNull) {
problemId = IProblem.RedundantNullCheckAgainstNonNullType;
arguments = new String[] { String.valueOf(expr.resolvedType.nullAnnotatedReadableName(this.options, true)) };
start = nodeSourceStart(location);
end = nodeSourceEnd(location);
handle(problemId, arguments, arguments, start, end);
return true;
}
}
// unwrap uninteresting nodes:
while (true) {
if (expr instanceof Assignment)
// don't report against the assignment, but the variable
return false;
else if (expr instanceof CastExpression)
expr = ((CastExpression) expr).expression;
else
break;
}
// check all those kinds of expressions that can possible answer NON_NULL from nullStatus():
if (expr instanceof MessageSend) {
problemId = checkForNull ? IProblem.NonNullMessageSendComparisonYieldsFalse : IProblem.RedundantNullCheckOnNonNullMessageSend;
MethodBinding method = ((MessageSend) expr).binding;
binding = method;
arguments = new String[] { new String(method.shortReadableName()) };
start = location.sourceStart;
end = location.sourceEnd;
} else if (expr instanceof Reference && !(expr instanceof ThisReference) && !(expr instanceof ArrayReference)) {
FieldBinding field = ((Reference) expr).lastFieldBinding();
if (field == null) {
return false;
}
if (field.isNonNull()) {
problemId = checkForNull ? IProblem.NonNullSpecdFieldComparisonYieldsFalse : IProblem.RedundantNullCheckOnNonNullSpecdField;
char[][] nonNullName = this.options.nonNullAnnotationName;
arguments = new String[] { new String(field.name), new String(nonNullName[nonNullName.length - 1]) };
} else if (field.constant() != Constant.NotAConstant) {
problemId = checkForNull ? IProblem.ConstNonNullFieldComparisonYieldsFalse : IProblem.RedundantNullCheckOnConstNonNullField;
char[][] nonNullName = this.options.nonNullAnnotationName;
arguments = new String[] { new String(field.name), new String(nonNullName[nonNullName.length - 1]) };
} else {
// signaling redundancy based on syntactic analysis:
problemId = checkForNull ? IProblem.FieldComparisonYieldsFalse : IProblem.RedundantNullCheckOnField;
arguments = new String[] { String.valueOf(field.name) };
}
binding = field;
start = nodeSourceStart(binding, location);
end = nodeSourceEnd(binding, location);
} else if (expr instanceof AllocationExpression || expr instanceof ArrayAllocationExpression || expr instanceof ArrayInitializer || expr instanceof ClassLiteralAccess || expr instanceof ThisReference) {
// fall through to bottom
} else if (expr instanceof Literal || expr instanceof ConditionalExpression || expr instanceof SwitchExpression) {
if (expr instanceof NullLiteral) {
// reported as nonnull??
needImplementation(location);
return false;
}
if (expr.resolvedType != null && expr.resolvedType.isBaseType()) {
// false alarm, auto(un)boxing is involved
return false;
}
// fall through to bottom
} else if (expr instanceof BinaryExpression) {
if ((expr.bits & ASTNode.ReturnTypeIDMASK) != TypeIds.T_JavaLangString) {
// false alarm, primitive types involved, must be auto(un)boxing?
return false;
}
// fall through to bottom
} else {
// want to see if we get here
needImplementation(expr);
return false;
}
if (problemId == 0) {
// standard case, fill in details now
problemId = checkForNull ? IProblem.NonNullExpressionComparisonYieldsFalse : IProblem.RedundantNullCheckOnNonNullExpression;
start = location.sourceStart;
end = location.sourceEnd;
arguments = NoArgument;
}
this.handle(problemId, arguments, arguments, start, end);
return true;
}
use of org.eclipse.jdt.internal.compiler.ast.Literal in project lombok by projectlombok.
the class EclipseHandlerUtil method copyAnnotationMemberValue0.
private static Expression copyAnnotationMemberValue0(Expression in) {
int s = in.sourceStart, e = in.sourceEnd;
if (in instanceof FalseLiteral)
return new FalseLiteral(s, e);
if (in instanceof TrueLiteral)
return new TrueLiteral(s, e);
if (in instanceof NullLiteral)
return new NullLiteral(s, e);
if (in instanceof CharLiteral)
return new CharLiteral(((Literal) in).source(), s, e);
if (in instanceof DoubleLiteral)
return new DoubleLiteral(((Literal) in).source(), s, e);
if (in instanceof FloatLiteral)
return new FloatLiteral(((Literal) in).source(), s, e);
if (in instanceof IntLiteral)
return IntLiteral.buildIntLiteral(((Literal) in).source(), s, e);
if (in instanceof LongLiteral)
return LongLiteral.buildLongLiteral(((Literal) in).source(), s, e);
if (in instanceof StringLiteral)
return new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
if (in instanceof ExtendedStringLiteral) {
StringLiteral str = new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
StringLiteral empty = new StringLiteral(new char[0], s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1);
return new ExtendedStringLiteral(str, empty);
}
if (in instanceof StringLiteralConcatenation) {
Expression[] literals = ((StringLiteralConcatenation) in).literals;
// 0 and 1 len shouldn't happen.
if (literals.length == 0)
return new StringLiteral(new char[0], s, e, 0);
if (literals.length == 1)
return copyAnnotationMemberValue0(literals[0]);
StringLiteralConcatenation c = new StringLiteralConcatenation((StringLiteral) literals[0], (StringLiteral) literals[1]);
for (int i = 2; i < literals.length; i++) c = c.extendsWith((StringLiteral) literals[i]);
return c;
}
if (in instanceof SingleNameReference) {
SingleNameReference snr = (SingleNameReference) in;
return new SingleNameReference(snr.token, pos(in));
}
if (in instanceof QualifiedNameReference) {
QualifiedNameReference qnr = (QualifiedNameReference) in;
return new QualifiedNameReference(qnr.tokens, poss(in, qnr.tokens.length), s, e);
}
// class refs
if (in instanceof ClassLiteralAccess)
return new ClassLiteralAccess(e, copyType(((ClassLiteralAccess) in).type));
// arrays
if (in instanceof ArrayInitializer) {
ArrayInitializer out = new ArrayInitializer();
out.sourceStart = s;
out.sourceEnd = e;
out.bits = in.bits;
out.implicitConversion = in.implicitConversion;
out.statementEnd = e;
Expression[] exprs = ((ArrayInitializer) in).expressions;
if (exprs != null) {
Expression[] copy = new Expression[exprs.length];
for (int i = 0; i < exprs.length; i++) copy[i] = copyAnnotationMemberValue(exprs[i]);
out.expressions = copy;
}
return out;
}
if (in instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) in;
BinaryExpression out = new BinaryExpression(be);
out.left = copyAnnotationMemberValue(be.left);
out.right = copyAnnotationMemberValue(be.right);
out.sourceStart = s;
out.sourceEnd = e;
out.statementEnd = e;
return out;
}
return in;
}
Aggregations