diff options
Diffstat (limited to 'org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java')
-rw-r--r-- | org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java | 2926 |
1 files changed, 1664 insertions, 1262 deletions
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java index 92f63b3c3..e7b89d65d 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTInstructionCompiler.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -191,26 +190,25 @@ import org.eclipse.jdt.internal.debug.eval.ast.instructions.XorOperator; import com.ibm.icu.text.MessageFormat; /** - * The AST instruction compiler generates a sequence - * of instructions (InstructionSequence) from a - * DOM AST. + * The AST instruction compiler generates a sequence of instructions + * (InstructionSequence) from a DOM AST. */ public class ASTInstructionCompiler extends ASTVisitor { /** - * Represent a break or a continue instruction. - * These instructions needs are stored and managed later by their - * related statement. + * Represent a break or a continue instruction. These instructions needs are + * stored and managed later by their related statement. */ class CompleteInstruction { Jump fInstruction; String fLabel; boolean fIsBreak; - public CompleteInstruction(Jump instruction, String label, boolean isBreak) { - fInstruction= instruction; - fLabel= label; - fIsBreak= isBreak; + public CompleteInstruction(Jump instruction, String label, + boolean isBreak) { + fInstruction = instruction; + fLabel = label; + fIsBreak = isBreak; } } @@ -224,7 +222,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * The list of pending break and continue instruction. */ - private List fCompleteInstructions; + private List<CompleteInstruction> fCompleteInstructions; private int fStartPosition; @@ -232,13 +230,12 @@ public class ASTInstructionCompiler extends ASTVisitor { private boolean fHasErrors; - private Stack fStack; + private Stack<Instruction> fStack; private int fCounter; - - // internal index used to create unique variable name - private int fUniqueIdIndex= 0; + // internal index used to create unique variable name + private int fUniqueIdIndex = 0; /** * Create a new AST instruction compiler @@ -246,27 +243,26 @@ public class ASTInstructionCompiler extends ASTVisitor { public ASTInstructionCompiler(int startPosition, String snippet) { fStartPosition = startPosition; fInstructions = new InstructionSequence(snippet); - fStack = new Stack(); - fCompleteInstructions= new ArrayList(); + fStack = new Stack<Instruction>(); + fCompleteInstructions = new ArrayList<CompleteInstruction>(); } /** - * Returns the instruction sequence generated - * by this AST instruction compiler + * Returns the instruction sequence generated by this AST instruction + * compiler */ public InstructionSequence getInstructions() { return fInstructions; } /** - * Returns whether the generated instruction sequence - * has errors. - * Errors include: + * Returns whether the generated instruction sequence has errors. Errors + * include: * <ol> - * <li>AST contains unimplemented operations (features which will be supported, - * but aren't yet)</li> - * <li>AST contains unsupported operations (features which are not yet implemented - * and are likely NOT to be implemented)</li> + * <li>AST contains unimplemented operations (features which will be + * supported, but aren't yet)</li> + * <li>AST contains unsupported operations (features which are not yet + * implemented and are likely NOT to be implemented)</li> * </ol> */ public boolean hasErrors() { @@ -274,7 +270,7 @@ public class ASTInstructionCompiler extends ASTVisitor { } private void setHasError(boolean value) { - fHasErrors= value; + fHasErrors = value; } private void addErrorMessage(String message) { @@ -289,31 +285,29 @@ public class ASTInstructionCompiler extends ASTVisitor { fActive = active; } - private void push(Instruction i) { fStack.push(i); } private Instruction pop() { - return (Instruction)fStack.pop(); + return fStack.pop(); } private void storeInstruction() { - Instruction instruction= pop(); + Instruction instruction = pop(); fCounter++; if (instruction instanceof CompoundInstruction) { - ((CompoundInstruction)instruction).setEnd(fCounter); + ((CompoundInstruction) instruction).setEnd(fCounter); } fInstructions.add(instruction); verbose("Add " + instruction.toString()); //$NON-NLS-1$ } - /** - * Prints the given message to the console if verbose - * mode is on. - * - * @param message the message to display + * Prints the given message to the console if verbose mode is on. + * + * @param message + * the message to display */ private void verbose(String message) { if (VERBOSE) { @@ -323,12 +317,12 @@ public class ASTInstructionCompiler extends ASTVisitor { private String getTypeName(ITypeBinding typeBinding) { if (typeBinding.isRawType()) { - typeBinding= typeBinding.getErasure(); + typeBinding = typeBinding.getErasure(); } if (typeBinding.isTypeVariable()) { - ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); + ITypeBinding[] typeBounds = typeBinding.getTypeBounds(); if (typeBounds.length > 0) { - String name= getTypeName(typeBounds[0]); + String name = getTypeName(typeBounds[0]); if (typeBounds.length > 1 && "java.lang.Object".equals(name)) { //$NON-NLS-1$ return getTypeName(typeBounds[1]); } @@ -338,24 +332,24 @@ public class ASTInstructionCompiler extends ASTVisitor { } StringBuffer name; if (typeBinding.isArray()) { - name= new StringBuffer(getTypeName(typeBinding.getElementType())); - int dimensions= typeBinding.getDimensions(); - for (int i= 0; i < dimensions; i++) { + name = new StringBuffer(getTypeName(typeBinding.getElementType())); + int dimensions = typeBinding.getDimensions(); + for (int i = 0; i < dimensions; i++) { name.append("[]"); //$NON-NLS-1$ } return name.toString(); } - String typeName= typeBinding.getName(); - int parameters= typeName.indexOf('<'); + String typeName = typeBinding.getName(); + int parameters = typeName.indexOf('<'); if (parameters >= 0) { - typeName= typeName.substring(0, parameters); + typeName = typeName.substring(0, parameters); } - name= new StringBuffer(typeName); - IPackageBinding packageBinding= typeBinding.getPackage(); - typeBinding= typeBinding.getDeclaringClass(); - while(typeBinding != null) { + name = new StringBuffer(typeName); + IPackageBinding packageBinding = typeBinding.getPackage(); + typeBinding = typeBinding.getDeclaringClass(); + while (typeBinding != null) { name.insert(0, '$').insert(0, typeBinding.getName()); - typeBinding= typeBinding.getDeclaringClass(); + typeBinding = typeBinding.getDeclaringClass(); } if (packageBinding != null && !packageBinding.isUnnamed()) { name.insert(0, '.').insert(0, packageBinding.getName()); @@ -364,46 +358,52 @@ public class ASTInstructionCompiler extends ASTVisitor { } private String getTypeSignature(ITypeBinding typeBinding) { - return Signature.createTypeSignature(getTypeName(typeBinding), true).replace('.', '/'); + return Signature.createTypeSignature(getTypeName(typeBinding), true) + .replace('.', '/'); } private boolean isALocalType(ITypeBinding typeBinding) { - while(typeBinding != null) { + while (typeBinding != null) { if (typeBinding.isLocal()) { return true; } - typeBinding= typeBinding.getDeclaringClass(); + typeBinding = typeBinding.getDeclaringClass(); } return false; } private boolean containsALocalType(IMethodBinding methodBinding) { - ITypeBinding[] typeBindings= methodBinding.getParameterTypes(); - for (int i= 0, length= typeBindings.length; i < length; i++) { - if (isALocalType(typeBindings[i])) { + ITypeBinding[] typeBindings = methodBinding.getParameterTypes(); + for (ITypeBinding typeBinding : typeBindings) { + if (isALocalType(typeBinding)) { return true; } } return false; } - private int getEnclosingLevel(ASTNode node, ITypeBinding referenceTypeBinding) { + private int getEnclosingLevel(ASTNode node, + ITypeBinding referenceTypeBinding) { ASTNode parent = node; - ITypeBinding refbinding = referenceTypeBinding.isParameterizedType() ? referenceTypeBinding.getTypeDeclaration() : referenceTypeBinding; + ITypeBinding refbinding = referenceTypeBinding.isParameterizedType() ? referenceTypeBinding + .getTypeDeclaration() : referenceTypeBinding; do { parent = parent.getParent(); - } while (parent != null && !(parent instanceof AbstractTypeDeclaration || parent instanceof AnonymousClassDeclaration)); - if(parent == null) { + } while (parent != null + && !(parent instanceof AbstractTypeDeclaration || parent instanceof AnonymousClassDeclaration)); + if (parent == null) { return 0; } ITypeBinding parentBinding = null; - if(parent instanceof AbstractTypeDeclaration) { - parentBinding = ((AbstractTypeDeclaration)parent).resolveBinding(); - } - else if(parent instanceof AnonymousClassDeclaration) { - parentBinding = ((AnonymousClassDeclaration)parent).resolveBinding(); - } - if (parentBinding != null && (parentBinding.isEqualTo(refbinding) || parentBinding.isCastCompatible(refbinding))) { + if (parent instanceof AbstractTypeDeclaration) { + parentBinding = ((AbstractTypeDeclaration) parent).resolveBinding(); + } else if (parent instanceof AnonymousClassDeclaration) { + parentBinding = ((AnonymousClassDeclaration) parent) + .resolveBinding(); + } + if (parentBinding != null + && (parentBinding.isEqualTo(refbinding) || parentBinding + .isCastCompatible(refbinding))) { return 0; } return getEnclosingLevel(parent, referenceTypeBinding) + 1; @@ -418,41 +418,47 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * Return the label associated with the given statement. - * - * @param statement the statement. + * + * @param statement + * the statement. * @return the associated label, or <code>null</code> if there is none. */ private String getLabel(Statement statement) { - ASTNode parent= statement.getParent(); + ASTNode parent = statement.getParent(); if (parent instanceof LabeledStatement) { - return ((LabeledStatement)parent).getLabel().getIdentifier(); + return ((LabeledStatement) parent).getLabel().getIdentifier(); } return null; } /** - * Append a pop instruction in the instruction list if needed. - * A pop instruction is added when the expression has a return value, - * i.e. all expressions expect method invocation expressions which - * have <code>void</code> as return type and variable declaration expression. - * - * @param expression the expression to test. + * Append a pop instruction in the instruction list if needed. A pop + * instruction is added when the expression has a return value, i.e. all + * expressions expect method invocation expressions which have + * <code>void</code> as return type and variable declaration expression. + * + * @param expression + * the expression to test. */ private void addPopInstructionIfNeeded(Expression expression) { - boolean pop= true; + boolean pop = true; if (expression instanceof MethodInvocation) { - IMethodBinding methodBinding= (IMethodBinding)((MethodInvocation)expression).getName().resolveBinding(); - if (methodBinding != null && "void".equals(methodBinding.getReturnType().getName())) { //$NON-NLS-1$ - pop= false; + IMethodBinding methodBinding = (IMethodBinding) ((MethodInvocation) expression) + .getName().resolveBinding(); + if (methodBinding != null + && "void".equals(methodBinding.getReturnType().getName())) { //$NON-NLS-1$ + pop = false; } } else if (expression instanceof SuperMethodInvocation) { - IMethodBinding methodBinding= (IMethodBinding)((SuperMethodInvocation)expression).getName().resolveBinding(); - if (methodBinding != null && "void".equals(methodBinding.getReturnType().getName())) { //$NON-NLS-1$ - pop= false; + IMethodBinding methodBinding = (IMethodBinding) ((SuperMethodInvocation) expression) + .getName().resolveBinding(); + if (methodBinding != null + && "void".equals(methodBinding.getReturnType().getName())) { //$NON-NLS-1$ + pop = false; } } else if (expression instanceof VariableDeclarationExpression) { - pop= false; + pop = false; } if (pop) { @@ -464,17 +470,20 @@ public class ASTInstructionCompiler extends ASTVisitor { * */ private void addPopInstruction() { - Instruction lastInstruction= fInstructions.getInstruction(fInstructions.getEnd()); + Instruction lastInstruction = fInstructions + .getInstruction(fInstructions.getEnd()); push(new Pop(lastInstruction.getSize() + 1)); storeInstruction(); } - + /** - * Check the current type of a value and the requested type to decide if boxing/un-boxing is required. - * If needed, the correct instruction is added to the stack - * Returns true if a storeInstruction() is needed after visiting the expression + * Check the current type of a value and the requested type to decide if + * boxing/un-boxing is required. If needed, the correct instruction is added + * to the stack Returns true if a storeInstruction() is needed after + * visiting the expression */ - private boolean checkAutoBoxing(ITypeBinding valueBinding, ITypeBinding requestedBinding) { + private boolean checkAutoBoxing(ITypeBinding valueBinding, + ITypeBinding requestedBinding) { if (valueBinding == null) { return false; // unresolved } @@ -493,59 +502,75 @@ public class ASTInstructionCompiler extends ASTVisitor { * Add to the stack the instruction to box a primitive value. */ private void boxing(ITypeBinding requestedBinding, ITypeBinding valueBinding) { - String requestedTypeName= requestedBinding.getQualifiedName(); + String requestedTypeName = requestedBinding.getQualifiedName(); if ("java.lang.Object".equals(requestedTypeName)) { //$NON-NLS-1$ switch (valueBinding.getBinaryName().charAt(0)) { - case 'I': - push(new SendStaticMessage("java.lang.Integer", "valueOf", "(I)Ljava/lang/Integer;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'C': - push(new SendStaticMessage("java.lang.Character", "valueOf", "(C)Ljava/lang/Character;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'B': - push(new SendStaticMessage("java.lang.Byte", "valueOf", "(B)Ljava/lang/Byte;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'S': - push(new SendStaticMessage("java.lang.Short", "valueOf", "(S)Ljava/lang/Short;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'J': - push(new SendStaticMessage("java.lang.Long", "valueOf", "(J)Ljava/lang/Long;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'F': - push(new SendStaticMessage("java.lang.Float", "valueOf", "(F)Ljava/lang/Float;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'D': - push(new SendStaticMessage("java.lang.Double", "valueOf", "(D)Ljava/lang/Double;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case 'Z': - push(new SendStaticMessage("java.lang.Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; + case 'I': + push(new SendStaticMessage( + "java.lang.Integer", "valueOf", "(I)Ljava/lang/Integer;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'C': + push(new SendStaticMessage( + "java.lang.Character", "valueOf", "(C)Ljava/lang/Character;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'B': + push(new SendStaticMessage( + "java.lang.Byte", "valueOf", "(B)Ljava/lang/Byte;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'S': + push(new SendStaticMessage( + "java.lang.Short", "valueOf", "(S)Ljava/lang/Short;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'J': + push(new SendStaticMessage( + "java.lang.Long", "valueOf", "(J)Ljava/lang/Long;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'F': + push(new SendStaticMessage( + "java.lang.Float", "valueOf", "(F)Ljava/lang/Float;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'D': + push(new SendStaticMessage( + "java.lang.Double", "valueOf", "(D)Ljava/lang/Double;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + case 'Z': + push(new SendStaticMessage( + "java.lang.Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; } } else if ("java.lang.Integer".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(I)Ljava/lang/Integer;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(I)Ljava/lang/Integer;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Character".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(C)Ljava/lang/Character;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(C)Ljava/lang/Character;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Byte".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(B)Ljava/lang/Byte;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(B)Ljava/lang/Byte;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Short".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(S)Ljava/lang/Short;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(S)Ljava/lang/Short;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Long".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(J)Ljava/lang/Long;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(J)Ljava/lang/Long;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Float".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(F)Ljava/lang/Float;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(F)Ljava/lang/Float;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Double".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(D)Ljava/lang/Double;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(D)Ljava/lang/Double;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Boolean".equals(requestedTypeName)) { //$NON-NLS-1$ - push(new SendStaticMessage(requestedTypeName, "valueOf", "(Z)Ljava/lang/Boolean;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new SendStaticMessage(requestedTypeName, + "valueOf", "(Z)Ljava/lang/Boolean;", 1, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } } /** - * Add the instruction to un-box a non-primitive value if needed. - * Returns true if a storeInstruction() is needed after visiting the expression + * Add the instruction to un-box a non-primitive value if needed. Returns + * true if a storeInstruction() is needed after visiting the expression */ private boolean unBoxing(ITypeBinding valueBinding) { - String valueTypeName= valueBinding.getQualifiedName(); + String valueTypeName = valueBinding.getQualifiedName(); if ("java.lang.Integer".equals(valueTypeName)) { //$NON-NLS-1$ push(new SendMessage("intValue", "()I", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ } else if ("java.lang.Character".equals(valueTypeName)) { //$NON-NLS-1$ @@ -570,21 +595,20 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * End visit methods - * + * * There are two paths to ending a visit to a node: * <ol> - * <li>For control statements, the necessary control - * instructions (jump, conditional jump) are inserted - * into the instruction sequence</li> - * <li>For other cases, we simply remove the node's - * instruction from the stack and add it to the - * instruction sequence.</li> + * <li>For control statements, the necessary control instructions (jump, + * conditional jump) are inserted into the instruction sequence</li> + * <li>For other cases, we simply remove the node's instruction from the + * stack and add it to the instruction sequence.</li> * </ol> */ /** * @see ASTVisitor#endVisit(AnonymousClassDeclaration) */ + @Override public void endVisit(AnonymousClassDeclaration node) { } @@ -592,6 +616,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ArrayAccess) */ + @Override public void endVisit(ArrayAccess node) { if (!isActive() || hasErrors()) return; @@ -606,6 +631,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ArrayCreation) */ + @Override public void endVisit(ArrayCreation node) { if (!isActive() || hasErrors()) return; @@ -615,6 +641,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ArrayInitializer) */ + @Override public void endVisit(ArrayInitializer node) { if (!isActive() || hasErrors()) return; @@ -624,6 +651,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ArrayType) */ + @Override public void endVisit(ArrayType node) { if (!isActive() || hasErrors()) return; @@ -633,6 +661,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(AssertStatement) */ + @Override public void endVisit(AssertStatement node) { } @@ -640,6 +669,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(Assignment) */ + @Override public void endVisit(Assignment node) { if (!isActive() || hasErrors()) return; @@ -649,6 +679,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(Block) */ + @Override public void endVisit(Block node) { if (!isActive() || hasErrors()) return; @@ -658,6 +689,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(BooleanLiteral) */ + @Override public void endVisit(BooleanLiteral node) { if (!isActive() || hasErrors()) return; @@ -667,6 +699,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(BreakStatement) */ + @Override public void endVisit(BreakStatement node) { if (!isActive() || hasErrors()) return; @@ -676,6 +709,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(CastExpression) */ + @Override public void endVisit(CastExpression node) { if (!isActive() || hasErrors()) return; @@ -685,6 +719,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(CatchClause) */ + @Override public void endVisit(CatchClause node) { } @@ -692,6 +727,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(CharacterLiteral) */ + @Override public void endVisit(CharacterLiteral node) { if (!isActive() || hasErrors()) return; @@ -701,6 +737,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ClassInstanceCreation) */ + @Override public void endVisit(ClassInstanceCreation node) { if (!isActive() || hasErrors()) return; @@ -710,6 +747,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(CompilationUnit) */ + @Override public void endVisit(CompilationUnit node) { } @@ -717,24 +755,25 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ConditionalExpression) */ + @Override public void endVisit(ConditionalExpression node) { if (!isActive() || hasErrors()) return; // Get the instructions - int ifFalseAddress= fInstructions.getEnd(); - Instruction ifFalse= fInstructions.get(ifFalseAddress); - int ifTrueAddress= ifFalseAddress - ifFalse.getSize(); - Instruction ifTrue= fInstructions.get(ifTrueAddress); - int conditionalAddress= ifTrueAddress - ifTrue.getSize(); + int ifFalseAddress = fInstructions.getEnd(); + Instruction ifFalse = fInstructions.get(ifFalseAddress); + int ifTrueAddress = ifFalseAddress - ifFalse.getSize(); + Instruction ifTrue = fInstructions.get(ifTrueAddress); + int conditionalAddress = ifTrueAddress - ifTrue.getSize(); // Insert the conditional jump - ConditionalJump conditionalJump= new ConditionalJump(false); + ConditionalJump conditionalJump = new ConditionalJump(false); fInstructions.insert(conditionalJump, conditionalAddress + 1); // Insert the jump - int jumpAddress= ifTrueAddress + 2; - Jump jump= new Jump(); + int jumpAddress = ifTrueAddress + 2; + Jump jump = new Jump(); fInstructions.insert(jump, jumpAddress); // Set the jump offsets @@ -749,6 +788,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ConstructorInvocation) */ + @Override public void endVisit(ConstructorInvocation node) { } @@ -756,6 +796,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ContinueStatement) */ + @Override public void endVisit(ContinueStatement node) { if (!isActive() || hasErrors()) return; @@ -765,33 +806,29 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(DoStatement) */ + @Override public void endVisit(DoStatement node) { if (!isActive() || hasErrors()) return; - /* The structure of generated instructions is : - * - * -- - * | body - * -- - * -- - * |condition - * -- - * - jump to the first instruction of the body if the condition is true. - * + /* + * The structure of generated instructions is : + * + * -- | body -- -- |condition -- - jump to the first instruction of the + * body if the condition is true. */ - String label= getLabel(node); + String label = getLabel(node); // get address of each part - int conditionAddress= fInstructions.getEnd(); - Instruction condition= fInstructions.getInstruction(conditionAddress); - int bodyAddress= conditionAddress - condition.getSize(); - Instruction body= fInstructions.getInstruction(bodyAddress); - int bodyStartAddress= bodyAddress - body.getSize(); + int conditionAddress = fInstructions.getEnd(); + Instruction condition = fInstructions.getInstruction(conditionAddress); + int bodyAddress = conditionAddress - condition.getSize(); + Instruction body = fInstructions.getInstruction(bodyAddress); + int bodyStartAddress = bodyAddress - body.getSize(); // add the conditionnalJump - ConditionalJump conditionalJump= new ConditionalJump(true); + ConditionalJump conditionalJump = new ConditionalJump(true); fInstructions.add(conditionalJump); fCounter++; @@ -800,15 +837,18 @@ public class ASTInstructionCompiler extends ASTVisitor { // for each pending break or continue instruction which are related to // this loop, set the offset of the corresponding jump. - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); - if (instructionAddress > bodyStartAddress && (instruction.fLabel == null || instruction.fLabel.equals(label))) { + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); + if (instructionAddress > bodyStartAddress + && (instruction.fLabel == null || instruction.fLabel + .equals(label))) { iter.remove(); if (instruction.fIsBreak) { // jump to the instruction after the last jump - jumpInstruction.setOffset((conditionAddress - instructionAddress) + 1); + jumpInstruction + .setOffset((conditionAddress - instructionAddress) + 1); } else { // jump to the first instruction of the condition jumpInstruction.setOffset(bodyAddress - instructionAddress); @@ -822,101 +862,88 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(EmptyStatement) */ + @Override public void endVisit(EmptyStatement node) { if (!isActive() || hasErrors()) return; storeInstruction(); } - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.EnhancedForStatement) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom + * .EnhancedForStatement) */ + @Override public void endVisit(EnhancedForStatement node) { if (!isActive() || hasErrors()) return; - /* The structure of generated instructions is : - * - * For an array: - * -- - * | <ParameterType>[] a= Expression - * | int i= 0 - * | <ParameterType> <ParameterName> - * -- - * -- - * | i < a.length - * - jump to the instruction after the last jump if the condition is false. - * -- - * -- - * | s= a[i] - * | Body - * -- - * -- - * - jump to the first instruction of the condition. - * - * For an Iterable: - * -- - * | Iterator i= Expression.iterator() - * | <ParameterType> <ParameterName> - * -- - * -- - * | i.hasNext() - * - jump to the instruction after the last jump if the condition is false. - * -- - * -- - * | s= i.next() - * | Body - * -- - * -- - * - jump to the first instruction of the condition. - * + /* + * The structure of generated instructions is : + * + * For an array: -- | <ParameterType>[] a= Expression | int i= 0 | + * <ParameterType> <ParameterName> -- -- | i < a.length - jump to the + * instruction after the last jump if the condition is false. -- -- | s= + * a[i] | Body -- -- - jump to the first instruction of the condition. + * + * For an Iterable: -- | Iterator i= Expression.iterator() | + * <ParameterType> <ParameterName> -- -- | i.hasNext() - jump to the + * instruction after the last jump if the condition is false. -- -- | s= + * i.next() | Body -- -- - jump to the first instruction of the + * condition. */ - int bodyAddress= fInstructions.getEnd(); - Instruction body= fInstructions.getInstruction(bodyAddress); - int conditionAddress= bodyAddress - body.getSize(); - Instruction condition= fInstructions.getInstruction(conditionAddress); - int initAddress= conditionAddress - condition.getSize(); - + int bodyAddress = fInstructions.getEnd(); + Instruction body = fInstructions.getInstruction(bodyAddress); + int conditionAddress = bodyAddress - body.getSize(); + Instruction condition = fInstructions.getInstruction(conditionAddress); + int initAddress = conditionAddress - condition.getSize(); + // add conditional jump - ConditionalJump condJump= new ConditionalJump(false); + ConditionalJump condJump = new ConditionalJump(false); fInstructions.insert(condJump, conditionAddress + 1); bodyAddress++; fCounter++; condJump.setOffset(body.getSize() + 1); - + // add jump - Jump jump= new Jump(); + Jump jump = new Jump(); fInstructions.add(jump); fCounter++; jump.setOffset(initAddress - (bodyAddress + 1)); - // for each pending break or continue instruction which are related to // this loop, set the offset of the corresponding jump. - String label= getLabel(node); - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); - if (instructionAddress > conditionAddress && (instruction.fLabel == null || instruction.fLabel.equals(label))) { + String label = getLabel(node); + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); + if (instructionAddress > conditionAddress + && (instruction.fLabel == null || instruction.fLabel + .equals(label))) { iter.remove(); if (instruction.fIsBreak) { // jump to the instruction after the last jump - jumpInstruction.setOffset((bodyAddress - instructionAddress) + 1); + jumpInstruction + .setOffset((bodyAddress - instructionAddress) + 1); } else { // jump to the first instruction of the condition jumpInstruction.setOffset(initAddress - instructionAddress); } } } - + storeInstruction(); } /** * @see ASTVisitor#endVisit(ExpressionStatement) */ + @Override public void endVisit(ExpressionStatement node) { if (!isActive() || hasErrors()) return; @@ -927,6 +954,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(FieldAccess) */ + @Override public void endVisit(FieldAccess node) { if (!isActive() || hasErrors()) return; @@ -936,6 +964,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(FieldDeclaration) */ + @Override public void endVisit(FieldDeclaration node) { } @@ -943,58 +972,48 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ForStatement) */ + @Override public void endVisit(ForStatement node) { if (!isActive() || hasErrors()) return; - /* The structure of generated instructions is : - * - * -- - * |initialization - * -- - * -- - * |condition - * -- - * - jump to the instruction after the last jump if the condition is false. - * -- - * | body - * -- - * -- - * | updaters - * -- - * - jump to the first instruction of the condition. - * + /* + * The structure of generated instructions is : + * + * -- |initialization -- -- |condition -- - jump to the instruction + * after the last jump if the condition is false. -- | body -- -- | + * updaters -- - jump to the first instruction of the condition. */ - String label= getLabel(node); - boolean hasCondition= node.getExpression() != null; + String label = getLabel(node); + boolean hasCondition = node.getExpression() != null; // get address of each part - int updatersAddress= fInstructions.getEnd(); - Instruction updaters= fInstructions.getInstruction(updatersAddress); - int bodyAddress= updatersAddress - updaters.getSize(); - Instruction body= fInstructions.getInstruction(bodyAddress); - int bodyStartAddress= bodyAddress - body.getSize(); + int updatersAddress = fInstructions.getEnd(); + Instruction updaters = fInstructions.getInstruction(updatersAddress); + int bodyAddress = updatersAddress - updaters.getSize(); + Instruction body = fInstructions.getInstruction(bodyAddress); + int bodyStartAddress = bodyAddress - body.getSize(); int conditionAddress; Instruction condition; if (hasCondition) { - conditionAddress= bodyStartAddress; - condition= fInstructions.getInstruction(conditionAddress); + conditionAddress = bodyStartAddress; + condition = fInstructions.getInstruction(conditionAddress); } else { - conditionAddress= 0; - condition= null; + conditionAddress = 0; + condition = null; } // add jump - Jump jump= new Jump(); + Jump jump = new Jump(); fInstructions.add(jump); fCounter++; if (hasCondition) { // add conditional jump - ConditionalJump condJump= new ConditionalJump(false); + ConditionalJump condJump = new ConditionalJump(false); fInstructions.insert(condJump, conditionAddress + 1); bodyAddress++; bodyStartAddress++; @@ -1005,19 +1024,23 @@ public class ASTInstructionCompiler extends ASTVisitor { } // set jump offset - jump.setOffset(-((hasCondition && (condition != null) ? condition.getSize() : 0) + body.getSize() + updaters.getSize() + 2)); + jump.setOffset(-((hasCondition && (condition != null) ? condition + .getSize() : 0) + body.getSize() + updaters.getSize() + 2)); // for each pending break or continue instruction which are related to // this loop, set the offset of the corresponding jump. - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); - if (instructionAddress > bodyStartAddress && (instruction.fLabel == null || instruction.fLabel.equals(label))) { + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); + if (instructionAddress > bodyStartAddress + && (instruction.fLabel == null || instruction.fLabel + .equals(label))) { iter.remove(); if (instruction.fIsBreak) { // jump to the instruction after the last jump - jumpInstruction.setOffset((updatersAddress - instructionAddress) + 1); + jumpInstruction + .setOffset((updatersAddress - instructionAddress) + 1); } else { // jump to the first instruction of the condition jumpInstruction.setOffset(bodyAddress - instructionAddress); @@ -1031,42 +1054,44 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(IfStatement) */ + @Override public void endVisit(IfStatement node) { if (!isActive() || hasErrors()) return; - boolean hasElseStatement= node.getElseStatement() != null; + boolean hasElseStatement = node.getElseStatement() != null; // Get the instructions - int ifFalseAddress= 0; - Instruction ifFalse= null; - int ifTrueAddress= 0; - Instruction ifTrue= null; + int ifFalseAddress = 0; + Instruction ifFalse = null; + int ifTrueAddress = 0; + Instruction ifTrue = null; if (hasElseStatement) { - ifFalseAddress= fInstructions.getEnd(); - ifFalse= fInstructions.get(ifFalseAddress); - ifTrueAddress= ifFalseAddress - ifFalse.getSize(); - ifTrue= fInstructions.get(ifTrueAddress); + ifFalseAddress = fInstructions.getEnd(); + ifFalse = fInstructions.get(ifFalseAddress); + ifTrueAddress = ifFalseAddress - ifFalse.getSize(); + ifTrue = fInstructions.get(ifTrueAddress); } else { - ifTrueAddress= fInstructions.getEnd(); - ifTrue= fInstructions.get(ifTrueAddress); + ifTrueAddress = fInstructions.getEnd(); + ifTrue = fInstructions.get(ifTrueAddress); } - int conditionalAddress= ifTrueAddress - ifTrue.getSize(); + int conditionalAddress = ifTrueAddress - ifTrue.getSize(); // Insert the conditional jump - ConditionalJump conditionalJump= new ConditionalJump(false); + ConditionalJump conditionalJump = new ConditionalJump(false); fInstructions.insert(conditionalJump, conditionalAddress + 1); // Set the jump offset - conditionalJump.setOffset(ifTrue.getSize() + ((hasElseStatement)? 1 : 0)); + conditionalJump.setOffset(ifTrue.getSize() + + ((hasElseStatement) ? 1 : 0)); fCounter++; if (hasElseStatement) { // Insert the jump - int jumpAddress= ifTrueAddress + 2; - Jump jump= new Jump(); + int jumpAddress = ifTrueAddress + 2; + Jump jump = new Jump(); fInstructions.insert(jump, jumpAddress); // Set the jump offset jump.setOffset(ifFalse.getSize() + 1); @@ -1080,6 +1105,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ImportDeclaration) */ + @Override public void endVisit(ImportDeclaration node) { } @@ -1087,12 +1113,14 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(InfixExpression) */ + @Override public void endVisit(InfixExpression node) { } /** * @see ASTVisitor#endVisit(Initializer) */ + @Override public void endVisit(Initializer node) { } @@ -1100,6 +1128,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(InstanceofExpression) */ + @Override public void endVisit(InstanceofExpression node) { if (!isActive() || hasErrors()) return; @@ -1109,6 +1138,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(Javadoc) */ + @Override public void endVisit(Javadoc node) { } @@ -1116,23 +1146,25 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(LabeledStatement) */ + @Override public void endVisit(LabeledStatement node) { if (!isActive() || hasErrors()) return; - String label= node.getLabel().getIdentifier(); + String label = node.getLabel().getIdentifier(); // for each pending continue instruction which are related to // this statement, set the offset of the corresponding jump. - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); if (instruction.fLabel != null && instruction.fLabel.equals(label)) { iter.remove(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); if (instruction.fIsBreak) { // jump to the instruction after the statement - jumpInstruction.setOffset(fInstructions.getEnd() - instructionAddress); + jumpInstruction.setOffset(fInstructions.getEnd() + - instructionAddress); } } } @@ -1141,6 +1173,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(MethodDeclaration) */ + @Override public void endVisit(MethodDeclaration node) { setActive(false); } @@ -1148,6 +1181,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(MethodInvocation) */ + @Override public void endVisit(MethodInvocation node) { if (!isActive() || hasErrors()) return; @@ -1157,6 +1191,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(NullLiteral) */ + @Override public void endVisit(NullLiteral node) { if (!isActive() || hasErrors()) return; @@ -1166,6 +1201,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(NumberLiteral) */ + @Override public void endVisit(NumberLiteral node) { if (!isActive() || hasErrors()) return; @@ -1175,6 +1211,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(PackageDeclaration) */ + @Override public void endVisit(PackageDeclaration node) { } @@ -1182,6 +1219,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SimpleType) */ + @Override public void endVisit(ParameterizedType node) { if (!isActive() || hasErrors()) return; @@ -1191,6 +1229,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ParenthesizedExpression) */ + @Override public void endVisit(ParenthesizedExpression node) { } @@ -1198,6 +1237,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(PostfixExpression) */ + @Override public void endVisit(PostfixExpression node) { if (!isActive() || hasErrors()) return; @@ -1207,6 +1247,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(PrefixExpression) */ + @Override public void endVisit(PrefixExpression node) { if (!isActive() || hasErrors()) return; @@ -1216,21 +1257,24 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(PrimitiveType) */ + @Override public void endVisit(PrimitiveType node) { if (!isActive() || hasErrors()) return; - storeInstruction(); + storeInstruction(); } /** * @see ASTVisitor#endVisit(QualifiedName) */ + @Override public void endVisit(QualifiedName node) { } /** * @see ASTVisitor#endVisit(SimpleType) */ + @Override public void endVisit(QualifiedType node) { if (!isActive() || hasErrors()) return; @@ -1240,6 +1284,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ReturnStatement) */ + @Override public void endVisit(ReturnStatement node) { if (!isActive() || hasErrors()) return; @@ -1249,6 +1294,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SimpleName) */ + @Override public void endVisit(SimpleName node) { if (!isActive() || hasErrors()) return; @@ -1258,6 +1304,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SimpleType) */ + @Override public void endVisit(SimpleType node) { if (!isActive() || hasErrors()) return; @@ -1267,6 +1314,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SingleVariableDeclaration) */ + @Override public void endVisit(SingleVariableDeclaration node) { if (!isActive() || hasErrors()) return; @@ -1276,6 +1324,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(StringLiteral) */ + @Override public void endVisit(StringLiteral node) { if (!isActive() || hasErrors()) return; @@ -1285,6 +1334,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SuperConstructorInvocation) */ + @Override public void endVisit(SuperConstructorInvocation node) { } @@ -1292,6 +1342,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SuperFieldAccess) */ + @Override public void endVisit(SuperFieldAccess node) { if (!isActive() || hasErrors()) return; @@ -1301,6 +1352,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SuperMethodInvocation) */ + @Override public void endVisit(SuperMethodInvocation node) { if (!isActive() || hasErrors()) return; @@ -1310,6 +1362,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SwitchCase) */ + @Override public void endVisit(SwitchCase node) { // never called } @@ -1317,6 +1370,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SwitchStatement) */ + @Override public void endVisit(SwitchStatement node) { // nothing to do } @@ -1324,6 +1378,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(SynchronizedStatement) */ + @Override public void endVisit(SynchronizedStatement node) { } @@ -1331,6 +1386,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ThisExpression) */ + @Override public void endVisit(ThisExpression node) { if (!isActive() || hasErrors()) return; @@ -1340,6 +1396,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(ThrowStatement) */ + @Override public void endVisit(ThrowStatement node) { if (!isActive() || hasErrors()) return; @@ -1349,6 +1406,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(TryStatement) */ + @Override public void endVisit(TryStatement node) { } @@ -1356,6 +1414,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(TypeDeclaration) */ + @Override public void endVisit(TypeDeclaration node) { } @@ -1363,6 +1422,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(TypeDeclarationStatement) */ + @Override public void endVisit(TypeDeclarationStatement node) { } @@ -1370,6 +1430,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(TypeLiteral) */ + @Override public void endVisit(TypeLiteral node) { if (!isActive() || hasErrors()) return; @@ -1379,6 +1440,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(VariableDeclarationExpression) */ + @Override public void endVisit(VariableDeclarationExpression node) { } @@ -1386,6 +1448,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(VariableDeclarationFragment) */ + @Override public void endVisit(VariableDeclarationFragment node) { if (!isActive() || hasErrors()) return; @@ -1395,6 +1458,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(VariableDeclarationStatement) */ + @Override public void endVisit(VariableDeclarationStatement node) { } @@ -1402,37 +1466,33 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#endVisit(WhileStatement) */ + @Override public void endVisit(WhileStatement node) { if (!isActive() || hasErrors()) return; - /* The structure of generated instructions is : - * - * -- - * |condition - * -- - * - jump to the instruction after the last jump if the condition is false. - * -- - * | body - * -- - * - jump to the first instruction of the condition. - * + /* + * The structure of generated instructions is : + * + * -- |condition -- - jump to the instruction after the last jump if the + * condition is false. -- | body -- - jump to the first instruction of + * the condition. */ - String label= getLabel(node); + String label = getLabel(node); // get address of each part - int bodyAddress= fInstructions.getEnd(); - Instruction body= fInstructions.getInstruction(bodyAddress); - int conditionAddress= bodyAddress - body.getSize(); - Instruction condition= fInstructions.getInstruction(conditionAddress); + int bodyAddress = fInstructions.getEnd(); + Instruction body = fInstructions.getInstruction(bodyAddress); + int conditionAddress = bodyAddress - body.getSize(); + Instruction condition = fInstructions.getInstruction(conditionAddress); // add the conditionnalJump - ConditionalJump conditionalJump= new ConditionalJump(false); + ConditionalJump conditionalJump = new ConditionalJump(false); fInstructions.insert(conditionalJump, conditionAddress + 1); // add the jump - Jump jump= new Jump(); + Jump jump = new Jump(); fInstructions.add(jump); // set jump offsets @@ -1441,51 +1501,59 @@ public class ASTInstructionCompiler extends ASTVisitor { // for each pending break or continue instruction which are related to // this loop, set the offset of the corresponding jump. - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); - if (instructionAddress > conditionAddress && (instruction.fLabel == null || instruction.fLabel.equals(label))) { + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); + if (instructionAddress > conditionAddress + && (instruction.fLabel == null || instruction.fLabel + .equals(label))) { iter.remove(); if (instruction.fIsBreak) { // jump to the instruction after the last jump - jumpInstruction.setOffset((bodyAddress - instructionAddress) + 2); + jumpInstruction + .setOffset((bodyAddress - instructionAddress) + 2); } else { // jump to the first instruction of the condition - jumpInstruction.setOffset((conditionAddress - condition.getSize()) - instructionAddress); + jumpInstruction.setOffset((conditionAddress - condition + .getSize()) - instructionAddress); } } } - fCounter+= 2; + fCounter += 2; storeInstruction(); } /* * Visit methods - * - * There are two variations of node visiting: - * <ol> - * <li>Push the instruction corresponding to the node - * onto the stack and return <code>true</code> to visit - * the children of the node.</li> - * <li>Push the instruction corresponding to the node - * onto the stack and visit the children of the node - * manually (return <code>false</code> to avoid the - * default child visiting implementation).</li> - * </ol> + * + * There are two variations of node visiting: <ol> <li>Push the instruction + * corresponding to the node onto the stack and return <code>true</code> to + * visit the children of the node.</li> <li>Push the instruction + * corresponding to the node onto the stack and visit the children of the + * node manually (return <code>false</code> to avoid the default child + * visiting implementation).</li> </ol> */ - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * AnnotationTypeDeclaration) */ + @Override public boolean visit(AnnotationTypeDeclaration node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * AnnotationTypeMemberDeclaration) */ + @Override public boolean visit(AnnotationTypeMemberDeclaration node) { return false; } @@ -1493,24 +1561,27 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(AnonymousClassDeclaration) */ + @Override public boolean visit(AnonymousClassDeclaration node) { if (!isActive()) { return true; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Anonymous_type_declaration_cannot_be_used_in_an_evaluation_expression_2); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Anonymous_type_declaration_cannot_be_used_in_an_evaluation_expression_2); return false; } /** * @see ASTVisitor#visit(ArrayAccess) */ + @Override public boolean visit(ArrayAccess node) { if (!isActive()) { return false; } - push(new org.eclipse.jdt.internal.debug.eval.ast.instructions.ArrayAccess(fCounter)); + push(new org.eclipse.jdt.internal.debug.eval.ast.instructions.ArrayAccess( + fCounter)); return true; } @@ -1518,21 +1589,23 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayCreation) */ + @Override public boolean visit(ArrayCreation node) { if (!isActive()) { return false; } - ArrayType arrayType= node.getType(); + ArrayType arrayType = node.getType(); ITypeBinding binding = resolveTypeBinding(arrayType); if (binding != null && isALocalType(binding.getElementType())) { - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Local_type_array_instance_creation_cannot_be_used_in_an_evaluation_expression_29); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Local_type_array_instance_creation_cannot_be_used_in_an_evaluation_expression_29); setHasError(true); return false; } - push(new ArrayAllocation(arrayType.getDimensions(), node.dimensions().size(), node.getInitializer() != null, fCounter)); + push(new ArrayAllocation(arrayType.getDimensions(), node.dimensions() + .size(), node.getInitializer() != null, fCounter)); return true; } @@ -1540,6 +1613,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayInitializer) */ + @Override public boolean visit(ArrayInitializer node) { if (!isActive()) { return false; @@ -1547,9 +1621,10 @@ public class ASTInstructionCompiler extends ASTVisitor { ITypeBinding typeBinding = resolveTypeBinding(node); if (typeBinding != null) { - int dimension= typeBinding.getDimensions(); - String signature= getTypeSignature(typeBinding.getElementType()); - push(new ArrayInitializerInstruction(signature, node.expressions().size(), dimension, fCounter)); + int dimension = typeBinding.getDimensions(); + String signature = getTypeSignature(typeBinding.getElementType()); + push(new ArrayInitializerInstruction(signature, node.expressions() + .size(), dimension, fCounter)); } return true; @@ -1558,14 +1633,16 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayType) */ + @Override public boolean visit(ArrayType node) { if (!isActive()) { return false; } - ITypeBinding arrayTypeBinding= resolveTypeBinding(node); + ITypeBinding arrayTypeBinding = resolveTypeBinding(node); if (arrayTypeBinding != null) { - int dimension= arrayTypeBinding.getDimensions(); - String signature= getTypeSignature(arrayTypeBinding.getElementType()); + int dimension = arrayTypeBinding.getDimensions(); + String signature = getTypeSignature(arrayTypeBinding + .getElementType()); push(new PushArrayType(signature, dimension, fCounter)); } @@ -1575,24 +1652,26 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(AssertStatement) */ + @Override public boolean visit(AssertStatement node) { if (!isActive()) { return false; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Assert_statement_cannot_be_used_in_an_evaluation_expression_3); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Assert_statement_cannot_be_used_in_an_evaluation_expression_3); return false; } /** * @see ASTVisitor#visit(Assignment) */ + @Override public boolean visit(Assignment node) { if (!isActive()) { return false; } - Expression leftHandSide= node.getLeftHandSide(); - Expression rightHandSide= node.getRightHandSide(); + Expression leftHandSide = node.getLeftHandSide(); + Expression rightHandSide = node.getRightHandSide(); int variableTypeId = getTypeId(leftHandSide); int valueTypeId = getTypeId(rightHandSide); @@ -1616,86 +1695,102 @@ public class ASTInstructionCompiler extends ASTVisitor { // If the variable is an object, the value may need to be boxed for // the simple assignment. // For the compound assignment operators, the value of the variable - // have to be un-boxed before the operation is done, then re-boxed to + // have to be un-boxed before the operation is done, then re-boxed + // to // to be stored in the variable. - - int unboxedVariableTypeId= getUnBoxedTypeId(leftHandSide); - int unboxedValueTypeId= getUnBoxedTypeId(rightHandSide); - int unboxedResultTypeId= Instruction.getBinaryPromotionType(unboxedVariableTypeId, unboxedValueTypeId); - push(new AssignmentOperator(variableTypeId, variableTypeId, fCounter)); - + int unboxedVariableTypeId = getUnBoxedTypeId(leftHandSide); + int unboxedValueTypeId = getUnBoxedTypeId(rightHandSide); + int unboxedResultTypeId = Instruction.getBinaryPromotionType( + unboxedVariableTypeId, unboxedValueTypeId); + + push(new AssignmentOperator(variableTypeId, variableTypeId, + fCounter)); + leftHandSide.accept(this); - + if (char0 == '=') { - - boolean storeRequired= false; + + boolean storeRequired = false; if (rightBinding.isPrimitive()) { boxing(leftBinding, rightBinding); - storeRequired= true; + storeRequired = true; } rightHandSide.accept(this); if (storeRequired) { storeInstruction(); // boxing } - + } else { boolean unrecognized = false; - - + boxing(leftBinding, rightBinding); - + switch (char0) { - case '=': // equal - break; - case '+': // plus equal - push(new PlusOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '-': // minus equal - push(new MinusOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '*': // multiply equal - push(new MultiplyOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '/': // divide equal - push(new DivideOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '%': // remainder equal - push(new RemainderOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '^': // XOr equal - push(new XorOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '|': // or equal - push(new OrOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '&': // and equal - push(new AndOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '<': // left shift equal - push(new LeftShiftOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); + case '=': // equal + break; + case '+': // plus equal + push(new PlusOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '-': // minus equal + push(new MinusOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '*': // multiply equal + push(new MultiplyOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '/': // divide equal + push(new DivideOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '%': // remainder equal + push(new RemainderOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '^': // XOr equal + push(new XorOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '|': // or equal + push(new OrOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '&': // and equal + push(new AndOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '<': // left shift equal + push(new LeftShiftOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, fCounter)); + break; + case '>': // right shift equal or unsigned right shift equal + switch (char2) { + case '=': // right shift equal + push(new RightShiftOperator(unboxedVariableTypeId, + unboxedValueTypeId, unboxedResultTypeId, + fCounter)); break; - case '>': // right shift equal or unsigned right shift equal - switch (char2) { - case '=': // right shift equal - push(new RightShiftOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - case '>': // unsigned right shift equal - push(new UnsignedRightShiftOperator(unboxedVariableTypeId, unboxedValueTypeId, unboxedResultTypeId, fCounter)); - break; - default: - unrecognized = true; - break; - } + case '>': // unsigned right shift equal + push(new UnsignedRightShiftOperator( + unboxedVariableTypeId, unboxedValueTypeId, + unboxedResultTypeId, fCounter)); break; default: unrecognized = true; break; + } + break; + default: + unrecognized = true; + break; } if (unrecognized) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_assignment_operator____4 + opToken); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_assignment_operator____4 + + opToken); return false; } @@ -1703,93 +1798,107 @@ public class ASTInstructionCompiler extends ASTVisitor { push(new Dup()); storeInstruction(); // dupe storeInstruction(); // un-boxing - - boolean storeRequired= unBoxing(rightBinding); + + boolean storeRequired = unBoxing(rightBinding); rightHandSide.accept(this); if (storeRequired) { storeInstruction(); // un-boxing } - + storeInstruction(); // operation storeInstruction(); // boxing - + } - + } else { boolean unrecognized = false; - + switch (char0) { - case '=': // equal - push(new AssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '+': // plus equal - push(new PlusAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '-': // minus equal - push(new MinusAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '*': // multiply equal - push(new MultiplyAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '/': // divide equal - push(new DivideAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '%': // remainder equal - push(new RemainderAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '^': // XOr equal - push(new XorAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '|': // or equal - push(new OrAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '&': // and equal - push(new AndAssignmentOperator(variableTypeId, valueTypeId, fCounter)); + case '=': // equal + push(new AssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '+': // plus equal + push(new PlusAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '-': // minus equal + push(new MinusAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '*': // multiply equal + push(new MultiplyAssignmentOperator(variableTypeId, + valueTypeId, fCounter)); + break; + case '/': // divide equal + push(new DivideAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '%': // remainder equal + push(new RemainderAssignmentOperator(variableTypeId, + valueTypeId, fCounter)); + break; + case '^': // XOr equal + push(new XorAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '|': // or equal + push(new OrAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '&': // and equal + push(new AndAssignmentOperator(variableTypeId, valueTypeId, + fCounter)); + break; + case '<': // left shift equal + push(new LeftShiftAssignmentOperator(variableTypeId, + valueTypeId, fCounter)); + break; + case '>': // right shift equal or unsigned right shift equal + switch (char2) { + case '=': // right shift equal + push(new RightShiftAssignmentOperator(variableTypeId, + valueTypeId, fCounter)); break; - case '<': // left shift equal - push(new LeftShiftAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '>': // right shift equal or unsigned right shift equal - switch (char2) { - case '=': // right shift equal - push(new RightShiftAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - case '>': // unsigned right shift equal - push(new UnsignedRightShiftAssignmentOperator(variableTypeId, valueTypeId, fCounter)); - break; - default: - unrecognized = true; - break; - } + case '>': // unsigned right shift equal + push(new UnsignedRightShiftAssignmentOperator( + variableTypeId, valueTypeId, fCounter)); break; default: unrecognized = true; break; + } + break; + default: + unrecognized = true; + break; } - + if (unrecognized) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_assignment_operator____4 + opToken); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_assignment_operator____4 + + opToken); return false; } - + leftHandSide.accept(this); - boolean storeRequired= unBoxing(rightBinding); + boolean storeRequired = unBoxing(rightBinding); rightHandSide.accept(this); if (storeRequired) { storeInstruction(); } } - + return false; - + } /** * @see ASTVisitor#visit(Block) */ + @Override public boolean visit(Block node) { - int start= node.getStartPosition(); + int start = node.getStartPosition(); if (start == fStartPosition || start == (fStartPosition + 1)) { setActive(true); } @@ -1802,16 +1911,21 @@ public class ASTInstructionCompiler extends ASTVisitor { return true; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.BlockComment) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * BlockComment) */ + @Override public boolean visit(BlockComment node) { return false; } - + /** * @see ASTVisitor#visit(BooleanLiteral) */ + @Override public boolean visit(BooleanLiteral node) { if (!isActive()) { return false; @@ -1825,6 +1939,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(BreakStatement) */ + @Override public boolean visit(BreakStatement node) { if (!isActive()) { return false; @@ -1832,14 +1947,15 @@ public class ASTInstructionCompiler extends ASTVisitor { // create the equivalent jump instruction in the instruction // and add an element in the list of pending break and continue // instructions - Jump instruction= new Jump(); - SimpleName labelName= node.getLabel(); - String label= null; + Jump instruction = new Jump(); + SimpleName labelName = node.getLabel(); + String label = null; if (labelName != null) { - label= labelName.getIdentifier(); + label = labelName.getIdentifier(); } push(instruction); - fCompleteInstructions.add(new CompleteInstruction(instruction, label, true)); + fCompleteInstructions.add(new CompleteInstruction(instruction, label, + true)); return false; } @@ -1847,22 +1963,23 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(CastExpression) */ + @Override public boolean visit(CastExpression node) { if (!isActive()) { return false; } - Type type= node.getType(); - int typeId= getTypeId(type); - ITypeBinding typeBinding= resolveTypeBinding(type); - + Type type = node.getType(); + int typeId = getTypeId(type); + ITypeBinding typeBinding = resolveTypeBinding(type); + if (typeBinding != null) { String baseTypeSignature; - int dimension= typeBinding.getDimensions(); + int dimension = typeBinding.getDimensions(); if (typeBinding.isArray()) { - typeBinding= typeBinding.getElementType(); + typeBinding = typeBinding.getElementType(); } - baseTypeSignature= getTypeName(typeBinding); + baseTypeSignature = getTypeName(typeBinding); push(new Cast(typeId, baseTypeSignature, dimension, fCounter)); node.getExpression().accept(this); } @@ -1873,18 +1990,20 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(CatchClause) */ + @Override public boolean visit(CatchClause node) { if (!isActive()) { return false; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Catch_clause_cannot_be_used_in_an_evaluation_expression_6); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Catch_clause_cannot_be_used_in_an_evaluation_expression_6); return false; } /** * @see ASTVisitor#visit(CharacterLiteral) */ + @Override public boolean visit(CharacterLiteral node) { if (!isActive()) { return false; @@ -1896,9 +2015,12 @@ public class ASTInstructionCompiler extends ASTVisitor { } /** - * return false, visit expression, type name & arguments, don't visit body declaration + * return false, visit expression, type name & arguments, don't visit body + * declaration + * * @see ASTVisitor#visit(ClassInstanceCreation) */ + @Override public boolean visit(ClassInstanceCreation node) { if (!isActive()) { return true; @@ -1906,50 +2028,55 @@ public class ASTInstructionCompiler extends ASTVisitor { if (node.getAnonymousClassDeclaration() != null) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Anonymous_type_declaration_cannot_be_used_in_an_evaluation_expression_7); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Anonymous_type_declaration_cannot_be_used_in_an_evaluation_expression_7); } - IMethodBinding methodBinding= node.resolveConstructorBinding(); + IMethodBinding methodBinding = node.resolveConstructorBinding(); if (methodBinding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_1, new String[]{node.toString()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_1, + new Object[] { node.toString() })); return false; } - ITypeBinding typeBinding= methodBinding.getDeclaringClass(); + ITypeBinding typeBinding = methodBinding.getDeclaringClass(); - boolean isInstanceMemberType= typeBinding.isMember() && ! Modifier.isStatic(typeBinding.getModifiers()); + boolean isInstanceMemberType = typeBinding.isMember() + && !Modifier.isStatic(typeBinding.getModifiers()); if (isALocalType(typeBinding)) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Constructor_of_a_local_type_cannot_be_used_in_an_evaluation_expression_8); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Constructor_of_a_local_type_cannot_be_used_in_an_evaluation_expression_8); } if (containsALocalType(methodBinding)) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Constructor_which_contains_a_local_type_as_parameter_cannot_be_used_in_an_evaluation_expression_30); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Constructor_which_contains_a_local_type_as_parameter_cannot_be_used_in_an_evaluation_expression_30); } - if (hasErrors()) { return false; } - int paramCount= methodBinding.getParameterTypes().length; + int paramCount = methodBinding.getParameterTypes().length; - String enclosingTypeSignature= null; - ITypeBinding enclosingTypeBinding= null; + String enclosingTypeSignature = null; + ITypeBinding enclosingTypeBinding = null; if (isInstanceMemberType) { - enclosingTypeBinding= typeBinding.getDeclaringClass(); + enclosingTypeBinding = typeBinding.getDeclaringClass(); if (enclosingTypeBinding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_2, new String[]{typeBinding.getQualifiedName()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_2, + new Object[] { typeBinding.getQualifiedName() })); return false; } - enclosingTypeSignature= getTypeSignature(enclosingTypeBinding); + enclosingTypeSignature = getTypeSignature(enclosingTypeBinding); paramCount++; } - String signature= getMethodSignature(methodBinding, enclosingTypeSignature).replace('.','/'); + String signature = getMethodSignature(methodBinding, + enclosingTypeSignature).replace('.', '/'); push(new Constructor(signature, paramCount, fCounter)); @@ -1957,18 +2084,20 @@ public class ASTInstructionCompiler extends ASTVisitor { storeInstruction(); if (isInstanceMemberType) { - Expression optionalExpression= node.getExpression(); + Expression optionalExpression = node.getExpression(); if (optionalExpression != null) { optionalExpression.accept(this); } else { - // for a non-static inner class, check if we are not in a static context (method) - ASTNode parent= node; + // for a non-static inner class, check if we are not in a static + // context (method) + ASTNode parent = node; do { - parent= parent.getParent(); - } while (! (parent instanceof MethodDeclaration)); - if (Modifier.isStatic(((MethodDeclaration)parent).getModifiers())) { + parent = parent.getParent(); + } while (!(parent instanceof MethodDeclaration)); + if (Modifier.isStatic(((MethodDeclaration) parent) + .getModifiers())) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Must_explicitly_qualify_the_allocation_with_an_instance_of_the_enclosing_type_33); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Must_explicitly_qualify_the_allocation_with_an_instance_of_the_enclosing_type_33); return false; } @@ -1977,7 +2106,7 @@ public class ASTInstructionCompiler extends ASTVisitor { } } - List arguments = node.arguments(); + List<Expression> arguments = node.arguments(); pushMethodArguments(methodBinding, arguments); return false; @@ -1986,6 +2115,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(CompilationUnit) */ + @Override public boolean visit(CompilationUnit node) { return true; } @@ -1993,6 +2123,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ConditionalExpression) */ + @Override public boolean visit(ConditionalExpression node) { if (!isActive()) { return true; @@ -2006,18 +2137,20 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ConstructorInvocation) */ + @Override public boolean visit(ConstructorInvocation node) { if (!isActive()) { return false; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_this_constructor_invocation_cannot_be_used_in_an_evaluation_expression_9); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_this_constructor_invocation_cannot_be_used_in_an_evaluation_expression_9); return false; } /** * @see ASTVisitor#visit(ContinueStatement) */ + @Override public boolean visit(ContinueStatement node) { if (!isActive()) { return false; @@ -2025,14 +2158,15 @@ public class ASTInstructionCompiler extends ASTVisitor { // create the equivalent jump instruction in the instruction // and add an element in the list of pending break and continue // instructions - Jump instruction= new Jump(); - SimpleName labelName= node.getLabel(); - String label= null; + Jump instruction = new Jump(); + SimpleName labelName = node.getLabel(); + String label = null; if (labelName != null) { - label= labelName.getIdentifier(); + label = labelName.getIdentifier(); } push(instruction); - fCompleteInstructions.add(new CompleteInstruction(instruction, label, false)); + fCompleteInstructions.add(new CompleteInstruction(instruction, label, + false)); return false; } @@ -2040,6 +2174,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(DoStatement) */ + @Override public boolean visit(DoStatement node) { if (!isActive()) { return false; @@ -2052,6 +2187,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(EmptyStatement) */ + @Override public boolean visit(EmptyStatement node) { if (!isActive()) { return false; @@ -2060,123 +2196,140 @@ public class ASTInstructionCompiler extends ASTVisitor { return true; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.EnhancedForStatement) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * EnhancedForStatement) */ + @Override public boolean visit(EnhancedForStatement node) { if (!isActive()) { return false; } - + push(new NoOp(fCounter)); - - - ITypeBinding typeBinding= resolveTypeBinding(node.getExpression()); + + ITypeBinding typeBinding = resolveTypeBinding(node.getExpression()); if (typeBinding == null) { return false; } - Type paramType= node.getParameter().getType(); - ITypeBinding paramBinding = resolveTypeBinding(paramType); - if (paramBinding == null) { + Type paramType = node.getParameter().getType(); + ITypeBinding paramBinding = resolveTypeBinding(paramType); + if (paramBinding == null) { return false; - } - String typeSignature= getTypeSignature(paramBinding); - int paramTypeId= getTypeId(paramType); - boolean isParamPrimitiveType= paramTypeId != Instruction.T_Object && paramTypeId != Instruction.T_String; - String paramIdentifier= node.getParameter().getName().getIdentifier(); - + } + String typeSignature = getTypeSignature(paramBinding); + int paramTypeId = getTypeId(paramType); + boolean isParamPrimitiveType = paramTypeId != Instruction.T_Object + && paramTypeId != Instruction.T_String; + String paramIdentifier = node.getParameter().getName().getIdentifier(); + if (typeBinding.isArray()) { // the expression returns an array - int idIndex= fUniqueIdIndex++; - String arrayIdentifier= "#a" + idIndex; //$NON-NLS-1$ - String varIdentifier= "#i" + idIndex; //$NON-NLS-1$ - push(new LocalVariableCreation(arrayIdentifier, typeSignature, 1, isParamPrimitiveType, true, fCounter)); - node.getExpression().accept(this); + int idIndex = fUniqueIdIndex++; + String arrayIdentifier = "#a" + idIndex; //$NON-NLS-1$ + String varIdentifier = "#i" + idIndex; //$NON-NLS-1$ + push(new LocalVariableCreation(arrayIdentifier, typeSignature, 1, + isParamPrimitiveType, true, fCounter)); + node.getExpression().accept(this); storeInstruction(); - push(new LocalVariableCreation(varIdentifier, "I", 0, true, true, fCounter)); //$NON-NLS-1$ - push(new PushInt(0)); - storeInstruction(); + push(new LocalVariableCreation(varIdentifier, + "I", 0, true, true, fCounter)); //$NON-NLS-1$ + push(new PushInt(0)); storeInstruction(); - push(new LocalVariableCreation(paramIdentifier, typeSignature, 0, isParamPrimitiveType, false, fCounter)); storeInstruction(); - - push(new LessOperator(Instruction.T_int, Instruction.T_int, fCounter)); - push(new PushLocalVariable(varIdentifier)); - storeInstruction(); - push(new PushArrayLength(fCounter)); - push(new PushLocalVariable(arrayIdentifier)); - storeInstruction(); - storeInstruction(); + push(new LocalVariableCreation(paramIdentifier, typeSignature, 0, + isParamPrimitiveType, false, fCounter)); + storeInstruction(); + + push(new LessOperator(Instruction.T_int, Instruction.T_int, + fCounter)); + push(new PushLocalVariable(varIdentifier)); storeInstruction(); - + push(new PushArrayLength(fCounter)); + push(new PushLocalVariable(arrayIdentifier)); + storeInstruction(); + storeInstruction(); + storeInstruction(); + // conditional jump will be added here - + push(new NoOp(fCounter)); - push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter)); - push(new PushLocalVariable(paramIdentifier)); - storeInstruction(); - push(new org.eclipse.jdt.internal.debug.eval.ast.instructions.ArrayAccess(fCounter)); - push(new PushLocalVariable(arrayIdentifier)); - storeInstruction(); - push(new PostfixPlusPlusOperator(Instruction.T_int, fCounter)); - push(new PushLocalVariable(varIdentifier)); - storeInstruction(); - storeInstruction(); - storeInstruction(); - if (checkAutoBoxing(typeBinding.getElementType(), paramBinding)) { - storeInstruction(); - } + push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter)); + push(new PushLocalVariable(paramIdentifier)); + storeInstruction(); + push(new org.eclipse.jdt.internal.debug.eval.ast.instructions.ArrayAccess( + fCounter)); + push(new PushLocalVariable(arrayIdentifier)); + storeInstruction(); + push(new PostfixPlusPlusOperator(Instruction.T_int, fCounter)); + push(new PushLocalVariable(varIdentifier)); + storeInstruction(); + storeInstruction(); + storeInstruction(); + if (checkAutoBoxing(typeBinding.getElementType(), paramBinding)) { storeInstruction(); - addPopInstruction(); - node.getBody().accept(this); + } + storeInstruction(); + addPopInstruction(); + node.getBody().accept(this); storeInstruction(); - + // jump will be added here - + } else { // the expression returns a collection - String iteratorIdentifier= "#i" + fUniqueIdIndex++; //$NON-NLS-1$ - push(new LocalVariableCreation(iteratorIdentifier, "Ljava/util/Iterator;", 0, false, true, fCounter)); //$NON-NLS-1$ - push(new SendMessage("iterator", "()Ljava/util/Iterator;", 0, null, fCounter)); //$NON-NLS-1$//$NON-NLS-2$ - node.getExpression().accept(this); - storeInstruction(); + String iteratorIdentifier = "#i" + fUniqueIdIndex++; //$NON-NLS-1$ + push(new LocalVariableCreation(iteratorIdentifier, + "Ljava/util/Iterator;", 0, false, true, fCounter)); //$NON-NLS-1$ + push(new SendMessage( + "iterator", "()Ljava/util/Iterator;", 0, null, fCounter)); //$NON-NLS-1$//$NON-NLS-2$ + node.getExpression().accept(this); storeInstruction(); - push(new LocalVariableCreation(paramIdentifier, typeSignature, 0, isParamPrimitiveType, false, fCounter)); storeInstruction(); - + push(new LocalVariableCreation(paramIdentifier, typeSignature, 0, + isParamPrimitiveType, false, fCounter)); + storeInstruction(); + push(new SendMessage("hasNext", "()Z", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ - push(new PushLocalVariable(iteratorIdentifier)); - storeInstruction(); + push(new PushLocalVariable(iteratorIdentifier)); + storeInstruction(); storeInstruction(); - + // conditional jump will be added here - + push(new NoOp(fCounter)); - push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter)); - push(new PushLocalVariable(paramIdentifier)); - storeInstruction(); - push(new SendMessage("next", "()Ljava/lang/Object;", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ - push(new PushLocalVariable(iteratorIdentifier)); - storeInstruction(); - storeInstruction(); - if (checkAutoBoxing(typeBinding.getTypeArguments()[0], paramBinding)) { - storeInstruction(); - } + push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter)); + push(new PushLocalVariable(paramIdentifier)); + storeInstruction(); + push(new SendMessage( + "next", "()Ljava/lang/Object;", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + push(new PushLocalVariable(iteratorIdentifier)); + storeInstruction(); + storeInstruction(); + if (checkAutoBoxing(typeBinding.getTypeArguments()[0], paramBinding)) { storeInstruction(); - addPopInstruction(); - node.getBody().accept(this); + } + storeInstruction(); + addPopInstruction(); + node.getBody().accept(this); storeInstruction(); - + // jump will be added here - + } return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * EnumConstantDeclaration) */ + @Override public boolean visit(EnumConstantDeclaration node) { if (!isActive()) { return true; @@ -2186,56 +2339,69 @@ public class ASTInstructionCompiler extends ASTVisitor { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.EnumDeclaration) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * EnumDeclaration) */ + @Override public boolean visit(EnumDeclaration node) { if (!isActive()) { return true; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_0); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_0); return false; } /** * @see ASTVisitor#visit(ExpressionStatement) */ + @Override public boolean visit(ExpressionStatement node) { return true; } /** * return false, visit expression, don't visit name - * + * * @see ASTVisitor#visit(FieldAccess) */ + @Override public boolean visit(FieldAccess node) { if (!isActive()) { return false; } - SimpleName fieldName= node.getName(); - IVariableBinding fieldBinding= (IVariableBinding) fieldName.resolveBinding(); - if(fieldBinding != null) { - ITypeBinding declaringTypeBinding= fieldBinding.getDeclaringClass(); + SimpleName fieldName = node.getName(); + IVariableBinding fieldBinding = (IVariableBinding) fieldName + .resolveBinding(); + if (fieldBinding != null) { + ITypeBinding declaringTypeBinding = fieldBinding + .getDeclaringClass(); Expression expression = node.getExpression(); String fieldId = fieldName.getIdentifier(); - + if (Modifier.isStatic(fieldBinding.getModifiers())) { - push(new PushStaticFieldVariable(fieldId, getTypeName(declaringTypeBinding), fCounter)); + push(new PushStaticFieldVariable(fieldId, + getTypeName(declaringTypeBinding), fCounter)); expression.accept(this); addPopInstruction(); } else { - if (declaringTypeBinding == null) { // it is a field without declaring type => it is the special length array field + if (declaringTypeBinding == null) { // it is a field without + // declaring type => it is + // the special length array + // field push(new PushArrayLength(fCounter)); } else { if (isALocalType(declaringTypeBinding)) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Qualified_local_type_field_access_cannot_be_used_in_an_evaluation_expression_31); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Qualified_local_type_field_access_cannot_be_used_in_an_evaluation_expression_31); return false; } - push(new PushFieldVariable(fieldId, getTypeSignature(declaringTypeBinding), fCounter)); + push(new PushFieldVariable(fieldId, + getTypeSignature(declaringTypeBinding), fCounter)); } expression.accept(this); } @@ -2246,16 +2412,17 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(FieldDeclaration) */ + @Override public boolean visit(FieldDeclaration node) { return true; } /** - * @see ASTVisitor#visit(ForStatement) - * return <code>false</code>, don't use the standard accept order. - * order used for visiting children : - * initializers, condition, body, updaters + * @see ASTVisitor#visit(ForStatement) return <code>false</code>, don't use + * the standard accept order. order used for visiting children : + * initializers, condition, body, updaters */ + @Override public boolean visit(ForStatement node) { if (!isActive()) { return false; @@ -2264,14 +2431,14 @@ public class ASTInstructionCompiler extends ASTVisitor { push(new NoOp(fCounter)); push(new NoOp(fCounter)); - for (Iterator iter= node.initializers().iterator(); iter.hasNext();) { - Expression expr= (Expression) iter.next(); + for (Iterator<Expression> iter = node.initializers().iterator(); iter.hasNext();) { + Expression expr = iter.next(); expr.accept(this); addPopInstructionIfNeeded(expr); } storeInstruction(); - Expression condition= node.getExpression(); + Expression condition = node.getExpression(); if (condition != null) { condition.accept(this); } @@ -2279,8 +2446,8 @@ public class ASTInstructionCompiler extends ASTVisitor { node.getBody().accept(this); push(new NoOp(fCounter)); - for (Iterator iter= node.updaters().iterator(); iter.hasNext();) { - Expression expr= (Expression) iter.next(); + for (Iterator<Expression> iter = node.updaters().iterator(); iter.hasNext();) { + Expression expr = iter.next(); expr.accept(this); addPopInstructionIfNeeded(expr); } @@ -2292,6 +2459,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(IfStatement) */ + @Override public boolean visit(IfStatement node) { if (!isActive()) { return false; @@ -2305,15 +2473,17 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ImportDeclaration) */ + @Override public boolean visit(ImportDeclaration node) { return false; } /** * return <code>false</code>, don't use the standard accept order. - * + * * @see ASTVisitor#visit(InfixExpression) */ + @Override public boolean visit(InfixExpression node) { if (!isActive()) { return false; @@ -2331,20 +2501,21 @@ public class ASTInstructionCompiler extends ASTVisitor { } } - List extendedOperands = node.extendedOperands(); + List<Expression> extendedOperands = node.extendedOperands(); - int operatorNumber=extendedOperands.size() + 1; + int operatorNumber = extendedOperands.size() + 1; int[][] types = new int[operatorNumber][3]; - Iterator iterator = extendedOperands.iterator(); + Iterator<Expression> iterator = extendedOperands.iterator(); - Expression leftOperand= node.getLeftOperand(); - Expression rightOperand= node.getRightOperand(); + Expression leftOperand = node.getLeftOperand(); + Expression rightOperand = node.getRightOperand(); int leftTypeId; int rightTypeId; boolean unbox = false; - // for == and != un-box when at least operand is primitive (otherwise compare the objects) + // for == and != un-box when at least operand is primitive (otherwise + // compare the objects) ITypeBinding leftBinding = resolveTypeBinding(leftOperand); if (leftBinding == null) { return false; @@ -2359,166 +2530,188 @@ public class ASTInstructionCompiler extends ASTVisitor { unbox = true; } if (unbox) { - leftTypeId= getUnBoxedTypeId(leftOperand); + leftTypeId = getUnBoxedTypeId(leftOperand); rightTypeId = getUnBoxedTypeId(rightOperand); } else { - leftTypeId= getTypeId(leftOperand); + leftTypeId = getTypeId(leftOperand); rightTypeId = getTypeId(rightOperand); } - int resultTypeId = Instruction.getBinaryPromotionType(leftTypeId, rightTypeId); + int resultTypeId = Instruction.getBinaryPromotionType(leftTypeId, + rightTypeId); types[0][0] = resultTypeId; types[0][1] = leftTypeId; types[0][2] = rightTypeId; for (int i = 1; i < operatorNumber; i++) { - Expression operand = (Expression) iterator.next(); + Expression operand = iterator.next(); leftTypeId = resultTypeId; rightTypeId = getUnBoxedTypeId(operand); - resultTypeId = Instruction.getBinaryPromotionType(leftTypeId, rightTypeId); + resultTypeId = Instruction.getBinaryPromotionType(leftTypeId, + rightTypeId); types[i][0] = resultTypeId; types[i][1] = leftTypeId; types[i][2] = rightTypeId; } - boolean unrecognized= false; + boolean unrecognized = false; switch (char0) { - case '*': // multiply + case '*': // multiply + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new MultiplyOperator(types[i][0], types[i][1], + types[i][2], fCounter)); + } + break; + case '/': // divide + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new DivideOperator(types[i][0], types[i][1], types[i][2], + fCounter)); + } + break; + case '%': // remainder + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new RemainderOperator(types[i][0], types[i][1], + types[i][2], fCounter)); + } + break; + case '+': // plus + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new PlusOperator(types[i][0], types[i][1], types[i][2], + fCounter)); + } + break; + case '-': // minus + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new MinusOperator(types[i][0], types[i][1], types[i][2], + fCounter)); + } + break; + case '<': // left shift or less or less equal + switch (char1) { + case '\0': // less for (int i = operatorNumber - 1; i >= 0; i--) { - push(new MultiplyOperator(types[i][0], types[i][1], types[i][2], fCounter)); + push(new LessOperator(types[i][1], types[i][2], fCounter)); } break; - case '/': // divide + case '<': // left shift for (int i = operatorNumber - 1; i >= 0; i--) { - push(new DivideOperator(types[i][0], types[i][1], types[i][2], fCounter)); + push(new LeftShiftOperator( + Instruction.getUnaryPromotionType(types[i][1]), + types[i][1], types[i][2], fCounter)); } break; - case '%': // remainder + case '=': // less equal for (int i = operatorNumber - 1; i >= 0; i--) { - push(new RemainderOperator(types[i][0], types[i][1], types[i][2], fCounter)); + push(new LessEqualOperator(types[i][1], types[i][2], + fCounter)); } break; - case '+': // plus - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new PlusOperator(types[i][0], types[i][1], types[i][2], fCounter)); - } + default: + unrecognized = true; break; - case '-': // minus + } + break; + case '>': // right shift or unsigned right shift or greater or greater + // equal + switch (char1) { + case '\0': // greater for (int i = operatorNumber - 1; i >= 0; i--) { - push(new MinusOperator(types[i][0], types[i][1], types[i][2], fCounter)); - } - break; - case '<': // left shift or less or less equal - switch (char1) { - case '\0': // less - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new LessOperator(types[i][1], types[i][2], fCounter)); - } - break; - case '<': // left shift - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new LeftShiftOperator(Instruction.getUnaryPromotionType(types[i][1]), types[i][1], types[i][2], fCounter)); - } - break; - case '=': // less equal - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new LessEqualOperator(types[i][1], types[i][2], fCounter)); - } - break; - default: - unrecognized= true; - break; + push(new GreaterOperator(types[i][1], types[i][2], fCounter)); } break; - case '>': // right shift or unsigned right shift or greater or greater equal - switch (char1) { - case '\0': // greater - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new GreaterOperator(types[i][1], types[i][2], fCounter)); - } - break; - case '>': // right shift or unsigned right shift - switch (char2) { - case '\0': // right shift - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new RightShiftOperator(Instruction.getUnaryPromotionType(types[i][1]), types[i][1], types[i][2], fCounter)); - } - break; - case '>': // unsigned right shift - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new UnsignedRightShiftOperator(Instruction.getUnaryPromotionType(types[i][1]), types[i][1], types[i][2], fCounter)); - } - break; - } - break; - case '=': // greater equal - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new GreaterEqualOperator(types[i][1], types[i][2], fCounter)); - } - break; - default: - unrecognized= true; - break; + case '>': // right shift or unsigned right shift + switch (char2) { + case '\0': // right shift + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new RightShiftOperator( + Instruction.getUnaryPromotionType(types[i][1]), + types[i][1], types[i][2], fCounter)); + } + break; + case '>': // unsigned right shift + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new UnsignedRightShiftOperator( + Instruction.getUnaryPromotionType(types[i][1]), + types[i][1], types[i][2], fCounter)); + } + break; } break; - case '=': // equal equal + case '=': // greater equal for (int i = operatorNumber - 1; i >= 0; i--) { - push(new EqualEqualOperator(types[i][1], types[i][2], true, fCounter)); + push(new GreaterEqualOperator(types[i][1], types[i][2], + fCounter)); } break; - case '!': // not equal + default: + unrecognized = true; + break; + } + break; + case '=': // equal equal + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new EqualEqualOperator(types[i][1], types[i][2], true, + fCounter)); + } + break; + case '!': // not equal + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new EqualEqualOperator(types[i][1], types[i][2], false, + fCounter)); + } + break; + case '^': // XOr + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new XorOperator(types[i][0], types[i][1], types[i][2], + fCounter)); + } + break; + case '|': // or or or or + switch (char1) { + case '\0': // or for (int i = operatorNumber - 1; i >= 0; i--) { - push(new EqualEqualOperator(types[i][1], types[i][2], false, fCounter)); + push(new OrOperator(types[i][0], types[i][1], types[i][2], + fCounter)); } break; - case '^': // XOr + case '|': // or or for (int i = operatorNumber - 1; i >= 0; i--) { - push(new XorOperator(types[i][0], types[i][1], types[i][2], fCounter)); + push(new NoOp(fCounter)); } break; - case '|': // or or or or - switch (char1) { - case '\0': // or - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new OrOperator(types[i][0], types[i][1], types[i][2], fCounter)); - } - break; - case '|': // or or - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new NoOp(fCounter)); - } - break; - default: - unrecognized= true; - break; + default: + unrecognized = true; + break; + } + break; + case '&': // and or and and + switch (char1) { + case '\0': // and + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new AndOperator(types[i][0], types[i][1], types[i][2], + fCounter)); } break; - case '&': // and or and and - switch (char1) { - case '\0': // and - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new AndOperator(types[i][0], types[i][1], types[i][2], fCounter)); - } - break; - case '&': // and and - for (int i = operatorNumber - 1; i >= 0; i--) { - push(new NoOp(fCounter)); - } - break; - default: - unrecognized= true; - break; + case '&': // and and + for (int i = operatorNumber - 1; i >= 0; i--) { + push(new NoOp(fCounter)); } break; default: - unrecognized= true; + unrecognized = true; break; + } + break; + default: + unrecognized = true; + break; } if (unrecognized) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_infix_operator____13 + opToken); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Unrecognized_infix_operator____13 + + opToken); } if (hasErrors()) { @@ -2527,43 +2720,45 @@ public class ASTInstructionCompiler extends ASTVisitor { iterator = extendedOperands.iterator(); - if ((char0 == '&' && char1 == '&') || (char0 == '|' && char1 == '|')) { // and and operator + if ((char0 == '&' && char1 == '&') || (char0 == '|' && char1 == '|')) { // and + // and + // operator - boolean isOrOr= char0 == '|'; + boolean isOrOr = char0 == '|'; - ConditionalJump[] conditionalJumps= new ConditionalJump[operatorNumber]; + ConditionalJump[] conditionalJumps = new ConditionalJump[operatorNumber]; int[] conditionalJumpAddresses = new int[operatorNumber]; - boolean storeRequired= unBoxing(leftBinding); + boolean storeRequired = unBoxing(leftBinding); leftOperand.accept(this); if (storeRequired) { storeInstruction(); } - ConditionalJump conditionalJump= new ConditionalJump(isOrOr); - conditionalJumps[0]= conditionalJump; + ConditionalJump conditionalJump = new ConditionalJump(isOrOr); + conditionalJumps[0] = conditionalJump; conditionalJumpAddresses[0] = fCounter; push(conditionalJump); storeInstruction(); - storeRequired= unBoxing(rightBinding); + storeRequired = unBoxing(rightBinding); rightOperand.accept(this); if (storeRequired) { storeInstruction(); } - for (int i= 1; i < operatorNumber; i ++) { - conditionalJump= new ConditionalJump(isOrOr); - conditionalJumps[i]= conditionalJump; + for (int i = 1; i < operatorNumber; i++) { + conditionalJump = new ConditionalJump(isOrOr); + conditionalJumps[i] = conditionalJump; conditionalJumpAddresses[i] = fCounter; push(conditionalJump); storeInstruction(); - Expression operand= (Expression) iterator.next(); + Expression operand = iterator.next(); ITypeBinding typeBinding = resolveTypeBinding(operand); if (typeBinding == null) { return false; } - storeRequired= unBoxing(typeBinding); + storeRequired = unBoxing(typeBinding); operand.accept(this); if (storeRequired) { storeInstruction(); @@ -2575,8 +2770,9 @@ public class ASTInstructionCompiler extends ASTVisitor { push(jump); storeInstruction(); - for (int i= 0; i < operatorNumber; i ++) { - conditionalJumps[i].setOffset(fCounter - conditionalJumpAddresses[i] - 1); + for (int i = 0; i < operatorNumber; i++) { + conditionalJumps[i].setOffset(fCounter + - conditionalJumpAddresses[i] - 1); } push(new PushBoolean(isOrOr)); @@ -2587,16 +2783,16 @@ public class ASTInstructionCompiler extends ASTVisitor { } else { // other operators - boolean storeRequired= false; + boolean storeRequired = false; if (unbox) { - storeRequired= unBoxing(leftBinding); + storeRequired = unBoxing(leftBinding); } leftOperand.accept(this); if (storeRequired) { storeInstruction(); } if (unbox) { - storeRequired= unBoxing(rightBinding); + storeRequired = unBoxing(rightBinding); } rightOperand.accept(this); if (storeRequired) { @@ -2604,14 +2800,14 @@ public class ASTInstructionCompiler extends ASTVisitor { } storeInstruction(); - for (int i= 1; i < operatorNumber; i ++) { - Expression operand= (Expression) iterator.next(); + for (int i = 1; i < operatorNumber; i++) { + Expression operand = iterator.next(); if (unbox) { ITypeBinding typeBinding = resolveTypeBinding(operand); if (typeBinding == null) { return false; } - storeRequired= unBoxing(typeBinding); + storeRequired = unBoxing(typeBinding); } operand.accept(this); if (storeRequired) { @@ -2621,14 +2817,13 @@ public class ASTInstructionCompiler extends ASTVisitor { } } - - return false; } /** * @see ASTVisitor#visit(Initializer) */ + @Override public boolean visit(Initializer node) { return true; } @@ -2636,6 +2831,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(InstanceofExpression) */ + @Override public boolean visit(InstanceofExpression node) { if (!isActive()) { return false; @@ -2647,54 +2843,73 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(Javadoc) */ + @Override public boolean visit(Javadoc node) { return false; } /** - * @see ASTVisitor#visit(LabeledStatement) - * return <code>false</code>, don't use the standard accept order. + * @see ASTVisitor#visit(LabeledStatement) return <code>false</code>, don't + * use the standard accept order. */ + @Override public boolean visit(LabeledStatement node) { node.getBody().accept(this); return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.LineComment) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * LineComment) */ + @Override public boolean visit(LineComment node) { return false; } - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MarkerAnnotation) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * MarkerAnnotation) */ + @Override public boolean visit(MarkerAnnotation node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberRef) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberRef + * ) */ + @Override public boolean visit(MemberRef node) { return false; } - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberValuePair) + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * MemberValuePair) */ + @Override public boolean visit(MemberValuePair node) { return false; } - + /** * @see ASTVisitor#visit(MethodDeclaration) */ + @Override public boolean visit(MethodDeclaration node) { - int start= node.getStartPosition(); - int end= start + node.getLength(); + int start = node.getStartPosition(); + int end = start + node.getLength(); if (start < fStartPosition && end > fStartPosition) { return true; } @@ -2703,29 +2918,31 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * return false, don't visit name, visit expression & arguments - * + * * @see ASTVisitor#visit(MethodInvocation) */ + @Override public boolean visit(MethodInvocation node) { if (!isActive()) { return false; } - IMethodBinding methodBinding= (IMethodBinding) node.getName().resolveBinding(); + IMethodBinding methodBinding = (IMethodBinding) node.getName() + .resolveBinding(); if (methodBinding == null) { - // could be the receiver is not visible - for example a private field access from super class + // could be the receiver is not visible - for example a private + // field access from super class ASTNode root = node.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit cu = (CompilationUnit) root; IProblem[] problems = cu.getProblems(); - for (int i = 0; i < problems.length; i++) { - IProblem problem = problems[i]; + for (IProblem problem : problems) { setHasError(true); addErrorMessage(problem.getMessage()); } } } - + if (hasErrors()) { return false; } @@ -2737,75 +2954,89 @@ public class ASTInstructionCompiler extends ASTVisitor { } int paramCount = methodBinding.getParameterTypes().length; - String selector= methodBinding.getName(); + String selector = methodBinding.getName(); - String signature= getMethodSignature(methodBinding, null).replace('.','/'); + String signature = getMethodSignature(methodBinding, null).replace('.', + '/'); - boolean isStatic= Flags.isStatic(methodBinding.getModifiers()); - Expression expression= node.getExpression(); + boolean isStatic = Flags.isStatic(methodBinding.getModifiers()); + Expression expression = node.getExpression(); if (isStatic) { - String typeName= getTypeName(methodBinding.getDeclaringClass()); - push(new SendStaticMessage(typeName, selector, signature, paramCount, fCounter)); + String typeName = getTypeName(methodBinding.getDeclaringClass()); + push(new SendStaticMessage(typeName, selector, signature, + paramCount, fCounter)); if (expression != null) { node.getExpression().accept(this); addPopInstruction(); } } else { - push(new SendMessage(selector, signature, paramCount, null, fCounter)); + push(new SendMessage(selector, signature, paramCount, null, + fCounter)); if (expression == null) { - push(new PushThis(getEnclosingLevel(node, methodBinding.getDeclaringClass()))); + push(new PushThis(getEnclosingLevel(node, + methodBinding.getDeclaringClass()))); storeInstruction(); } else { node.getExpression().accept(this); } } - List arguments = node.arguments(); + List<Expression> arguments = node.arguments(); pushMethodArguments(methodBinding, arguments); return false; } - + /** - * Pushes method arguments onto the stack for a method or constructor invocation taking - * variable arguments and auto-boxing into consideration. + * Pushes method arguments onto the stack for a method or constructor + * invocation taking variable arguments and auto-boxing into consideration. * - * @param methodBinding method or constructor being called - * @param arguments argument list + * @param methodBinding + * method or constructor being called + * @param arguments + * argument list */ - private void pushMethodArguments(IMethodBinding methodBinding, List arguments) { + private void pushMethodArguments(IMethodBinding methodBinding, List<Expression> arguments) { int argCount = arguments.size(); ITypeBinding[] parameterTypes = methodBinding.getParameterTypes(); int paramCount = parameterTypes.length; ITypeBinding lastArgBinding = null; if (methodBinding.isVarargs()) { - Expression lastArg = (Expression)arguments.get(argCount - 1); + Expression lastArg = arguments.get(argCount - 1); lastArgBinding = resolveTypeBinding(lastArg); if (lastArgBinding == null) { return; } } - if (methodBinding.isVarargs() && !(paramCount == argCount && parameterTypes[paramCount - 1].getDimensions() == lastArgBinding.getDimensions())) { - // if this method is a varargs, and if the method is invoked using the varargs syntax + if (methodBinding.isVarargs() + && !(paramCount == argCount && parameterTypes[paramCount - 1] + .getDimensions() == lastArgBinding.getDimensions())) { + // if this method is a varargs, and if the method is invoked using + // the varargs syntax // (multiple arguments) and not an array - Iterator iterator= arguments.iterator(); + Iterator<Expression> iterator = arguments.iterator(); // process the first arguments (no part of the variable argument) - for (int i= 0; i < paramCount - 1; i++) { - Expression argument= (Expression)iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), parameterTypes[i]); + for (int i = 0; i < paramCount - 1; i++) { + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), parameterTypes[i]); argument.accept(this); if (storeRequired) { storeInstruction(); } } // create a array of the remainder arguments - ITypeBinding varargsParameterType= parameterTypes[paramCount - 1]; - ITypeBinding varargsElementType= varargsParameterType.getElementType(); - push(new ArrayInitializerInstruction(getTypeSignature(varargsElementType), argCount - paramCount + 1, varargsParameterType.getDimensions(), fCounter)); + ITypeBinding varargsParameterType = parameterTypes[paramCount - 1]; + ITypeBinding varargsElementType = varargsParameterType + .getElementType(); + push(new ArrayInitializerInstruction( + getTypeSignature(varargsElementType), argCount - paramCount + + 1, varargsParameterType.getDimensions(), fCounter)); while (iterator.hasNext()) { - Expression argument= (Expression) iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), varargsElementType); + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), varargsElementType); argument.accept(this); if (storeRequired) { storeInstruction(); @@ -2813,43 +3044,62 @@ public class ASTInstructionCompiler extends ASTVisitor { } storeInstruction(); } else { - Iterator iterator= arguments.iterator(); - int i= 0; + Iterator<Expression> iterator = arguments.iterator(); + int i = 0; while (iterator.hasNext()) { - Expression argument= (Expression) iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), parameterTypes[i++]); + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), parameterTypes[i++]); argument.accept(this); if (storeRequired) { storeInstruction(); } } - } + } } - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodRef) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodRef + * ) */ + @Override public boolean visit(MethodRef node) { return false; } - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodRefParameter) + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * MethodRefParameter) */ + @Override public boolean visit(MethodRefParameter node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Modifier) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Modifier + * ) */ + @Override public boolean visit(Modifier node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NormalAnnotation) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * NormalAnnotation) */ + @Override public boolean visit(NormalAnnotation node) { return false; } @@ -2857,6 +3107,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(NullLiteral) */ + @Override public boolean visit(NullLiteral node) { if (!isActive()) { return false; @@ -2870,166 +3121,187 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(NumberLiteral) */ + @Override public boolean visit(NumberLiteral node) { if (!isActive()) { return false; } - int literalType= getTypeId(node); - String token= node.getToken(); - int tokenLastCharOffset= token.length() - 1; - char lastChar= token.charAt(tokenLastCharOffset); - String subToken= token.substring(0, tokenLastCharOffset); - + int literalType = getTypeId(node); + String token = node.getToken(); + int tokenLastCharOffset = token.length() - 1; + char lastChar = token.charAt(tokenLastCharOffset); + String subToken = token.substring(0, tokenLastCharOffset); switch (literalType) { - case Instruction.T_byte: - push(new PushInt(parseByteValue(token))); - break; - case Instruction.T_short: - push(new PushInt(parseShortValue(token))); - break; - case Instruction.T_int: - push(new PushInt(parseIntValue(token))); - break; - case Instruction.T_long: - push(new PushLong(parseLongValue(subToken))); - break; - case Instruction.T_float: - push(new PushFloat(Float.parseFloat(removePrefixZerosAndUnderscores(subToken, false)))); - break; - case Instruction.T_double: - if (lastChar == 'D' || lastChar == 'd') { - push(new PushDouble(Double.parseDouble(removePrefixZerosAndUnderscores(subToken, false)))); - } else { - push(new PushDouble(Double.parseDouble(removePrefixZerosAndUnderscores(token, false)))); - } - break; + case Instruction.T_byte: + push(new PushInt(parseByteValue(token))); + break; + case Instruction.T_short: + push(new PushInt(parseShortValue(token))); + break; + case Instruction.T_int: + push(new PushInt(parseIntValue(token))); + break; + case Instruction.T_long: + push(new PushLong(parseLongValue(subToken))); + break; + case Instruction.T_float: + push(new PushFloat( + Float.parseFloat(removePrefixZerosAndUnderscores(subToken, + false)))); + break; + case Instruction.T_double: + if (lastChar == 'D' || lastChar == 'd') { + push(new PushDouble( + Double.parseDouble(removePrefixZerosAndUnderscores( + subToken, false)))); + } else { + push(new PushDouble( + Double.parseDouble(removePrefixZerosAndUnderscores( + token, false)))); + } + break; } return true; } /** - * Removes all preamble typing and underscores and returns the base integer value + * Removes all preamble typing and underscores and returns the base integer + * value * - * @param token the token to parse + * @param token + * the token to parse * @return the int value of the token */ public static int parseIntValue(String token) { token = removePrefixZerosAndUnderscores(token, false); switch (getBase(token)) { - case 8: - return Integer.valueOf(token.substring(1), 8).intValue(); - case 16: - return Integer.valueOf(token.substring(2), 16).intValue(); - case 2: - return Integer.valueOf(token.substring(2), 2).intValue(); - default: - return Integer.valueOf(token, 10).intValue(); + case 8: + return Integer.valueOf(token.substring(1), 8).intValue(); + case 16: + return Integer.valueOf(token.substring(2), 16).intValue(); + case 2: + return Integer.valueOf(token.substring(2), 2).intValue(); + default: + return Integer.valueOf(token, 10).intValue(); } } /** - * Removes all preamble typing and underscores and returns the base short value + * Removes all preamble typing and underscores and returns the base short + * value * - * @param token the token to parse + * @param token + * the token to parse * @return the short value of the token */ public static short parseShortValue(String token) { token = removePrefixZerosAndUnderscores(token, false); switch (getBase(token)) { - case 8: - return Short.valueOf(token.substring(1), 8).shortValue(); - case 16: - return Short.valueOf(token.substring(2), 16).shortValue(); - case 2: - return Short.valueOf(token.substring(2), 2).shortValue(); - default: - return Short.valueOf(token, 10).shortValue(); + case 8: + return Short.valueOf(token.substring(1), 8).shortValue(); + case 16: + return Short.valueOf(token.substring(2), 16).shortValue(); + case 2: + return Short.valueOf(token.substring(2), 2).shortValue(); + default: + return Short.valueOf(token, 10).shortValue(); } } /** - * Removes all preamble typing and underscores and returns the base byte value + * Removes all preamble typing and underscores and returns the base byte + * value * - * @param token the token to parse + * @param token + * the token to parse * @return the byte value of the token */ public static byte parseByteValue(String token) { token = removePrefixZerosAndUnderscores(token, false); switch (getBase(token)) { - case 8: - return Byte.valueOf(token.substring(1), 8).byteValue(); - case 16: - return Byte.valueOf(token.substring(2), 16).byteValue(); - case 2: - return Byte.valueOf(token.substring(2), 2).byteValue(); - default: - return Byte.valueOf(token, 10).byteValue(); + case 8: + return Byte.valueOf(token.substring(1), 8).byteValue(); + case 16: + return Byte.valueOf(token.substring(2), 16).byteValue(); + case 2: + return Byte.valueOf(token.substring(2), 2).byteValue(); + default: + return Byte.valueOf(token, 10).byteValue(); } } - + /** - * Removes all preamble typing and underscores and returns the base long value - * @param token the token to parse + * Removes all preamble typing and underscores and returns the base long + * value + * + * @param token + * the token to parse * @return the long value of the token */ public static long parseLongValue(String token) { token = removePrefixZerosAndUnderscores(token, true); switch (getBase(token)) { - case 8: - return Long.valueOf(token.substring(1), 8).longValue(); - case 16: - return Long.valueOf(token.substring(2), 16).longValue(); - case 2: - return Long.valueOf(token.substring(2), 2).longValue(); - default: - return Long.valueOf(token, 10).longValue(); + case 8: + return Long.valueOf(token.substring(1), 8).longValue(); + case 16: + return Long.valueOf(token.substring(2), 16).longValue(); + case 2: + return Long.valueOf(token.substring(2), 2).longValue(); + default: + return Long.valueOf(token, 10).longValue(); } } /** - * Returns the numeric base for the given token - * according to the Java specification. Returns - * 8, 10, or 16. - * @param token the token to get the base from + * Returns the numeric base for the given token according to the Java + * specification. Returns 8, 10, or 16. + * + * @param token + * the token to get the base from * @return the numeric base for the given token */ public static int getBase(String token) { if (token.charAt(0) == '0' && (token.length() > 1)) { - switch(token.charAt(1)) { - case 'x' : - case 'X' : - // "0x" prefix: Hexadecimal - return 16; - case 'b' : - case 'B' : - // "0b" prefix: binary - return 2; - default : - // "0" prefix: Octal - return 8; + switch (token.charAt(1)) { + case 'x': + case 'X': + // "0x" prefix: Hexadecimal + return 16; + case 'b': + case 'B': + // "0b" prefix: binary + return 2; + default: + // "0" prefix: Octal + return 8; } - } + } return 10; // No prefix: Decimal } /** * @see ASTVisitor#visit(PackageDeclaration) */ + @Override public boolean visit(PackageDeclaration node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ParameterizedType) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * ParameterizedType) */ + @Override public boolean visit(ParameterizedType node) { if (!isActive()) { return false; } - ITypeBinding typeBinding = resolveTypeBinding(node); + ITypeBinding typeBinding = resolveTypeBinding(node); if (typeBinding != null) { push(new PushType(getTypeName(typeBinding))); } @@ -3039,6 +3311,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ParenthesizedExpression) */ + @Override public boolean visit(ParenthesizedExpression node) { if (!isActive()) { return false; @@ -3049,35 +3322,42 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(PostfixExpression) */ + @Override public boolean visit(PostfixExpression node) { if (!isActive()) { return false; } - Expression operand= node.getOperand(); + Expression operand = node.getOperand(); int expressionTypeId = getTypeId(operand); String opToken = node.getOperator().toString(); char char0 = opToken.charAt(0); - + if (expressionTypeId == Instruction.T_Object) { - int expressionUnBoxedTypeId= getUnBoxedTypeId(operand); - - AssignmentOperator assignmentInstruction= new AssignmentOperator(Instruction.T_Object, Instruction.T_Object, fCounter); + int expressionUnBoxedTypeId = getUnBoxedTypeId(operand); + + AssignmentOperator assignmentInstruction = new AssignmentOperator( + Instruction.T_Object, Instruction.T_Object, fCounter); push(assignmentInstruction); operand.accept(this); switch (char0) { - case '+': // plus plus - push(new PlusOperator(expressionUnBoxedTypeId, expressionUnBoxedTypeId, expressionUnBoxedTypeId, fCounter)); - break; - case '-': // minus minus - push(new MinusOperator(expressionUnBoxedTypeId, expressionUnBoxedTypeId, expressionUnBoxedTypeId, fCounter)); - break; - default: - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_postfix_operator____15 + opToken); - return false; + case '+': // plus plus + push(new PlusOperator(expressionUnBoxedTypeId, + expressionUnBoxedTypeId, expressionUnBoxedTypeId, + fCounter)); + break; + case '-': // minus minus + push(new MinusOperator(expressionUnBoxedTypeId, + expressionUnBoxedTypeId, expressionUnBoxedTypeId, + fCounter)); + break; + default: + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_postfix_operator____15 + + opToken); + return false; } push(new Value(fCounter)); push(new Dup()); @@ -3098,22 +3378,22 @@ public class ASTInstructionCompiler extends ASTVisitor { storeInstruction(); // boxing storeInstruction(); // assignment push(new Pop(assignmentInstruction.getSize() + 1)); - - + return false; } switch (char0) { - case '+': // plus plus - push(new PostfixPlusPlusOperator(expressionTypeId, fCounter)); - break; - case '-': // minus minus - push(new PostfixMinusMinusOperator(expressionTypeId, fCounter)); - break; - default: - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_postfix_operator____15 + opToken); - return false; + case '+': // plus plus + push(new PostfixPlusPlusOperator(expressionTypeId, fCounter)); + break; + case '-': // minus minus + push(new PostfixMinusMinusOperator(expressionTypeId, fCounter)); + break; + default: + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_postfix_operator____15 + + opToken); + return false; } return true; @@ -3122,12 +3402,13 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(PrefixExpression) */ + @Override public boolean visit(PrefixExpression node) { if (!isActive()) { return false; } - Expression operand= node.getOperand(); + Expression operand = node.getOperand(); int expressionTypeId = getTypeId(operand); String opToken = node.getOperator().toString(); @@ -3139,118 +3420,127 @@ public class ASTInstructionCompiler extends ASTVisitor { } boolean unrecognized = false; - + if (expressionTypeId == Instruction.T_Object) { - - int expressionUnBoxedTypeId= getUnBoxedTypeId(operand); - + + int expressionUnBoxedTypeId = getUnBoxedTypeId(operand); + ITypeBinding typeBinding = resolveTypeBinding(operand); if (typeBinding == null) { return false; } if (char1 == '\0') { switch (char0) { - case '+': // unary plus - push(new UnaryPlusOperator(expressionUnBoxedTypeId, fCounter)); - break; - case '-': // unary minus - push(new UnaryMinusOperator(expressionUnBoxedTypeId, fCounter)); - break; - case '~': // twiddle - push(new TwiddleOperator(expressionUnBoxedTypeId, fCounter)); - break; - case '!': // not - push(new NotOperator(expressionUnBoxedTypeId, fCounter)); - break; - default: - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + opToken); - return false; + case '+': // unary plus + push(new UnaryPlusOperator(expressionUnBoxedTypeId, + fCounter)); + break; + case '-': // unary minus + push(new UnaryMinusOperator(expressionUnBoxedTypeId, + fCounter)); + break; + case '~': // twiddle + push(new TwiddleOperator(expressionUnBoxedTypeId, fCounter)); + break; + case '!': // not + push(new NotOperator(expressionUnBoxedTypeId, fCounter)); + break; + default: + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + + opToken); + return false; } - + unBoxing(typeBinding); operand.accept(this); storeInstruction(); // un-boxing - + } else { // plus plus and minus minus operators - - push(new AssignmentOperator(Instruction.T_Object, Instruction.T_Object, fCounter)); - + + push(new AssignmentOperator(Instruction.T_Object, + Instruction.T_Object, fCounter)); + operand.accept(this); - + boxing(typeBinding, null); - + switch (char1) { - case '+': - push(new PlusOperator(expressionUnBoxedTypeId, expressionUnBoxedTypeId, expressionUnBoxedTypeId, fCounter)); - break; - case '-': - push(new MinusOperator(expressionUnBoxedTypeId, expressionUnBoxedTypeId, expressionUnBoxedTypeId, fCounter)); - break; - default: - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + opToken); - return false; + case '+': + push(new PlusOperator(expressionUnBoxedTypeId, + expressionUnBoxedTypeId, expressionUnBoxedTypeId, + fCounter)); + break; + case '-': + push(new MinusOperator(expressionUnBoxedTypeId, + expressionUnBoxedTypeId, expressionUnBoxedTypeId, + fCounter)); + break; + default: + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + + opToken); + return false; } - + unBoxing(typeBinding); push(new Dup()); storeInstruction(); // dupe storeInstruction(); // un-boxing push(new PushInt(1)); storeInstruction(); // push 1 - + storeInstruction(); // operator storeInstruction(); // boxing - + } - + return false; } - + switch (char0) { - case '+': // plus plus or unary plus - switch (char1) { - case '\0': // unary plus - push(new UnaryPlusOperator(expressionTypeId, fCounter)); - break; - case '+': // plus plus - push(new PrefixPlusPlusOperator(expressionTypeId, fCounter)); - break; - default: - unrecognized= true; - break; - } + case '+': // plus plus or unary plus + switch (char1) { + case '\0': // unary plus + push(new UnaryPlusOperator(expressionTypeId, fCounter)); break; - case '-': // minus minus or unary minus - switch (char1) { - case '\0': // unary minus - push(new UnaryMinusOperator(expressionTypeId, fCounter)); - break; - case '-': // minus minus - push(new PrefixMinusMinusOperator(expressionTypeId, fCounter)); - break; - default: - unrecognized= true; - break; - } + case '+': // plus plus + push(new PrefixPlusPlusOperator(expressionTypeId, fCounter)); break; - case '~': // twiddle - push(new TwiddleOperator(expressionTypeId, fCounter)); + default: + unrecognized = true; + break; + } + break; + case '-': // minus minus or unary minus + switch (char1) { + case '\0': // unary minus + push(new UnaryMinusOperator(expressionTypeId, fCounter)); break; - case '!': // not - push(new NotOperator(expressionTypeId, fCounter)); + case '-': // minus minus + push(new PrefixMinusMinusOperator(expressionTypeId, fCounter)); break; default: - unrecognized= true; + unrecognized = true; break; + } + break; + case '~': // twiddle + push(new TwiddleOperator(expressionTypeId, fCounter)); + break; + case '!': // not + push(new NotOperator(expressionTypeId, fCounter)); + break; + default: + unrecognized = true; + break; } - if (unrecognized) { setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + opToken); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_unrecognized_prefix_operator____16 + + opToken); return false; } @@ -3260,11 +3550,12 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(PrimitiveType) */ + @Override public boolean visit(PrimitiveType node) { if (!isActive()) { return false; } - ITypeBinding typeBinding = resolveTypeBinding(node); + ITypeBinding typeBinding = resolveTypeBinding(node); if (typeBinding != null) { push(new PushPrimitiveType(getTypeName(typeBinding))); } @@ -3274,6 +3565,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(QualifiedName) */ + @Override public boolean visit(QualifiedName node) { if (!isActive()) { return false; @@ -3288,43 +3580,50 @@ public class ASTInstructionCompiler extends ASTVisitor { return false; } switch (binding.getKind()) { - case IBinding.TYPE: - node.getName().accept(this); - break; - case IBinding.VARIABLE: - SimpleName fieldName= node.getName(); - IVariableBinding fieldBinding= (IVariableBinding) resolveBinding(fieldName); - if (fieldBinding == null) { - return false; - } - ITypeBinding declaringTypeBinding= fieldBinding.getDeclaringClass(); - String fieldId = fieldName.getIdentifier(); + case IBinding.TYPE: + node.getName().accept(this); + break; + case IBinding.VARIABLE: + SimpleName fieldName = node.getName(); + IVariableBinding fieldBinding = (IVariableBinding) resolveBinding(fieldName); + if (fieldBinding == null) { + return false; + } + ITypeBinding declaringTypeBinding = fieldBinding + .getDeclaringClass(); + String fieldId = fieldName.getIdentifier(); - if (Modifier.isStatic(fieldBinding.getModifiers())) { - push(new PushStaticFieldVariable(fieldId, getTypeName(declaringTypeBinding), fCounter)); + if (Modifier.isStatic(fieldBinding.getModifiers())) { + push(new PushStaticFieldVariable(fieldId, + getTypeName(declaringTypeBinding), fCounter)); + } else { + if (declaringTypeBinding == null) { + push(new PushArrayLength(fCounter)); } else { - if (declaringTypeBinding == null) { - push(new PushArrayLength(fCounter)); - } else { - push(new PushFieldVariable(fieldId, getTypeSignature(declaringTypeBinding), fCounter)); - } - node.getQualifier().accept(this); + push(new PushFieldVariable(fieldId, + getTypeSignature(declaringTypeBinding), fCounter)); } - storeInstruction(); - break; + node.getQualifier().accept(this); + } + storeInstruction(); + break; } return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.QualifiedType) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * QualifiedType) */ + @Override public boolean visit(QualifiedType node) { if (!isActive()) { return false; } - ITypeBinding typeBinding = resolveTypeBinding(node); + ITypeBinding typeBinding = resolveTypeBinding(node); if (typeBinding != null) { push(new PushType(getTypeName(typeBinding))); } @@ -3334,6 +3633,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ReturnStatement) */ + @Override public boolean visit(ReturnStatement node) { if (!isActive()) { return false; @@ -3345,6 +3645,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(SimpleName) */ + @Override public boolean visit(SimpleName node) { if (!isActive()) { return false; @@ -3361,74 +3662,86 @@ public class ASTInstructionCompiler extends ASTVisitor { String variableId = node.getIdentifier(); switch (binding.getKind()) { - case IBinding.TYPE: - ITypeBinding typeBinding= (ITypeBinding) binding; - push(new PushType(getTypeName(typeBinding))); - break; - case IBinding.VARIABLE: - IVariableBinding variableBinding= (IVariableBinding) binding; - ITypeBinding declaringTypeBinding= variableBinding.getDeclaringClass(); - if (variableBinding.isField()) { - if (Modifier.isStatic(variableBinding.getModifiers())) { - push(new PushStaticFieldVariable(variableId, getTypeName(declaringTypeBinding), fCounter)); - } else { - if (isALocalType(declaringTypeBinding)) { - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_36); - return false; - } - push(new PushFieldVariable(variableId, getTypeSignature(declaringTypeBinding), fCounter)); - push(new PushThis(getEnclosingLevel(node, declaringTypeBinding))); - storeInstruction(); - } + case IBinding.TYPE: + ITypeBinding typeBinding = (ITypeBinding) binding; + push(new PushType(getTypeName(typeBinding))); + break; + case IBinding.VARIABLE: + IVariableBinding variableBinding = (IVariableBinding) binding; + ITypeBinding declaringTypeBinding = variableBinding + .getDeclaringClass(); + if (variableBinding.isField()) { + if (Modifier.isStatic(variableBinding.getModifiers())) { + push(new PushStaticFieldVariable(variableId, + getTypeName(declaringTypeBinding), fCounter)); } else { - push(new PushLocalVariable(variableId)); + if (isALocalType(declaringTypeBinding)) { + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_36); + return false; + } + push(new PushFieldVariable(variableId, + getTypeSignature(declaringTypeBinding), fCounter)); + push(new PushThis(getEnclosingLevel(node, + declaringTypeBinding))); + storeInstruction(); } - break; + } else { + push(new PushLocalVariable(variableId)); + } + break; } return true; } /** * return false, don't visit child - * + * * @see ASTVisitor#visit(SimpleType) */ + @Override public boolean visit(SimpleType node) { if (!isActive()) { return false; } - ITypeBinding typeBinding = resolveTypeBinding(node); + ITypeBinding typeBinding = resolveTypeBinding(node); if (typeBinding != null) { push(new PushType(getTypeName(typeBinding))); } return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * SingleMemberAnnotation) */ + @Override public boolean visit(SingleMemberAnnotation node) { return false; } - + /** - * @see ASTVisitor#visit(SingleVariableDeclaration) - * return <code>false</code>, don't use the standard accept order. + * @see ASTVisitor#visit(SingleVariableDeclaration) return + * <code>false</code>, don't use the standard accept order. */ + @Override public boolean visit(SingleVariableDeclaration node) { if (!isActive()) { return false; } - ITypeBinding typeBinding= resolveTypeBinding(node.getType()); + ITypeBinding typeBinding = resolveTypeBinding(node.getType()); if (typeBinding != null) { - int typeDimension= typeBinding.getDimensions(); + int typeDimension = typeBinding.getDimensions(); if (typeDimension != 0) { - typeBinding= typeBinding.getElementType(); + typeBinding = typeBinding.getElementType(); } - Expression initializer= node.getInitializer(); - push(new LocalVariableCreation(node.getName().getIdentifier(), getTypeSignature(typeBinding), typeDimension, typeBinding.isPrimitive(), initializer != null, fCounter)); + Expression initializer = node.getInitializer(); + push(new LocalVariableCreation(node.getName().getIdentifier(), + getTypeSignature(typeBinding), typeDimension, + typeBinding.isPrimitive(), initializer != null, fCounter)); if (initializer != null) { initializer.accept(this); } @@ -3439,6 +3752,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(StringLiteral) */ + @Override public boolean visit(StringLiteral node) { if (!isActive()) { return false; @@ -3452,48 +3766,51 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(SuperConstructorInvocation) */ + @Override public boolean visit(SuperConstructorInvocation node) { if (!isActive()) { return false; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_super_constructor_invocation_cannot_be_used_in_an_evaluation_expression_19); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_super_constructor_invocation_cannot_be_used_in_an_evaluation_expression_19); return false; } /** * @see ASTVisitor#visit(SuperFieldAccess) */ + @Override public boolean visit(SuperFieldAccess node) { if (!isActive()) { return false; } - SimpleName fieldName= node.getName(); - IVariableBinding fieldBinding= (IVariableBinding) resolveBinding(fieldName); + SimpleName fieldName = node.getName(); + IVariableBinding fieldBinding = (IVariableBinding) resolveBinding(fieldName); if (fieldBinding == null) { return false; } - ITypeBinding declaringTypeBinding= fieldBinding.getDeclaringClass(); + ITypeBinding declaringTypeBinding = fieldBinding.getDeclaringClass(); String fieldId = fieldName.getIdentifier(); if (Modifier.isStatic(fieldBinding.getModifiers())) { - push(new PushStaticFieldVariable(fieldId, getTypeName(declaringTypeBinding), fCounter)); + push(new PushStaticFieldVariable(fieldId, + getTypeName(declaringTypeBinding), fCounter)); } else { Name qualifier = node.getQualifier(); - int superLevel= 1; - int enclosingLevel= 0; + int superLevel = 1; + int enclosingLevel = 0; if (qualifier != null) { ITypeBinding typeBinding = resolveTypeBinding(qualifier); if (typeBinding == null) { return false; } - superLevel= getSuperLevel(typeBinding, declaringTypeBinding); - ITypeBinding binding = (ITypeBinding)resolveBinding(qualifier); + superLevel = getSuperLevel(typeBinding, declaringTypeBinding); + ITypeBinding binding = (ITypeBinding) resolveBinding(qualifier); if (binding == null) { return false; } - enclosingLevel= getEnclosingLevel(node, binding); + enclosingLevel = getEnclosingLevel(node, binding); } push(new PushFieldVariable(fieldId, superLevel, fCounter)); push(new PushThis(enclosingLevel)); @@ -3505,15 +3822,17 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * return false, don't visit name, visit arguments - * + * * @see ASTVisitor#visit(SuperMethodInvocation) */ + @Override public boolean visit(SuperMethodInvocation node) { if (!isActive()) { return false; } - IMethodBinding methodBinding = (IMethodBinding) resolveBinding(node.getName()); + IMethodBinding methodBinding = (IMethodBinding) resolveBinding(node + .getName()); if (methodBinding == null) { return false; } @@ -3529,52 +3848,64 @@ public class ASTInstructionCompiler extends ASTVisitor { String selector = methodBinding.getName(); String signature = getMethodSignature(methodBinding, null); - Name qualifier= node.getQualifier(); + Name qualifier = node.getQualifier(); if (Modifier.isStatic(methodBinding.getModifiers())) { - push(new SendStaticMessage(getTypeName(methodBinding.getDeclaringClass()), selector, signature, paramCount, fCounter)); + push(new SendStaticMessage( + getTypeName(methodBinding.getDeclaringClass()), selector, + signature, paramCount, fCounter)); } else { - push(new SendMessage(selector, signature, paramCount, getTypeSignature(methodBinding.getDeclaringClass()), fCounter)); - int enclosingLevel= 0; + push(new SendMessage(selector, signature, paramCount, + getTypeSignature(methodBinding.getDeclaringClass()), + fCounter)); + int enclosingLevel = 0; if (qualifier != null) { - ITypeBinding typeBinding = (ITypeBinding)resolveBinding(qualifier); + ITypeBinding typeBinding = (ITypeBinding) resolveBinding(qualifier); if (typeBinding == null) { return false; } - enclosingLevel= getEnclosingLevel(node, typeBinding); + enclosingLevel = getEnclosingLevel(node, typeBinding); } push(new PushThis(enclosingLevel)); storeInstruction(); } - List arguments = node.arguments(); + List<Expression> arguments = node.arguments(); int argCount = arguments.size(); ITypeBinding lastArgBinding = null; if (methodBinding.isVarargs()) { - lastArgBinding = resolveTypeBinding((Expression)arguments.get(argCount - 1)); + lastArgBinding = resolveTypeBinding(arguments.get(argCount - 1)); if (lastArgBinding == null) { return false; } } - if (methodBinding.isVarargs() && !(paramCount == argCount && parameterTypes[paramCount - 1].getDimensions() == lastArgBinding.getDimensions())) { - // if this method is a varargs, and if the method is invoked using the varargs syntax + if (methodBinding.isVarargs() + && !(paramCount == argCount && parameterTypes[paramCount - 1] + .getDimensions() == lastArgBinding.getDimensions())) { + // if this method is a varargs, and if the method is invoked using + // the varargs syntax // (multiple arguments) and not an array - Iterator iterator= arguments.iterator(); + Iterator<Expression> iterator = arguments.iterator(); // process the first arguments (no part of the variable argument) - for (int i= 0; i < paramCount - 1; i++) { - Expression argument= (Expression) iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), parameterTypes[i]); + for (int i = 0; i < paramCount - 1; i++) { + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), parameterTypes[i]); argument.accept(this); if (storeRequired) { storeInstruction(); } } // create a array of the remainder arguments - ITypeBinding varargsParameterType= parameterTypes[paramCount - 1]; - ITypeBinding varargsElementType= varargsParameterType.getElementType(); - push(new ArrayInitializerInstruction(getTypeSignature(varargsElementType), argCount - paramCount + 1, varargsParameterType.getDimensions(), fCounter)); + ITypeBinding varargsParameterType = parameterTypes[paramCount - 1]; + ITypeBinding varargsElementType = varargsParameterType + .getElementType(); + push(new ArrayInitializerInstruction( + getTypeSignature(varargsElementType), argCount - paramCount + + 1, varargsParameterType.getDimensions(), fCounter)); while (iterator.hasNext()) { - Expression argument= (Expression) iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), varargsElementType); + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), varargsElementType); argument.accept(this); if (storeRequired) { storeInstruction(); @@ -3582,17 +3913,18 @@ public class ASTInstructionCompiler extends ASTVisitor { } storeInstruction(); } else { - Iterator iterator= arguments.iterator(); - int i= 0; + Iterator<Expression> iterator = arguments.iterator(); + int i = 0; while (iterator.hasNext()) { - Expression argument= (Expression) iterator.next(); - boolean storeRequired= checkAutoBoxing(argument.resolveTypeBinding(), parameterTypes[i++]); + Expression argument = iterator.next(); + boolean storeRequired = checkAutoBoxing( + argument.resolveTypeBinding(), parameterTypes[i++]); argument.accept(this); if (storeRequired) { storeInstruction(); } } - } + } return false; } @@ -3600,117 +3932,131 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(SwitchCase) */ + @Override public boolean visit(SwitchCase node) { // never called return false; } + class slot { + ArrayList<ConditionalJump> jumps = new ArrayList<ConditionalJump>(); + ArrayList<Statement> stmts = null; + } + /** * @see ASTVisitor#visit(SwitchStatement) */ + @Override public boolean visit(SwitchStatement node) { if (!isActive()) { return false; } push(new NoOp(fCounter)); - int switchStart= fCounter; + int switchStart = fCounter; node.getExpression().accept(this); - - ArrayList statementsDefault= null; - Jump jumpDefault= null; - ArrayList jumpsStatements= new ArrayList(); - ArrayList[] currentJumpsStatements= new ArrayList[] {new ArrayList(), null}; - jumpsStatements.add(currentJumpsStatements); - - for (Iterator iter= node.statements().iterator(); iter.hasNext();) { - Statement statement= (Statement) iter.next(); + + ArrayList<Statement> statementsDefault = null; + Jump jumpDefault = null; + ArrayList<slot> jumpsStatements = new ArrayList<slot>(); + slot currentslot = new slot(); + jumpsStatements.add(currentslot); + + for (Iterator<Statement> iter = node.statements().iterator(); iter.hasNext();) { + Statement statement = iter.next(); if (statement instanceof SwitchCase) { - SwitchCase switchCase= (SwitchCase) statement; + SwitchCase switchCase = (SwitchCase) statement; if (switchCase.isDefault()) { - jumpDefault= new Jump(); + jumpDefault = new Jump(); push(jumpDefault); storeInstruction(); // jump - statementsDefault= new ArrayList(); + statementsDefault = new ArrayList<Statement>(); } else { - if(switchCase.getExpression() instanceof StringLiteral) { - push(new SendMessage("equals", "(Ljava/lang/Object;)Z", 1, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - push(new EqualEqualOperator(Instruction.T_int, Instruction.T_int, true, fCounter)); + if (switchCase.getExpression() instanceof StringLiteral) { + push(new SendMessage( + "equals", "(Ljava/lang/Object;)Z", 1, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + push(new EqualEqualOperator(Instruction.T_int, + Instruction.T_int, true, fCounter)); } push(new Dup()); storeInstruction(); // dupe switchCase.getExpression().accept(this); storeInstruction(); // equal-equal - ConditionalJump condJump= new ConditionalJump(true); + ConditionalJump condJump = new ConditionalJump(true); push(condJump); storeInstruction(); // conditional jump - if (currentJumpsStatements[1] != null) { - currentJumpsStatements= new ArrayList[] {new ArrayList(), null}; - jumpsStatements.add(currentJumpsStatements); + if (currentslot.stmts != null) { + currentslot = new slot(); + jumpsStatements.add(currentslot); } - currentJumpsStatements[0].add(condJump); + currentslot.jumps.add(condJump); } } else { if (statementsDefault != null) { statementsDefault.add(statement); } else { - if (currentJumpsStatements[1] == null) { - currentJumpsStatements[1]= new ArrayList(); + if (currentslot.stmts == null) { + currentslot.stmts = new ArrayList<Statement>(); } - currentJumpsStatements[1].add(statement); + currentslot.stmts.add(statement); } } } - - Jump jumpEnd= null; + + Jump jumpEnd = null; if (jumpDefault == null) { push(new Pop(0)); storeInstruction(); // pop - jumpEnd= new Jump(); + jumpEnd = new Jump(); push(jumpEnd); storeInstruction(); // jump } - - for (Iterator iter= jumpsStatements.iterator(); iter.hasNext();) { - currentJumpsStatements= (ArrayList[]) iter.next(); - for (Iterator iterator= currentJumpsStatements[0].iterator(); iterator.hasNext();) { - ConditionalJump condJump= (ConditionalJump) iterator.next(); + + for (Iterator<slot> iter = jumpsStatements.iterator(); iter.hasNext();) { + currentslot = iter.next(); + for (Iterator<ConditionalJump> iterator = currentslot.jumps.iterator(); iterator.hasNext();) { + ConditionalJump condJump = iterator.next(); condJump.setOffset((fCounter - fInstructions.indexOf(condJump)) - 1); } - if (currentJumpsStatements[1] != null) { + if (currentslot.stmts != null) { push(new Pop(0)); storeInstruction(); // pop - for (Iterator iterator= currentJumpsStatements[1].iterator(); iterator.hasNext();) { - ((Statement) iterator.next()).accept(this); + for (Iterator<Statement> iterator = currentslot.stmts.iterator(); iterator.hasNext();) { + iterator.next().accept(this); } } } - + // default case if (jumpDefault != null) { - jumpDefault.setOffset((fCounter - fInstructions.indexOf(jumpDefault)) - 1); + jumpDefault.setOffset((fCounter - fInstructions + .indexOf(jumpDefault)) - 1); push(new Pop(0)); storeInstruction(); // pop - for (Iterator iterator= statementsDefault.iterator(); iterator.hasNext();) { - ((Statement) iterator.next()).accept(this); + for (Iterator<Statement> iterator = statementsDefault.iterator(); iterator + .hasNext();) { + iterator.next().accept(this); } } else { jumpEnd.setOffset((fCounter - fInstructions.indexOf(jumpEnd)) - 1); } - + // for each pending break or continue instruction which are related to // this loop, set the offset of the corresponding jump. - String label= getLabel(node); - for (Iterator iter= fCompleteInstructions.iterator(); iter.hasNext();) { - CompleteInstruction instruction= (CompleteInstruction) iter.next(); - Jump jumpInstruction= instruction.fInstruction; - int instructionAddress= fInstructions.indexOf(jumpInstruction); - if (instructionAddress > switchStart && (instruction.fLabel == null || instruction.fLabel.equals(label))) { + String label = getLabel(node); + for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) { + CompleteInstruction instruction = iter.next(); + Jump jumpInstruction = instruction.fInstruction; + int instructionAddress = fInstructions.indexOf(jumpInstruction); + if (instructionAddress > switchStart + && (instruction.fLabel == null || instruction.fLabel + .equals(label))) { iter.remove(); if (instruction.fIsBreak) { - // jump to the instruction after the last instruction of the switch - jumpInstruction.setOffset((fCounter - instructionAddress) - 1); + // jump to the instruction after the last instruction of the + // switch + jumpInstruction + .setOffset((fCounter - instructionAddress) - 1); } } } @@ -3720,6 +4066,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(SynchronizedStatement) */ + @Override public boolean visit(SynchronizedStatement node) { if (!isActive()) { return false; @@ -3727,16 +4074,25 @@ public class ASTInstructionCompiler extends ASTVisitor { return true; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TagElement) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TagElement + * ) */ + @Override public boolean visit(TagElement node) { return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TextElement) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * TextElement) */ + @Override public boolean visit(TextElement node) { return false; } @@ -3744,19 +4100,20 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ThisExpression) */ + @Override public boolean visit(ThisExpression node) { if (!isActive()) { return false; } - Name qualifier= node.getQualifier(); - int enclosingLevel= 0; + Name qualifier = node.getQualifier(); + int enclosingLevel = 0; if (qualifier != null) { - ITypeBinding binding = (ITypeBinding)resolveBinding(qualifier); + ITypeBinding binding = (ITypeBinding) resolveBinding(qualifier); if (binding == null) { return false; } - enclosingLevel= getEnclosingLevel(node, binding); + enclosingLevel = getEnclosingLevel(node, binding); } push(new PushThis(enclosingLevel)); @@ -3766,6 +4123,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(ThrowStatement) */ + @Override public boolean visit(ThrowStatement node) { if (!isActive()) { return false; @@ -3777,42 +4135,49 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(TryStatement) */ + @Override public boolean visit(TryStatement node) { if (!isActive()) { return false; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Try_statement_cannot_be_used_in_an_evaluation_expression_23); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Try_statement_cannot_be_used_in_an_evaluation_expression_23); return false; } /** * @see ASTVisitor#visit(TypeDeclaration) */ + @Override public boolean visit(TypeDeclaration node) { if (!isActive()) { return true; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Type_declaration_cannot_be_used_in_an_evaluation_expression_24); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Type_declaration_cannot_be_used_in_an_evaluation_expression_24); return false; } /** * @see ASTVisitor#visit(TypeDeclarationStatement) */ + @Override public boolean visit(TypeDeclarationStatement node) { if (!isActive()) { return true; } setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Type_declaration_statement_cannot_be_used_in_an_evaluation_expression_25); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Type_declaration_statement_cannot_be_used_in_an_evaluation_expression_25); return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeParameter) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * TypeParameter) */ + @Override public boolean visit(TypeParameter node) { return false; } @@ -3820,6 +4185,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(TypeLiteral) */ + @Override public boolean visit(TypeLiteral node) { if (!isActive()) { return false; @@ -3833,17 +4199,19 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationExpression) */ + @Override public boolean visit(VariableDeclarationExpression node) { - /* if it is in the code to execute, return <code>false</code>, - * we don't use the standard accept order. - * Otherwise, return true. We want to search the code to execute - * in variable declarations (in case of inner classes). + /* + * if it is in the code to execute, return <code>false</code>, we don't + * use the standard accept order. Otherwise, return true. We want to + * search the code to execute in variable declarations (in case of inner + * classes). */ if (!isActive()) { return true; } - for (Iterator iter= node.fragments().iterator(); iter.hasNext();) { - ((VariableDeclarationFragment) iter.next()).accept(this); + for (Iterator<VariableDeclarationFragment> iter = node.fragments().iterator(); iter.hasNext();) { + iter.next().accept(this); } return false; } @@ -3851,41 +4219,47 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationFragment) */ + @Override public boolean visit(VariableDeclarationFragment node) { - /* if it is in the code to execute, return <code>false</code>, - * we don't use the standard accept order. - * Otherwise, return true. We want to search the code to execute - * in variable declarations (in case of inner classes). + /* + * if it is in the code to execute, return <code>false</code>, we don't + * use the standard accept order. Otherwise, return true. We want to + * search the code to execute in variable declarations (in case of inner + * classes). */ if (!isActive()) { return true; } // get the type of the variable ITypeBinding varTypeBinding; - ASTNode parent= node.getParent(); + ASTNode parent = node.getParent(); switch (parent.getNodeType()) { - case ASTNode.VARIABLE_DECLARATION_EXPRESSION: - varTypeBinding= resolveTypeBinding(((VariableDeclarationExpression)parent).getType()); - break; - case ASTNode.VARIABLE_DECLARATION_STATEMENT: - varTypeBinding= resolveTypeBinding(((VariableDeclarationStatement)parent).getType()); - break; - default: - setHasError(true); - addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Error_in_type_declaration_statement); - return false; + case ASTNode.VARIABLE_DECLARATION_EXPRESSION: + varTypeBinding = resolveTypeBinding(((VariableDeclarationExpression) parent) + .getType()); + break; + case ASTNode.VARIABLE_DECLARATION_STATEMENT: + varTypeBinding = resolveTypeBinding(((VariableDeclarationStatement) parent) + .getType()); + break; + default: + setHasError(true); + addErrorMessage(EvaluationEngineMessages.ASTInstructionCompiler_Error_in_type_declaration_statement); + return false; } if (varTypeBinding == null) { return false; } - int typeDimension= varTypeBinding.getDimensions(); + int typeDimension = varTypeBinding.getDimensions(); ITypeBinding elementBinding = varTypeBinding; if (typeDimension != 0) { - elementBinding= elementBinding.getElementType(); + elementBinding = elementBinding.getElementType(); } - Expression initializer= node.getInitializer(); - push(new LocalVariableCreation(node.getName().getIdentifier(), getTypeSignature(elementBinding), typeDimension, elementBinding.isPrimitive(), initializer != null, fCounter)); + Expression initializer = node.getInitializer(); + push(new LocalVariableCreation(node.getName().getIdentifier(), + getTypeSignature(elementBinding), typeDimension, + elementBinding.isPrimitive(), initializer != null, fCounter)); if (initializer != null) { initializer.accept(this); ITypeBinding expBindnig = initializer.resolveTypeBinding(); @@ -3902,24 +4276,30 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationStatement) */ + @Override public boolean visit(VariableDeclarationStatement node) { - /* if it is in the code to execute, return <code>false</code>, - * we don't use the standard accept order. - * Otherwise, return true. We want to search the code to execute - * in variable declarations (in case of inner classes). + /* + * if it is in the code to execute, return <code>false</code>, we don't + * use the standard accept order. Otherwise, return true. We want to + * search the code to execute in variable declarations (in case of inner + * classes). */ if (!isActive()) { return true; } - for (Iterator iter= node.fragments().iterator(); iter.hasNext();) { - ((VariableDeclarationFragment) iter.next()).accept(this); + for (Iterator<VariableDeclarationFragment> iter = node.fragments().iterator(); iter.hasNext();) { + iter.next().accept(this); } return false; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.WildcardType) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * WildcardType) */ + @Override public boolean visit(WildcardType node) { // we shouldn't have to do anything return false; @@ -3928,6 +4308,7 @@ public class ASTInstructionCompiler extends ASTVisitor { /** * @see ASTVisitor#visit(WhileStatement) */ + @Override public boolean visit(WhileStatement node) { if (!isActive()) { return false; @@ -3937,7 +4318,7 @@ public class ASTInstructionCompiler extends ASTVisitor { return true; } - //-------------------------- + // -------------------------- private int getTypeId(Expression expression) { ITypeBinding typeBinding = expression.resolveTypeBinding(); @@ -3947,7 +4328,7 @@ public class ASTInstructionCompiler extends ASTVisitor { String typeName = typeBinding.getQualifiedName(); if (typeBinding.isPrimitive()) { return getPrimitiveTypeId(typeName); - } else if ("java.lang.String".equals(typeName)){ //$NON-NLS-1$ + } else if ("java.lang.String".equals(typeName)) { //$NON-NLS-1$ return Instruction.T_String; } else { return Instruction.T_Object; @@ -3962,7 +4343,7 @@ public class ASTInstructionCompiler extends ASTVisitor { String typeName = typeBinding.getQualifiedName(); if (typeBinding.isPrimitive()) { return getPrimitiveTypeId(typeName); - } else if ("java.lang.String".equals(typeName)){ //$NON-NLS-1$ + } else if ("java.lang.String".equals(typeName)) { //$NON-NLS-1$ return Instruction.T_String; } else { // un-boxing @@ -3989,12 +4370,13 @@ public class ASTInstructionCompiler extends ASTVisitor { private int getTypeId(Type type) { if (type.isPrimitiveType()) { - return getPrimitiveTypeId(((PrimitiveType)type).getPrimitiveTypeCode().toString()); + return getPrimitiveTypeId(((PrimitiveType) type) + .getPrimitiveTypeCode().toString()); } else if (type.isSimpleType()) { SimpleType simpleType = (SimpleType) type; - if ("java.lang.String".equals(simpleType.getName().getFullyQualifiedName())){ //$NON-NLS-1$ + if ("java.lang.String".equals(simpleType.getName().getFullyQualifiedName())) { //$NON-NLS-1$ return Instruction.T_String; - } + } return Instruction.T_Object; } else if (type.isArrayType()) { return Instruction.T_Object; @@ -4004,7 +4386,8 @@ public class ASTInstructionCompiler extends ASTVisitor { } - public static String removePrefixZerosAndUnderscores(String tokenString, boolean isLong) { + public static String removePrefixZerosAndUnderscores(String tokenString, + boolean isLong) { char[] token = tokenString.toCharArray(); int max = token.length; int start = 0; @@ -4025,18 +4408,18 @@ public class ASTInstructionCompiler extends ASTVisitor { boolean ignore = true; loop: for (int i = start; i < max; i++) { char currentChar = token[i]; - switch(currentChar) { - case '0' : - // this is a prefix '0' - if (ignore && !modified && (i < end)) { - modified = true; - } - break; - case '_' : + switch (currentChar) { + case '0': + // this is a prefix '0' + if (ignore && !modified && (i < end)) { modified = true; - break loop; - default : - ignore = false; + } + break; + case '_': + modified = true; + break loop; + default: + ignore = false; } } if (!modified) { @@ -4047,17 +4430,17 @@ public class ASTInstructionCompiler extends ASTVisitor { buffer.append(token, 0, start); loop: for (int i = start; i < max; i++) { char currentChar = token[i]; - switch(currentChar) { - case '0' : - if (ignore && (i < end)) { - // this is a prefix '0' - continue loop; - } - break; - case '_' : + switch (currentChar) { + case '0': + if (ignore && (i < end)) { + // this is a prefix '0' continue loop; - default: - ignore = false; + } + break; + case '_': + continue loop; + default: + ignore = false; } buffer.append(currentChar); } @@ -4065,123 +4448,142 @@ public class ASTInstructionCompiler extends ASTVisitor { } /** - * Returns the method signature given the binding and the enclosing type signature (if there is one) - * @param methodBinding the binding to get the signature for - * @param enclosingTypeSignature the enclosing type signature or <code>null</code> - * @return the method signature for the given binding and enclosing type signature - */ - private String getMethodSignature(IMethodBinding methodBinding, String enclosingTypeSignature) { - methodBinding= methodBinding.getMethodDeclaration(); + * Returns the method signature given the binding and the enclosing type + * signature (if there is one) + * + * @param methodBinding + * the binding to get the signature for + * @param enclosingTypeSignature + * the enclosing type signature or <code>null</code> + * @return the method signature for the given binding and enclosing type + * signature + */ + private String getMethodSignature(IMethodBinding methodBinding, + String enclosingTypeSignature) { + methodBinding = methodBinding.getMethodDeclaration(); ITypeBinding[] parameterTypes = methodBinding.getParameterTypes(); int offset = 0; int argCount; String[] parameterSignatures; if (enclosingTypeSignature == null) { - argCount= parameterTypes.length; - parameterSignatures= new String[argCount]; + argCount = parameterTypes.length; + parameterSignatures = new String[argCount]; } else { offset = 1; - argCount= parameterTypes.length + 1; - parameterSignatures= new String[argCount]; - parameterSignatures[0]= enclosingTypeSignature; + argCount = parameterTypes.length + 1; + parameterSignatures = new String[argCount]; + parameterSignatures[0] = enclosingTypeSignature; } for (int i = 0; i < parameterTypes.length; i++) { - parameterSignatures[i+offset]= getTypeSignature(parameterTypes[i]); + parameterSignatures[i + offset] = getTypeSignature(parameterTypes[i]); } - String signature= Signature.createMethodSignature(parameterSignatures, getTypeSignature(methodBinding.getReturnType())); + String signature = Signature.createMethodSignature(parameterSignatures, + getTypeSignature(methodBinding.getReturnType())); return signature; } private int getPrimitiveTypeId(String typeName) { switch (typeName.charAt(0)) { - case 'b': // byte or boolean - switch (typeName.charAt(1)) { - case 'o': // boolean; - return Instruction.T_boolean; - case 'y': // byte - return Instruction.T_byte; - } - break; - case 'c': // char - return Instruction.T_char; - case 'd': // double - return Instruction.T_double; - case 'f': // float - return Instruction.T_float; - case 'i': // int - return Instruction.T_int; - case 'l': // long - return Instruction.T_long; - case 'n': - return Instruction.T_null; - case 's': // short - return Instruction.T_short; - case 'v': // void - return Instruction.T_void; + case 'b': // byte or boolean + switch (typeName.charAt(1)) { + case 'o': // boolean; + return Instruction.T_boolean; + case 'y': // byte + return Instruction.T_byte; + } + break; + case 'c': // char + return Instruction.T_char; + case 'd': // double + return Instruction.T_double; + case 'f': // float + return Instruction.T_float; + case 'i': // int + return Instruction.T_int; + case 'l': // long + return Instruction.T_long; + case 'n': + return Instruction.T_null; + case 's': // short + return Instruction.T_short; + case 'v': // void + return Instruction.T_void; } return Instruction.T_undefined; } - + /** - * Resolves and returns the type binding from the given expression reporting an error - * if the binding is <code>null</code>. - * - * @param expression expression to resolve type binding for + * Resolves and returns the type binding from the given expression reporting + * an error if the binding is <code>null</code>. + * + * @param expression + * expression to resolve type binding for * @return type binding or <code>null</code> if not available */ private ITypeBinding resolveTypeBinding(Expression expression) { ITypeBinding typeBinding = expression.resolveTypeBinding(); if (typeBinding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_3, new String[]{expression.toString()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_3, + new Object[] { expression.toString() })); } return typeBinding; } - + /** - * Resolves and returns the type binding for the give type reporting an error - * if the binding is <code>null</code>. + * Resolves and returns the type binding for the give type reporting an + * error if the binding is <code>null</code>. * - * @param type type to resolve binding for + * @param type + * type to resolve binding for * @return type binding or <code>null</code> if not available */ private ITypeBinding resolveTypeBinding(Type type) { ITypeBinding typeBinding = type.resolveBinding(); if (typeBinding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_3, new String[]{type.toString()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_3, + new Object[] { type.toString() })); } return typeBinding; } - + /** - * Resolves and returns the binding for the given name reporting an error - * if the binding is <code>null</code>. + * Resolves and returns the binding for the given name reporting an error if + * the binding is <code>null</code>. * - * @param name name to resolve binding for + * @param name + * name to resolve binding for * @return binding or <code>null</code> if not available */ private IBinding resolveBinding(Name name) { IBinding binding = name.resolveBinding(); if (binding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_5, new String[]{name.getFullyQualifiedName()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_5, + new Object[] { name.getFullyQualifiedName() })); } return binding; - } - + } + /** - * Resolves and returns the type binding for the given name reporting an error - * if the binding is <code>null</code>. + * Resolves and returns the type binding for the given name reporting an + * error if the binding is <code>null</code>. * - * @param name name to resolve type binding for + * @param name + * name to resolve type binding for * @return type binding or <code>null</code> if not available */ private ITypeBinding resolveTypeBinding(Name name) { ITypeBinding typeBinding = name.resolveTypeBinding(); if (typeBinding == null) { setHasError(true); - addErrorMessage(MessageFormat.format(EvaluationEngineMessages.ASTInstructionCompiler_3, new String[]{name.getFullyQualifiedName()})); + addErrorMessage(MessageFormat.format( + EvaluationEngineMessages.ASTInstructionCompiler_3, + new Object[] { name.getFullyQualifiedName() })); } return typeBinding; } |