/** Give 2 clones! */ public Expression longToIntForHashCode(Expression ref1, Expression ref2, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; /* (int)(ref >>> 32 ^ ref) */ IntLiteral int32 = makeIntLiteral("32".toCharArray(), source); BinaryExpression higherBits = new BinaryExpression(ref1, int32, OperatorIds.UNSIGNED_RIGHT_SHIFT); setGeneratedBy(higherBits, source); BinaryExpression xorParts = new BinaryExpression(ref2, higherBits, OperatorIds.XOR); setGeneratedBy(xorParts, source); TypeReference intRef = TypeReference.baseTypeReference(TypeIds.T_int, 0); intRef.sourceStart = pS; intRef.sourceEnd = pE; setGeneratedBy(intRef, source); CastExpression expr = makeCastExpression(xorParts, intRef, source); expr.sourceStart = pS; expr.sourceEnd = pE; return expr; }
/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.CastExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit(CastExpression castExpression, BlockScope scope) { final int numberOfParens = (castExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(castExpression, numberOfParens); } this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN); if (this.preferences.insert_space_after_opening_paren_in_cast) { this.scribe.space(); } castExpression.type.traverse(this, scope); this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_cast); if (this.preferences.insert_space_after_closing_paren_in_cast) { this.scribe.space(); } castExpression.expression.traverse(this, scope); if (numberOfParens > 0) { manageClosingParenthesizedExpression(castExpression, numberOfParens); } return false; }
protected void consumeCastExpressionLL1() { //CastExpression ::= '(' Name ')' InsideCastExpressionLL1 UnaryExpressionNotPlusMinus //optimize push/pop Expression cast; Expression exp; this.expressionPtr--; this.expressionStack[this.expressionPtr] = cast = new CastExpression( exp=this.expressionStack[this.expressionPtr+1] , (TypeReference) this.expressionStack[this.expressionPtr]); this.expressionLengthPtr -- ; updateSourcePosition(cast); cast.sourceEnd=exp.sourceEnd; }
protected void consumeCastExpressionLL1WithBounds() { //CastExpression ::= '(' Name AdditionalBoundsList ')' UnaryExpressionNotPlusMinus Expression cast; Expression exp; int length; exp = this.expressionStack[this.expressionPtr--]; this.expressionLengthPtr --; TypeReference[] bounds = new TypeReference[length = this.expressionLengthStack[this.expressionLengthPtr]]; System.arraycopy(this.expressionStack, this.expressionPtr -= (length - 1), bounds, 0, length); this.expressionStack[this.expressionPtr] = cast = new CastExpression( exp, createIntersectionCastTypeReference(bounds)); this.expressionLengthStack[this.expressionLengthPtr] = 1; updateSourcePosition(cast); cast.sourceEnd=exp.sourceEnd; }
public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) { String leftName = new String(leftType.readableName()); String rightName = new String(rightType.readableName()); String leftShortName = new String(leftType.shortReadableName()); String rightShortName = new String(rightType.shortReadableName()); if (leftShortName.equals(rightShortName)){ leftShortName = leftName; rightShortName = rightName; } this.handle( IProblem.IllegalCast, new String[] { rightName, leftName }, new String[] { rightShortName, leftShortName }, expression.sourceStart, expression.sourceEnd); }
public void unsafeCast(CastExpression castExpression, Scope scope) { if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 int severity = computeSeverity(IProblem.UnsafeGenericCast); if (severity == ProblemSeverities.Ignore) return; TypeBinding castedExpressionType = castExpression.expression.resolvedType; TypeBinding castExpressionResolvedType = castExpression.resolvedType; this.handle( IProblem.UnsafeGenericCast, new String[]{ new String(castedExpressionType.readableName()), new String(castExpressionResolvedType.readableName()) }, new String[]{ new String(castedExpressionType.shortReadableName()), new String(castExpressionResolvedType.shortReadableName()) }, severity, castExpression.sourceStart, castExpression.sourceEnd); }
public void unsafeNullnessCast(CastExpression castExpression, Scope scope) { TypeBinding castedExpressionType = castExpression.expression.resolvedType; TypeBinding castExpressionResolvedType = castExpression.resolvedType; this.handle( IProblem.UnsafeNullnessCast, new String[]{ new String(castedExpressionType.nullAnnotatedReadableName(this.options, false)), new String(castExpressionResolvedType.nullAnnotatedReadableName(this.options, false)) }, new String[]{ new String(castedExpressionType.nullAnnotatedReadableName(this.options, true)), new String(castExpressionResolvedType.nullAnnotatedReadableName(this.options, true)) }, castExpression.sourceStart, castExpression.sourceEnd); }
/** Give 2 clones! */ private Expression longToIntForHashCode(Expression ref1, Expression ref2, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; /* (int)(ref >>> 32 ^ ref) */ IntLiteral int32 = makeIntLiteral("32".toCharArray(), source); BinaryExpression higherBits = new BinaryExpression(ref1, int32, OperatorIds.UNSIGNED_RIGHT_SHIFT); setGeneratedBy(higherBits, source); BinaryExpression xorParts = new BinaryExpression(ref2, higherBits, OperatorIds.XOR); setGeneratedBy(xorParts, source); TypeReference intRef = TypeReference.baseTypeReference(TypeIds.T_int, 0); intRef.sourceStart = pS; intRef.sourceEnd = pE; setGeneratedBy(intRef, source); CastExpression expr = makeCastExpression(xorParts, intRef, source); expr.sourceStart = pS; expr.sourceEnd = pE; return expr; }
private void doAssignmentCheck0(EclipseNode node, Statement statement, char[] varName) { if (statement instanceof Assignment) doAssignmentCheck0(node, ((Assignment)statement).expression, varName); else if (statement instanceof LocalDeclaration) doAssignmentCheck0(node, ((LocalDeclaration)statement).initialization, varName); else if (statement instanceof CastExpression) doAssignmentCheck0(node, ((CastExpression)statement).expression, varName); else if (statement instanceof SingleNameReference) { if (Arrays.equals(((SingleNameReference)statement).token, varName)) { EclipseNode problemNode = node.getNodeFor(statement); if (problemNode != null) problemNode.addWarning( "You're assigning an auto-cleanup variable to something else. This is a bad idea."); } } }
protected void consumeCastExpressionWithGenericsArray() { // CastExpression ::= PushLPAREN Name TypeArguments Dimsopt AdditionalBoundsListOpt PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus TypeReference[] bounds = null; int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--]; if (additionalBoundsLength > 0) { bounds = new TypeReference[additionalBoundsLength + 1]; this.genericsPtr -= additionalBoundsLength; System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 1, additionalBoundsLength); } Expression exp; Expression cast; TypeReference castType; int end = this.intStack[this.intPtr--]; int dim = this.intStack[this.intPtr--]; pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]); if (additionalBoundsLength > 0) { bounds[0] = getTypeReference(dim); castType = createIntersectionCastTypeReference(bounds); } else { castType = getTypeReference(dim); } this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType); this.intPtr--; // pop position of '<' castType.sourceEnd = end - 1; castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1; cast.sourceEnd = exp.sourceEnd; }
protected void consumeCastExpressionWithNameArray() { // CastExpression ::= PushLPAREN Name Dims AdditionalBoundsListOpt PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus Expression exp; Expression cast; TypeReference castType; int end = this.intStack[this.intPtr--]; TypeReference[] bounds = null; int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--]; if (additionalBoundsLength > 0) { bounds = new TypeReference[additionalBoundsLength + 1]; this.genericsPtr -= additionalBoundsLength; System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 1, additionalBoundsLength); } // handle type arguments pushOnGenericsLengthStack(0); pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]); if (additionalBoundsLength > 0) { bounds[0] = getTypeReference(this.intStack[this.intPtr--]); castType = createIntersectionCastTypeReference(bounds); } else { castType = getTypeReference(this.intStack[this.intPtr--]); } this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType); castType.sourceEnd = end - 1; castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1; cast.sourceEnd = exp.sourceEnd; }
protected void consumeCastExpressionWithPrimitiveType() { // CastExpression ::= PushLPAREN PrimitiveType Dimsopt AdditionalBoundsListOpt PushRPAREN InsideCastExpression UnaryExpression //this.intStack : posOfLeftParen dim posOfRightParen TypeReference[] bounds = null; int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--]; if (additionalBoundsLength > 0) { bounds = new TypeReference[additionalBoundsLength + 1]; this.genericsPtr -= additionalBoundsLength; System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 1, additionalBoundsLength); } //optimize the push/pop Expression exp; Expression cast; TypeReference castType; int end = this.intStack[this.intPtr--]; if (additionalBoundsLength > 0) { bounds[0] = getTypeReference(this.intStack[this.intPtr--]); castType = createIntersectionCastTypeReference(bounds); } else { castType = getTypeReference(this.intStack[this.intPtr--]); } this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType); castType.sourceEnd = end - 1; castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1; cast.sourceEnd = exp.sourceEnd; }
protected void consumeCastExpressionWithQualifiedGenericsArray() { // CastExpression ::= PushLPAREN Name OnlyTypeArguments '.' ClassOrInterfaceType Dimsopt AdditionalBoundsOpt PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus TypeReference[] bounds = null; int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--]; if (additionalBoundsLength > 0) { bounds = new TypeReference[additionalBoundsLength + 1]; this.genericsPtr -= additionalBoundsLength; System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 1, additionalBoundsLength); } Expression exp; Expression cast; TypeReference castType; int end = this.intStack[this.intPtr--]; int dim = this.intStack[this.intPtr--]; Annotation [][] annotationsOnDimensions = dim == 0 ? null : getAnnotationsOnDimensions(dim); TypeReference rightSide = getTypeReference(0); castType = computeQualifiedGenericsFromRightSide(rightSide, dim, annotationsOnDimensions); if (additionalBoundsLength > 0) { bounds[0] = castType; castType = createIntersectionCastTypeReference(bounds); } this.intPtr--; this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType); castType.sourceEnd = end - 1; castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1; cast.sourceEnd = exp.sourceEnd; }
public void unnecessaryCast(CastExpression castExpression) { if (castExpression.expression instanceof FunctionalExpression) return; int severity = computeSeverity(IProblem.UnnecessaryCast); if (severity == ProblemSeverities.Ignore) return; TypeBinding castedExpressionType = castExpression.expression.resolvedType; this.handle( IProblem.UnnecessaryCast, new String[]{ new String(castedExpressionType.readableName()), new String(castExpression.type.resolvedType.readableName())}, new String[]{ new String(castedExpressionType.shortReadableName()), new String(castExpression.type.resolvedType.shortReadableName())}, severity, castExpression.sourceStart, castExpression.sourceEnd); }
public void unnecessaryCast(CastExpression castExpression) { int severity = computeSeverity(IProblem.UnnecessaryCast); if (severity == ProblemSeverities.Ignore) return; TypeBinding castedExpressionType = castExpression.expression.resolvedType; this.handle( IProblem.UnnecessaryCast, new String[]{ new String(castedExpressionType.readableName()), new String(castExpression.type.resolvedType.readableName())}, new String[]{ new String(castedExpressionType.shortReadableName()), new String(castExpression.type.resolvedType.shortReadableName())}, severity, castExpression.sourceStart, castExpression.sourceEnd); }
@Override public void endVisit(CastExpression x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JType type = typeMap.get(x.resolvedType); JExpression expression = pop(x.expression); if (x.type instanceof NameReference) { pop(x.type); } push(new JCastOperation(info, type, expression)); } catch (Throwable e) { throw translateException(x, e); } }
@Override public boolean visit(CastExpression node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
private void buildMoreCompletionContext(Expression expression) { ASTNode parentNode = null; int kind = topKnownElementKind(SELECTION_OR_ASSIST_PARSER); if(kind != 0) { int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER); nextElement : switch (kind) { case K_BETWEEN_CASE_AND_COLON : if(this.expressionPtr > 0) { SwitchStatement switchStatement = new SwitchStatement(); switchStatement.expression = this.expressionStack[this.expressionPtr - 1]; if(this.astLengthPtr > -1 && this.astPtr > -1) { int length = this.astLengthStack[this.astLengthPtr]; int newAstPtr = this.astPtr - length; ASTNode firstNode = this.astStack[newAstPtr + 1]; if(length != 0 && firstNode.sourceStart > switchStatement.expression.sourceEnd) { switchStatement.statements = new Statement[length + 1]; System.arraycopy( this.astStack, newAstPtr + 1, switchStatement.statements, 0, length); } } CaseStatement caseStatement = new CaseStatement(expression, expression.sourceStart, expression.sourceEnd); if(switchStatement.statements == null) { switchStatement.statements = new Statement[]{caseStatement}; } else { switchStatement.statements[switchStatement.statements.length - 1] = caseStatement; } parentNode = switchStatement; this.assistNodeParent = parentNode; } break nextElement; case K_INSIDE_RETURN_STATEMENT : if(info == this.bracketDepth) { ReturnStatement returnStatement = new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd); parentNode = returnStatement; this.assistNodeParent = parentNode; } break nextElement; case K_CAST_STATEMENT : Expression castType; if(this.expressionPtr > 0 && ((castType = this.expressionStack[this.expressionPtr-1]) instanceof TypeReference)) { CastExpression cast = new CastExpression(expression, (TypeReference) castType); cast.sourceStart = castType.sourceStart; cast.sourceEnd= expression.sourceEnd; parentNode = cast; this.assistNodeParent = parentNode; } break nextElement; } } // Do not add assist node/parent into the recovery system if we are inside a lambda. The lambda will be fully recovered including the containing statement and added. if (lastIndexOfElement(K_LAMBDA_EXPRESSION_DELIMITER) < 0) { if(parentNode != null) { this.currentElement = this.currentElement.add((Statement)parentNode, 0); } else { this.currentElement = this.currentElement.add((Statement)wrapWithExplicitConstructorCallIfNeeded(expression), 0); if(this.lastCheckPoint < expression.sourceEnd) { this.lastCheckPoint = expression.sourceEnd + 1; } } } }
public boolean visit(CastExpression castExpression, BlockScope scope) { addRealFragment(castExpression); return false; }
@Override public boolean visit(CastExpression node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetExpression(node); return super.visit(node, scope); }