KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > PostfixExpression


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.*;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16
17 public class PostfixExpression extends CompoundAssignment {
18
19 public PostfixExpression(Expression lhs, Expression expression, int operator, int pos) {
20     super(lhs, expression, operator, pos);
21     this.sourceStart = lhs.sourceStart;
22     this.sourceEnd = pos;
23 }
24
25 /**
26  * Code generation for PostfixExpression
27  *
28  * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
29  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
30  * @param valueRequired boolean
31  */

32 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
33     // various scenarii are possible, setting an array reference,
34
// a field reference, a blank final field reference, a field of an enclosing instance or
35
// just a local variable.
36

37     int pc = codeStream.position;
38      ((Reference) this.lhs).generatePostIncrement(currentScope, codeStream, this, valueRequired);
39     if (valueRequired) {
40         codeStream.generateImplicitConversion(this.implicitConversion);
41     }
42     codeStream.recordPositionsFrom(pc, this.sourceStart);
43 }
44
45 public String JavaDoc operatorToString() {
46     switch (this.operator) {
47         case PLUS :
48             return "++"; //$NON-NLS-1$
49
case MINUS :
50             return "--"; //$NON-NLS-1$
51
}
52     return "unknown operator"; //$NON-NLS-1$
53
}
54
55 public StringBuffer JavaDoc printExpressionNoParenthesis(int indent, StringBuffer JavaDoc output) {
56     return this.lhs.printExpression(indent, output).append(' ').append(operatorToString());
57 }
58
59 public boolean restrainUsageToNumericTypes() {
60     return true;
61 }
62
63 public void traverse(ASTVisitor visitor, BlockScope scope) {
64
65     if (visitor.visit(this, scope)) {
66         this.lhs.traverse(visitor, scope);
67     }
68     visitor.endVisit(this, scope);
69 }
70 }
71
Popular Tags