diff options
Diffstat (limited to 'org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval')
97 files changed, 6122 insertions, 4539 deletions
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/EvaluationResult.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/EvaluationResult.java index 0687b4a3c..69ccfa739 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/EvaluationResult.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/EvaluationResult.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -21,60 +20,59 @@ import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.debug.eval.IEvaluationEngine; import org.eclipse.jdt.debug.eval.IEvaluationResult; - + /** * The result of an evaluation. * * @see org.eclipse.jdt.debug.eval.IEvaluationResult */ public class EvaluationResult implements IEvaluationResult { - + /** * The result of an evaluation, possibly <code>null</code> */ private IJavaValue fValue; - + /** - * Thread in which the associated evaluation was - * executed. + * Thread in which the associated evaluation was executed. */ private IJavaThread fThread; - + /** * Evaluation engine that created this result */ private IEvaluationEngine fEngine; - + /** * Source that was evaluated. */ private String fSnippet; - + /** - * Exception that occurred during evaluation, - * or <code>null</code> if none. + * Exception that occurred during evaluation, or <code>null</code> if none. */ private DebugException fException; - + /** * List of <code>String</code>s describing compilation problems. */ - private List fErrors; - + private List<String> fErrors; + /** * Whether the evaluation was terminated. */ private boolean fTerminated = false; /** - * Constructs a new evaluation result for the given - * engine, thread, and code snippet. + * Constructs a new evaluation result for the given engine, thread, and code + * snippet. */ - public EvaluationResult(IEvaluationEngine engine, String snippet, IJavaThread thread) { + public EvaluationResult(IEvaluationEngine engine, String snippet, + IJavaThread thread) { setEvaluationEngine(engine); setThread(thread); setSnippet(snippet); - fErrors= new ArrayList(); + fErrors = new ArrayList<String>(); } /** @@ -83,17 +81,16 @@ public class EvaluationResult implements IEvaluationResult { public IJavaValue getValue() { return fValue; } - + /** - * Sets the result of an evaluation, possibly - * <code>null</code>. + * Sets the result of an evaluation, possibly <code>null</code>. * - * @param value result of an evaluation, possibly - * <code>null</code> + * @param value + * result of an evaluation, possibly <code>null</code> */ public void setValue(IJavaValue value) { fValue = value; - } + } /** * @see IEvaluationResult#hasProblems() @@ -106,33 +103,35 @@ public class EvaluationResult implements IEvaluationResult { * @see IEvaluationResult#getProblems() * @deprecated */ + @Deprecated public Message[] getErrors() { - Message[] messages= new Message[fErrors.size()]; - int i= 0; - for (Iterator iter= fErrors.iterator(); iter.hasNext();) { - messages[i++]= new Message((String) iter.next(), -1); + Message[] messages = new Message[fErrors.size()]; + int i = 0; + for (Iterator<String> iter = fErrors.iterator(); iter.hasNext();) { + messages[i++] = new Message(iter.next(), -1); } return messages; } - + /** * @see org.eclipse.jdt.debug.eval.IEvaluationResult#getErrorMessages() */ public String[] getErrorMessages() { - return (String[])fErrors.toArray(new String[fErrors.size()]); + return fErrors.toArray(new String[fErrors.size()]); } - + /** * @see IEvaluationResult#getSnippet() */ public String getSnippet() { return fSnippet; } - + /** * Sets the code snippet that was evaluated. * - * @param snippet the source code that was evaluated + * @param snippet + * the source code that was evaluated */ private void setSnippet(String snippet) { fSnippet = snippet; @@ -144,12 +143,13 @@ public class EvaluationResult implements IEvaluationResult { public DebugException getException() { return fException; } - + /** - * Sets an exception that occurred while attempting - * the associated evaluation. + * Sets an exception that occurred while attempting the associated + * evaluation. * - * @param e exception + * @param e + * exception */ public void setException(DebugException e) { fException = e; @@ -161,16 +161,15 @@ public class EvaluationResult implements IEvaluationResult { public IJavaThread getThread() { return fThread; } - + /** - * Sets the thread this result was generated - * from. + * Sets the thread this result was generated from. * - * @param thread thread in which the associated - * evaluation was executed + * @param thread + * thread in which the associated evaluation was executed */ private void setThread(IJavaThread thread) { - fThread= thread; + fThread = thread; } /** @@ -179,16 +178,17 @@ public class EvaluationResult implements IEvaluationResult { public IEvaluationEngine getEvaluationEngine() { return fEngine; } - + /** * Sets the evaluation that created this result. * - * @param engine the evaluation that created this result + * @param engine + * the evaluation that created this result */ private void setEvaluationEngine(IEvaluationEngine engine) { fEngine = engine; } - + /** * Adds the given message to the list of error messages. */ @@ -196,7 +196,9 @@ public class EvaluationResult implements IEvaluationResult { fErrors.add(message); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jdt.debug.eval.IEvaluationResult#isTerminated() */ public boolean isTerminated() { @@ -206,10 +208,10 @@ public class EvaluationResult implements IEvaluationResult { /** * Sets whether terminated. * - * @param terminated whether terminated + * @param terminated + * whether terminated */ public void setTerminated(boolean terminated) { fTerminated = terminated; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/LocalEvaluationEngine.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/LocalEvaluationEngine.java index d969070e8..cd9aacb33 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/LocalEvaluationEngine.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/LocalEvaluationEngine.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,11 +10,9 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import com.ibm.icu.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -46,12 +44,14 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.debug.core.JDIDebugModel; import org.eclipse.jdt.debug.eval.IClassFileEvaluationEngine; +import org.eclipse.jdt.debug.eval.IEvaluationEngine; import org.eclipse.jdt.debug.eval.IEvaluationListener; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; import org.eclipse.jdt.internal.debug.core.model.JDIValue; +import com.ibm.icu.text.MessageFormat; import com.sun.jdi.InvocationException; import com.sun.jdi.ObjectReference; @@ -59,139 +59,136 @@ import com.sun.jdi.ObjectReference; * An evaluation engine that deploys class files locally */ -public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeSnippetRequestor , IEvaluationRunnable { - - private static final String CODE_SNIPPET_NAME= "CodeSnippet.class"; //$NON-NLS-1$ +public class LocalEvaluationEngine implements IClassFileEvaluationEngine, + ICodeSnippetRequestor, IEvaluationRunnable { + + private static final String CODE_SNIPPET_NAME = "CodeSnippet.class"; //$NON-NLS-1$ /** - * A count of the number of engines created. - * Count is incremented on instantiation and decremented on - * dispose. When the count == 0, the special CodeSnippet.class - * is deleted as this class file is shared by all. + * A count of the number of engines created. Count is incremented on + * instantiation and decremented on dispose. When the count == 0, the + * special CodeSnippet.class is deleted as this class file is shared by all. */ - private static int ENGINE_COUNT= 0; + private static int ENGINE_COUNT = 0; /** * The Java project context in which to compile snippets. */ private IJavaProject fJavaProject; - + /** * The debug target on which to execute snippets */ private IJavaDebugTarget fDebugTarget; - + /** * The location in which to deploy snippet class files */ private File fOutputDirectory; - + /** - * The listener to notify when the current evaluation - * is complete. + * The listener to notify when the current evaluation is complete. */ private IEvaluationListener fListener; - + /** - * The stack frame context for the current evaluation - * or <code>null</code> if there is no stack frame - * context. + * The stack frame context for the current evaluation or <code>null</code> + * if there is no stack frame context. */ private IJavaStackFrame fStackFrame; - + /** * The result of this evaluation */ private EvaluationResult fResult; - + /** * Collection of deployed snippet class files */ - private List fSnippetFiles; - + private List<File> fSnippetFiles; + /** - * Collection of directories created by this evaluation - * engine. + * Collection of directories created by this evaluation engine. */ - private List fDirectories; - + private List<File> fDirectories; + /** - * Evaluation context for the Java project associated - * with this evaluation engine. + * Evaluation context for the Java project associated with this evaluation + * engine. */ private IEvaluationContext fEvaluationContext; - + /** - * Array of modifier constants for visible local variables - * in the current evaluation. + * Array of modifier constants for visible local variables in the current + * evaluation. * - * XXX: constants should be 'default' or 'final'. Where - * are these constants defined. + * XXX: constants should be 'default' or 'final'. Where are these constants + * defined. */ private int[] fLocalVariableModifiers; - + /** - * Array of names of visible local variables - * in the current evaluation. + * Array of names of visible local variables in the current evaluation. */ private String[] fLocalVariableNames; - + /** - * Array of type names of visible local variables - * in the current evaluation. + * Array of type names of visible local variables in the current evaluation. */ private String[] fLocalVariableTypeNames; - + /** - * The 'this' object for the current evaluation - * or <code>null</code> if there is no 'this' - * context (static method, or not context) + * The 'this' object for the current evaluation or <code>null</code> if + * there is no 'this' context (static method, or not context) */ private IJavaObject fThis; - + /** * Whether this engine has been disposed. */ private boolean fDisposed = false; - + /** - * The number of evaluations currently being - * performed. + * The number of evaluations currently being performed. */ private int fEvaluationCount = 0; - + /** * The name of the code snippet class to instantiate */ private String fCodeSnippetClassName = null; - - /** + + /** * Whether to hit breakpoints in the evaluation thread */ private boolean fHitBreakpoints = false; - + /** * Constant for empty array of <code>java.lang.String</code> */ private static final String[] EMPTY_STRING_ARRAY = new String[0]; - + /** * Constant for empty array of <code>int</code> */ private static final int[] EMPTY_INT_ARRAY = new int[0]; - + /** - * Cosntructs a new evaluation engine for the given VM in the context - * of the specified project. Class files required for the evaluation will - * be deployed to the specified directory (which must be on the class - * path of the VM in order for evaluation to work). + * Constructs a new evaluation engine for the given VM in the context of the + * specified project. Class files required for the evaluation will be + * deployed to the specified directory (which must be on the class path of + * the VM in order for evaluation to work). * - * @param project context in which to compile snippets - * @param vm debug target in which to evaluate snippets - * @param directory location where snippet class files will - * be deployed for execution. The directory must exist - */ - public LocalEvaluationEngine(IJavaProject project, IJavaDebugTarget vm, File directory) { + * @param project + * context in which to compile snippets + * @param vm + * debug target in which to evaluate snippets + * @param directory + * location where snippet class files will be deployed for + * execution. The directory must exist + */ + public LocalEvaluationEngine(IJavaProject project, IJavaDebugTarget vm, + File directory) { setJavaProject(project); setDebugTarget(vm); setOutputDirectory(directory); @@ -201,60 +198,66 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * @see ICodeSnippetRequestor#acceptClassFiles(byte[][], String[][], String) */ - public boolean acceptClassFiles( - byte[][] classFileBytes, - String[][] classFileCompoundNames, - String codeSnippetClassName) { + public boolean acceptClassFiles(byte[][] classFileBytes, + String[][] classFileCompoundNames, String codeSnippetClassName) { + try { + deploy(classFileBytes, classFileCompoundNames); + } catch (DebugException e) { + getResult().setException(e); + return false; + } + if (codeSnippetClassName != null) { + setCodeSnippetClassName(codeSnippetClassName); try { - deploy(classFileBytes, classFileCompoundNames); + getThread().runEvaluation(this, null, DebugEvent.EVALUATION, + getHitBreakpoints()); } catch (DebugException e) { - getResult().setException(e); - return false; + // exception handling is in evaluation runnable } - if (codeSnippetClassName != null) { - setCodeSnippetClassName(codeSnippetClassName); - try { - getThread().runEvaluation(this, null, DebugEvent.EVALUATION, getHitBreakpoints()); - } catch (DebugException e) { - // exception handling is in evaluation runnable - } - } - return true; + } + return true; } - + public void run(IJavaThread thread, IProgressMonitor monitor) { IJavaObject codeSnippetInstance = null; try { codeSnippetInstance = newInstance(getCodeSnippetClassName()); - initializeLocals(codeSnippetInstance); - codeSnippetInstance.sendMessage(RUN_METHOD, "()V", null, getThread(), false); //$NON-NLS-1$ + initializeLocals(codeSnippetInstance); + codeSnippetInstance.sendMessage(RUN_METHOD, + "()V", null, getThread(), false); //$NON-NLS-1$ restoreLocals(codeSnippetInstance); - + // now retrieve the description of the result IVariable[] fields = codeSnippetInstance.getVariables(); IJavaVariable resultValue = null; IJavaVariable resultType = null; - for (int i = 0; i < fields.length; i++) { - if (fields[i].getName().equals(RESULT_TYPE_FIELD)) { - resultType = (IJavaVariable)fields[i]; + for (IVariable field : fields) { + if (field.getName().equals(RESULT_TYPE_FIELD)) { + resultType = (IJavaVariable) field; } - if (fields[i].getName().equals(RESULT_VALUE_FIELD)) { - resultValue = (IJavaVariable)fields[i]; + if (field.getName().equals(RESULT_VALUE_FIELD)) { + resultValue = (IJavaVariable) field; } } - IJavaValue result = convertResult((IJavaClassObject)resultType.getValue(), (IJavaValue)resultValue.getValue()); + IJavaValue result = convertResult( + (IJavaClassObject) resultType.getValue(), + (IJavaValue) resultValue.getValue()); getResult().setValue(result); } catch (DebugException e) { getResult().setException(e); - + Throwable underlyingException = e.getStatus().getException(); if (underlyingException instanceof InvocationException) { - ObjectReference theException = ((InvocationException)underlyingException).exception(); + ObjectReference theException = ((InvocationException) underlyingException) + .exception(); if (theException != null) { try { try { - IJavaObject v = (IJavaObject)JDIValue.createValue((JDIDebugTarget)getDebugTarget(), theException); - v.sendMessage("printStackTrace", "()V", null, getThread(), false); //$NON-NLS-2$ //$NON-NLS-1$ + IJavaObject v = (IJavaObject) JDIValue.createValue( + (JDIDebugTarget) getDebugTarget(), + theException); + v.sendMessage( + "printStackTrace", "()V", null, getThread(), false); //$NON-NLS-2$ //$NON-NLS-1$ } catch (DebugException de) { JDIDebugPlugin.log(de); } @@ -264,18 +267,18 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS } } } - + } - + /** - * Initializes the value of instance variables in the - * 'code snippet object' that are used as placeholders - * for locals and 'this' in the current stack frame. + * Initializes the value of instance variables in the 'code snippet object' + * that are used as place-holders for locals and 'this' in the current stack + * frame. * - * @param object instance of code snippet class that will - * be run - * @exception DebugException if an exception is thrown - * accessing the given object + * @param object + * instance of code snippet class that will be run + * @exception DebugException + * if an exception is thrown accessing the given object */ protected void initializeLocals(IJavaObject object) throws DebugException { IJavaVariable[] locals = null; @@ -284,15 +287,18 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS locals = getStackFrame().getLocalVariables(); } if (locals != null) { - for (int i = 0; i < locals.length; i++) { - IJavaVariable local = locals[i]; - IJavaVariable field = object.getField(LOCAL_VAR_PREFIX + local.getName(), false); + for (IJavaVariable local : locals) { + IJavaVariable field = object.getField( + LOCAL_VAR_PREFIX + local.getName(), false); // internal error if field is not found if (field == null) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__4, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__4, + null)); } field.setValue(local.getValue()); } @@ -302,23 +308,26 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS // internal error if field is not found if (field == null) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize___this___context__5, null) - ); - } + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize___this___context__5, + null)); + } field.setValue(thisObject); } } - + /** - * Restores the value local variables from the instance - * variables in the 'code snippet object' that are used - * as placeholders for locals in the current stack frame. + * Restores the value local variables from the instance variables in the + * 'code snippet object' that are used as place-holders for locals in the + * current stack frame. * - * @param object instance of code snippet class that was - * run - * @exception DebugException if an exception is thrown - * accessing the given object + * @param object + * instance of code snippet class that was run + * @exception DebugException + * if an exception is thrown accessing the given object */ protected void restoreLocals(IJavaObject object) throws DebugException { IJavaVariable[] locals = null; @@ -326,16 +335,19 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS locals = getStackFrame().getLocalVariables(); } if (locals != null) { - for (int i = 0; i < locals.length; i++) { - IJavaVariable local = locals[i]; - IJavaVariable field = object.getField(LOCAL_VAR_PREFIX + local.getName(), false); + for (IJavaVariable local : locals) { + IJavaVariable field = object.getField( + LOCAL_VAR_PREFIX + local.getName(), false); // internal error if field is not found if (field == null) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__6, null) - ); - } + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__6, + null)); + } local.setValue(field.getValue()); } } @@ -344,13 +356,14 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * @see ICodeSnippetRequestor#acceptProblem(IMarker, String, int) */ - public void acceptProblem(IMarker problemMarker, String fragmentSource, int fragmentKind) { + public void acceptProblem(IMarker problemMarker, String fragmentSource, + int fragmentKind) { if (problemMarker.getAttribute(IMarker.SEVERITY, -1) != IMarker.SEVERITY_ERROR) { return; } getResult().addError(problemMarker.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ } - + /** * @see IEvaluationEngine#getDebugTarget() */ @@ -361,7 +374,8 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * Sets the debug target in which snippets are executed. * - * @param debugTarget the debug target in which snippets are executed + * @param debugTarget + * the debug target in which snippets are executed */ private void setDebugTarget(IJavaDebugTarget debugTarget) { fDebugTarget = debugTarget; @@ -377,7 +391,8 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * Sets the Java project in which snippets are compiled. * - * @param javaProject the Java project in which snippets are compiled + * @param javaProject + * the Java project in which snippets are compiled */ private void setJavaProject(IJavaProject javaProject) { fJavaProject = javaProject; @@ -393,263 +408,298 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS } /** - * Sets the directory in which snippet class files are - * deployed. + * Sets the directory in which snippet class files are deployed. * - * @param outputDirectory location to deploy snippet class files + * @param outputDirectory + * location to deploy snippet class files */ private void setOutputDirectory(File outputDirectory) { fOutputDirectory = outputDirectory; } /** - * @see IClassFileEvaluationEngine#evaluate(String, IJavaThread, IEvaluationListener) + * @see IClassFileEvaluationEngine#evaluate(String, IJavaThread, + * IEvaluationListener) */ - public void evaluate(String snippet, IJavaThread thread, IEvaluationListener listener, boolean hitBreakpoints) throws DebugException { - checkDisposed(); - checkEvaluating(); - try { - evaluationStarted(); - setListener(listener); - setHitBreakpoints(hitBreakpoints); - setResult(new EvaluationResult(this, snippet, thread)); - checkThread(); - // no receiver/stack frame context - setThis(null); - setLocalVariableNames(EMPTY_STRING_ARRAY); - setLocalVariableTypeNames(EMPTY_STRING_ARRAY); - setLocalVariableModifiers(EMPTY_INT_ARRAY); - - // do the evaluation in a different thread - Runnable r = new Runnable() { - public void run() { - try { - LocalEvaluationEngine.this.getEvaluationContext(). - evaluateCodeSnippet(LocalEvaluationEngine.this.getSnippet(), - LocalEvaluationEngine.this, null); - } catch (JavaModelException e) { - LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); - } finally { - LocalEvaluationEngine.this.evaluationComplete(); - } + public void evaluate(String snippet, IJavaThread thread, + IEvaluationListener listener, boolean hitBreakpoints) + throws DebugException { + checkDisposed(); + checkEvaluating(); + try { + evaluationStarted(); + setListener(listener); + setHitBreakpoints(hitBreakpoints); + setResult(new EvaluationResult(this, snippet, thread)); + checkThread(); + // no receiver/stack frame context + setThis(null); + setLocalVariableNames(EMPTY_STRING_ARRAY); + setLocalVariableTypeNames(EMPTY_STRING_ARRAY); + setLocalVariableModifiers(EMPTY_INT_ARRAY); + + // do the evaluation in a different thread + Runnable r = new Runnable() { + public void run() { + try { + LocalEvaluationEngine.this + .getEvaluationContext() + .evaluateCodeSnippet( + LocalEvaluationEngine.this.getSnippet(), + LocalEvaluationEngine.this, null); + } catch (JavaModelException e) { + LocalEvaluationEngine.this.getResult().setException( + new DebugException(e.getStatus())); + } finally { + LocalEvaluationEngine.this.evaluationComplete(); } - }; - - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); - } catch (DebugException d) { - evaluationAborted(); - throw d; - } - + } + }; + + Thread t = new Thread(r); + t.setDaemon(true); + t.start(); + } catch (DebugException d) { + evaluationAborted(); + throw d; + } + } /** - * @see IEvaluationEngine#evaluate(String, IJavaStackFrame, IEvaluationListener, int) + * @see IEvaluationEngine#evaluate(String, IJavaStackFrame, + * IEvaluationListener, int) */ - public void evaluate(String snippet, IJavaStackFrame frame, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { - checkDisposed(); - checkEvaluating(); - try { - evaluationStarted(); - setListener(listener); - setStackFrame(frame); - setHitBreakpoints(hitBreakpoints); - setResult(new EvaluationResult(this, snippet, (IJavaThread)frame.getThread())); - checkThread(); - - // set up local variables and 'this' context for evaluation - IJavaVariable[] locals = frame.getLocalVariables(); - - List typeNames = new ArrayList(locals.length); - List varNames = new ArrayList(locals.length); - - for (int i = 0; i < locals.length; i++) { - IJavaVariable var = locals[i]; - String typeName = getTranslatedTypeName(var.getReferenceTypeName()); - if (typeName != null) { - typeNames.add(typeName); - varNames.add(var.getName()); - } + public void evaluate(String snippet, IJavaStackFrame frame, + IEvaluationListener listener, int evaluationDetail, + boolean hitBreakpoints) throws DebugException { + checkDisposed(); + checkEvaluating(); + try { + evaluationStarted(); + setListener(listener); + setStackFrame(frame); + setHitBreakpoints(hitBreakpoints); + setResult(new EvaluationResult(this, snippet, + (IJavaThread) frame.getThread())); + checkThread(); + + // set up local variables and 'this' context for evaluation + IJavaVariable[] locals = frame.getLocalVariables(); + + List<String> typeNames = new ArrayList<String>(locals.length); + List<String> varNames = new ArrayList<String>(locals.length); + + for (IJavaVariable var : locals) { + String typeName = getTranslatedTypeName(var + .getReferenceTypeName()); + if (typeName != null) { + typeNames.add(typeName); + varNames.add(var.getName()); } - - setLocalVariableTypeNames((String[])typeNames.toArray(new String[typeNames.size()])); - setLocalVariableNames((String[])varNames.toArray(new String[varNames.size()])); - int[] modifiers = new int[typeNames.size()]; - // cannot determine if local is final, so specify as default - Arrays.fill(modifiers, 0); - setLocalVariableModifiers(modifiers); - setThis(frame.getThis()); - - final boolean isStatic = frame.isStatic(); - final boolean isConstructor = frame.isConstructor(); - final IType receivingType = JavaDebugUtils.resolveDeclaringType(frame); - validateReceivingType(receivingType); - - // do the evaluation in a different thread - Runnable r = new Runnable() { - public void run() { - try { - LocalEvaluationEngine.this.getEvaluationContext(). - evaluateCodeSnippet( - LocalEvaluationEngine.this.getSnippet(), - LocalEvaluationEngine.this.getLocalVariableTypeNames(), - LocalEvaluationEngine.this.getLocalVariableNames(), - LocalEvaluationEngine.this.getLocalVariableModifiers(), - receivingType, - isStatic, - isConstructor, - LocalEvaluationEngine.this, - null); - } catch (JavaModelException e) { - LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); - } finally { - LocalEvaluationEngine.this.evaluationComplete(); - } + } + + setLocalVariableTypeNames(typeNames + .toArray(new String[typeNames.size()])); + setLocalVariableNames(varNames + .toArray(new String[varNames.size()])); + int[] modifiers = new int[typeNames.size()]; + // cannot determine if local is final, so specify as default + Arrays.fill(modifiers, 0); + setLocalVariableModifiers(modifiers); + setThis(frame.getThis()); + + final boolean isStatic = frame.isStatic(); + final boolean isConstructor = frame.isConstructor(); + final IType receivingType = JavaDebugUtils + .resolveDeclaringType(frame); + validateReceivingType(receivingType); + + // do the evaluation in a different thread + Runnable r = new Runnable() { + public void run() { + try { + LocalEvaluationEngine.this + .getEvaluationContext() + .evaluateCodeSnippet( + LocalEvaluationEngine.this.getSnippet(), + LocalEvaluationEngine.this + .getLocalVariableTypeNames(), + LocalEvaluationEngine.this + .getLocalVariableNames(), + LocalEvaluationEngine.this + .getLocalVariableModifiers(), + receivingType, isStatic, isConstructor, + LocalEvaluationEngine.this, null); + } catch (JavaModelException e) { + LocalEvaluationEngine.this.getResult().setException( + new DebugException(e.getStatus())); + } finally { + LocalEvaluationEngine.this.evaluationComplete(); } - }; - - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); - } catch (DebugException d) { - evaluationAborted(); - throw d; - } catch (CoreException e) { - evaluationAborted(); - throw new DebugException(e.getStatus()); - } + } + }; + + Thread t = new Thread(r); + t.setDaemon(true); + t.start(); + } catch (DebugException d) { + evaluationAborted(); + throw d; + } catch (CoreException e) { + evaluationAborted(); + throw new DebugException(e.getStatus()); + } } /** - * Verifies the receiving type was resovled and is not an inner type. + * Verifies the receiving type was resolved and is not an inner type. * * @param receivingType * @throws DebugException */ - private void validateReceivingType(final IType receivingType) throws DebugException { + private void validateReceivingType(final IType receivingType) + throws DebugException { if (receivingType == null) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_determine_receiving_type_context__18, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_determine_receiving_type_context__18, + null)); } - + if (receivingType.getDeclaringType() != null) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_in_context_of_inner_type_not_supported__19, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_in_context_of_inner_type_not_supported__19, + null)); } } - + /** - * @see IEvaluationEngine#evaluate(String, IJavaObject, IJavaThread, IEvaluationListener, int) + * @see IEvaluationEngine#evaluate(String, IJavaObject, IJavaThread, + * IEvaluationListener, int) */ - public void evaluate(String snippet, IJavaObject thisContext, IJavaThread thread, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { - checkDisposed(); - checkEvaluating(); - try { - evaluationStarted(); - setListener(listener); - setHitBreakpoints(hitBreakpoints); - setResult(new EvaluationResult(this, snippet, thread)); - checkThread(); - - // no locals - setLocalVariableTypeNames(new String[0]); - setLocalVariableNames(new String[0]); - setLocalVariableModifiers(new int[0]); - - setThis(thisContext); - - final boolean isStatic = false; - final boolean isConstructor = false; - final IType receivingType = JavaDebugUtils.resolveType(thisContext.getJavaType()); - validateReceivingType(receivingType); - - // do the evaluation in a different thread - Runnable r = new Runnable() { - public void run() { - try { - LocalEvaluationEngine.this.getEvaluationContext(). - evaluateCodeSnippet( - LocalEvaluationEngine.this.getSnippet(), - LocalEvaluationEngine.this.getLocalVariableTypeNames(), - LocalEvaluationEngine.this.getLocalVariableNames(), - LocalEvaluationEngine.this.getLocalVariableModifiers(), - receivingType, - isStatic, - isConstructor, - LocalEvaluationEngine.this, - null); - } catch (JavaModelException e) { - LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); - } finally { - LocalEvaluationEngine.this.evaluationComplete(); - } + public void evaluate(String snippet, IJavaObject thisContext, + IJavaThread thread, IEvaluationListener listener, + int evaluationDetail, boolean hitBreakpoints) throws DebugException { + checkDisposed(); + checkEvaluating(); + try { + evaluationStarted(); + setListener(listener); + setHitBreakpoints(hitBreakpoints); + setResult(new EvaluationResult(this, snippet, thread)); + checkThread(); + + // no locals + setLocalVariableTypeNames(new String[0]); + setLocalVariableNames(new String[0]); + setLocalVariableModifiers(new int[0]); + + setThis(thisContext); + + final boolean isStatic = false; + final boolean isConstructor = false; + final IType receivingType = JavaDebugUtils.resolveType(thisContext + .getJavaType()); + validateReceivingType(receivingType); + + // do the evaluation in a different thread + Runnable r = new Runnable() { + public void run() { + try { + LocalEvaluationEngine.this + .getEvaluationContext() + .evaluateCodeSnippet( + LocalEvaluationEngine.this.getSnippet(), + LocalEvaluationEngine.this + .getLocalVariableTypeNames(), + LocalEvaluationEngine.this + .getLocalVariableNames(), + LocalEvaluationEngine.this + .getLocalVariableModifiers(), + receivingType, isStatic, isConstructor, + LocalEvaluationEngine.this, null); + } catch (JavaModelException e) { + LocalEvaluationEngine.this.getResult().setException( + new DebugException(e.getStatus())); + } finally { + LocalEvaluationEngine.this.evaluationComplete(); } - }; - - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); - } catch (DebugException d) { - evaluationAborted(); - throw d; - } catch (CoreException e) { - evaluationAborted(); - throw new DebugException(e.getStatus()); - } + } + }; + + Thread t = new Thread(r); + t.setDaemon(true); + t.start(); + } catch (DebugException d) { + evaluationAborted(); + throw d; + } catch (CoreException e) { + evaluationAborted(); + throw new DebugException(e.getStatus()); + } } - + /** - * Throws an exception if this engine has already been - * disposed. + * Throws an exception if this engine has already been disposed. * - * @exception DebugException if this engine has been disposed + * @exception DebugException + * if this engine has been disposed */ protected void checkDisposed() throws DebugException { if (isDisposed()) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_context_has_been_disposed__7, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_context_has_been_disposed__7, + null)); } } - + /** - * Throws an exception if this engine is already in an - * evaluation. + * Throws an exception if this engine is already in an evaluation. * - * @exception DebugException if this engine is currently - * performing an evaluation + * @exception DebugException + * if this engine is currently performing an evaluation */ protected void checkEvaluating() throws DebugException { if (isEvaluating()) { - throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, "Cannot perform nested evaluations.", null) //$NON-NLS-1$ + throw new DebugException(new Status(IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + "Cannot perform nested evaluations.", null) //$NON-NLS-1$ ); } - } - + } + /** - * Throws an exception if this engine's current evaluation - * thread is not suspended. + * Throws an exception if this engine's current evaluation thread is not + * suspended. * - * @exception DebugException if this engine's current evaluation - * thread is not suspended + * @exception DebugException + * if this engine's current evaluation thread is not + * suspended */ protected void checkThread() throws DebugException { if (!getThread().isSuspended()) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_thread_must_be_suspended__8, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_thread_must_be_suspended__8, + null)); } - } + } /** * Deletes deployed class files, and clears state. @@ -664,33 +714,43 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS // wait for evaluation to complete return; } - List snippetFiles = getSnippetFiles(); - Iterator iter = snippetFiles.iterator(); + List<File> snippetFiles = getSnippetFiles(); + Iterator<File> iter = snippetFiles.iterator(); while (iter.hasNext()) { - File file = (File)iter.next(); + File file = (File) iter.next(); if (file.exists()) { - if (CODE_SNIPPET_NAME.equals(file.getName()) && ENGINE_COUNT > 0) { - continue; //do not delete the common file for other engines + if (CODE_SNIPPET_NAME.equals(file.getName()) + && ENGINE_COUNT > 0) { + continue; // do not delete the common file for other engines } if (!file.delete()) { - JDIDebugPlugin.log( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, - MessageFormat.format("Unable to delete temporary evaluation class file {0}.", new String[] {file.getAbsolutePath()}), null) //$NON-NLS-1$ - ); + JDIDebugPlugin + .log(new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + MessageFormat + .format("Unable to delete temporary evaluation class file {0}.", new Object[] { file.getAbsolutePath() }), null) //$NON-NLS-1$ + ); } } } - List directories = getDirectories(); + List<File> directories = getDirectories(); // remove directories in bottom up order int i = directories.size() - 1; while (i >= 0) { - File dir = (File)directories.get(i); - String[] listing= dir.list(); - if (dir.exists() && listing != null && listing.length == 0 && !dir.delete()) { - JDIDebugPlugin.log( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, - MessageFormat.format("Unable to delete temporary evaluation directory {0}.", new String[] {dir.getAbsolutePath()}), null) //$NON-NLS-1$ - ); + File dir = directories.get(i); + String[] listing = dir.list(); + if (dir.exists() && listing != null && listing.length == 0 + && !dir.delete()) { + JDIDebugPlugin + .log(new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + MessageFormat + .format("Unable to delete temporary evaluation directory {0}.", new Object[] { dir.getAbsolutePath() }), null) //$NON-NLS-1$ + ); } i--; } @@ -701,7 +761,6 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS setResult(null); setEvaluationContext(null); } - /** * Resets this engine for another evaluation. @@ -711,35 +770,32 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS setStackFrame(null); setListener(null); } - + /** - * Returns the listener to notify when the current - * evaluation is complete. + * Returns the listener to notify when the current evaluation is complete. * - * @return the listener to notify when the current - * evaluation is complete + * @return the listener to notify when the current evaluation is complete */ protected IEvaluationListener getListener() { return fListener; } /** - * Sets the listener to notify when the current - * evaluation is complete. + * Sets the listener to notify when the current evaluation is complete. * - * @param listener the listener to notify when the current - * evaluation is complete + * @param listener + * the listener to notify when the current evaluation is complete */ private void setListener(IEvaluationListener listener) { fListener = listener; } /** - * Returns the stack frame context for the current - * evaluation, or <code>null</code> if none. + * Returns the stack frame context for the current evaluation, or + * <code>null</code> if none. * - * @return the stack frame context for the current - * evaluation, or <code>null</code> if none + * @return the stack frame context for the current evaluation, or + * <code>null</code> if none */ protected IJavaStackFrame getStackFrame() { return fStackFrame; @@ -748,24 +804,22 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * Sets the stack frame context for the current evaluation. * - * @param stackFrame stack frame context or <code>null</code> - * if none + * @param stackFrame + * stack frame context or <code>null</code> if none */ private void setStackFrame(IJavaStackFrame stackFrame) { fStackFrame = stackFrame; } /** - * Returns the thread in which the current evaluation is - * to be executed. + * Returns the thread in which the current evaluation is to be executed. * - * @return the thread in which the current evaluation is - * to be executed + * @return the thread in which the current evaluation is to be executed */ protected IJavaThread getThread() { return getResult().getThread(); } - + /** * Returns the code snippet being evaluated. * @@ -773,7 +827,7 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS */ protected String getSnippet() { return getResult().getSnippet(); - } + } /** * Returns the current evaluation result. @@ -787,30 +841,31 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * Sets the current evaluation result. * - * @param result the current evaluation result + * @param result + * the current evaluation result */ private void setResult(EvaluationResult result) { fResult = result; } - + /** - * Deploys the given class files to this engine's - * output location, and adds the files to this - * engines list of temporary files to be deleted - * when disposed. - * - * @exception DebugException if this fails due to a - * lower level exception. + * Deploys the given class files to this engine's output location, and adds + * the files to this engines list of temporary files to be deleted when + * disposed. + * + * @exception DebugException + * if this fails due to a lower level exception. */ - protected void deploy(byte[][] classFiles, String[][] classFileNames) throws DebugException { + protected void deploy(byte[][] classFiles, String[][] classFileNames) + throws DebugException { for (int i = 0; i < classFiles.length; i++) { String[] compoundName = classFileNames[i]; - //create required folders + // create required folders File dir = LocalEvaluationEngine.this.getOutputDirectory(); try { String pkgDirName = dir.getCanonicalPath(); for (int j = 0; j < (compoundName.length - 1); j++) { - pkgDirName += File.separator + compoundName[j]; + pkgDirName += File.separator + compoundName[j]; File pkgDir = new File(pkgDirName); if (!pkgDir.exists()) { pkgDir.mkdir(); @@ -828,47 +883,51 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS LocalEvaluationEngine.this.addSnippetFile(classFile); } catch (IOException e) { throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, - MessageFormat.format(EvaluationMessages.LocalEvaluationEngine__0__occurred_deploying_class_file_for_evaluation_9, new String[] {e.toString()}), e) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + MessageFormat + .format(EvaluationMessages.LocalEvaluationEngine__0__occurred_deploying_class_file_for_evaluation_9, + new Object[] { e.toString() }), + e)); } - } - } - + } + } + /** - * Adds the given file to this engine's collection - * of deployed snippet class files, which are to - * be deleted when this engine is diposed. + * Adds the given file to this engine's collection of deployed snippet class + * files, which are to be deleted when this engine is disposed. * - * @param File snippet class file + * @param File + * snippet class file */ private void addSnippetFile(File file) { if (fSnippetFiles == null) { - fSnippetFiles = new ArrayList(); + fSnippetFiles = new ArrayList<File>(); } fSnippetFiles.add(file); } - + /** - * Adds the given file to this engine's collection - * of cerated directories, which are to - * be deleted when this engine is diposed. + * Adds the given file to this engine's collection of created directories, + * which are to be deleted when this engine is disposed. * - * @param file directory created for class file deployment + * @param file + * directory created for class file deployment */ private void addDirectory(File file) { if (fDirectories == null) { - fDirectories = new ArrayList(); + fDirectories = new ArrayList<File>(); } fDirectories.add(file); - } + } /** - * Returns an evaluation context for this evaluation - * engine. An evaluation context is associted with a - * specific Java project. The evaluation context is - * created lazily on the first access. - * + * Returns an evaluation context for this evaluation engine. An evaluation + * context is associated with a specific Java project. The evaluation context + * is created lazily on the first access. + * * @return evaluation context */ protected IEvaluationContext getEvaluationContext() { @@ -877,62 +936,59 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS } return fEvaluationContext; } - + /** - * Sets the evaluation context for this evaluation - * engine. - * - * @param context evaluation context + * Sets the evaluation context for this evaluation engine. + * + * @param context + * evaluation context */ private void setEvaluationContext(IEvaluationContext context) { fEvaluationContext = context; } - /** - * Returns a collection of snippet class file deployed by - * this evaluation engine, possibly empty. + * Returns a collection of snippet class file deployed by this evaluation + * engine, possibly empty. * * @return deployed class files */ - protected List getSnippetFiles() { + protected List<File> getSnippetFiles() { if (fSnippetFiles == null) { return Collections.EMPTY_LIST; } return fSnippetFiles; } - + /** - * Returns a collection of directories created by - * this evaluation engine, possibly empty. + * Returns a collection of directories created by this evaluation engine, + * possibly empty. * * @return directories created when deploying class files */ - protected List getDirectories() { + protected List<File> getDirectories() { if (fDirectories == null) { return Collections.EMPTY_LIST; - } + } return fDirectories; - } - + } + /** - * Returns whether this evaluation engine has been - * disposed. + * Returns whether this evaluation engine has been disposed. * - * @return whether this evaluation engine has been - * disposed + * @return whether this evaluation engine has been disposed */ protected boolean isDisposed() { return fDisposed; } - + /** - * The evaluation is complete. Notify the current listener - * and reset for the next evaluation. + * The evaluation is complete. Notify the current listener and reset for the + * next evaluation. */ protected void evaluationComplete() { // only notify if plug-in not yet shutdown (bug# 8693) - if (JDIDebugPlugin.getDefault() != null) { + if (JDIDebugPlugin.getDefault() != null) { getListener().evaluationComplete(getResult()); } evaluationEnded(); @@ -941,16 +997,16 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS // if the engine was disposed during an evaluation // do the cleanup now dispose(); - } + } } - + /** * Increments the evaluation counter. */ private void evaluationStarted() { fEvaluationCount++; } - + /** * Decrements the evaluation counter. */ @@ -958,20 +1014,18 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS if (fEvaluationCount > 0) { fEvaluationCount--; } - } - + } + /** - * Returns whether this engine is currently in the - * midst of an evaluation. + * Returns whether this engine is currently in the midst of an evaluation. */ protected boolean isEvaluating() { return fEvaluationCount > 0; } - + /** - * Called when an evaluation is aborted due to an - * exception. Decrements the evalution count, and - * disposes this engine if the target VM disconnected + * Called when an evaluation is aborted due to an exception. Decrements the + * evaluation count, and disposes this engine if the target VM disconnected * or terminated during the evaluation attempt. */ private void evaluationAborted() { @@ -980,23 +1034,25 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS // if the engine was disposed during an evaluation // do the cleanup now dispose(); - } + } } - + /** - * Constructs and returns a new instance of the specified - * class on the target VM. + * Constructs and returns a new instance of the specified class on the + * target VM. * - * @param className fully qualified class name + * @param className + * fully qualified class name * @return a new instance on the target, as an <code>IJavaValue</code> - * @exception DebugException if creation fails + * @exception DebugException + * if creation fails */ protected IJavaObject newInstance(String className) throws DebugException { IJavaObject object = null; IJavaClassType clazz = null; IJavaType[] types = getDebugTarget().getJavaTypes(className); if (types != null && types.length > 0) { - clazz = (IJavaClassType)types[0]; + clazz = (IJavaClassType) types[0]; } if (clazz == null) { // The class is not loaded on the target VM. @@ -1004,48 +1060,59 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS types = getDebugTarget().getJavaTypes("java.lang.Class"); //$NON-NLS-1$ IJavaClassType classClass = null; if (types != null && types.length > 0) { - classClass = (IJavaClassType)types[0]; + classClass = (IJavaClassType) types[0]; } if (classClass == null) { // unable to load the class throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_instantiate_code_snippet_class__11, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_instantiate_code_snippet_class__11, + null)); } - IJavaValue[] args = new IJavaValue[] {getDebugTarget().newValue(className)}; - IJavaObject classObject = (IJavaObject)classClass.sendMessage("forName", "(Ljava/lang/String;)Ljava/lang/Class;", args, getThread()); //$NON-NLS-2$ //$NON-NLS-1$ - object = (IJavaObject)classObject.sendMessage("newInstance", "()Ljava/lang/Object;", null, getThread(), false); //$NON-NLS-2$ //$NON-NLS-1$ + IJavaValue[] args = new IJavaValue[] { getDebugTarget().newValue( + className) }; + IJavaObject classObject = (IJavaObject) classClass + .sendMessage( + "forName", "(Ljava/lang/String;)Ljava/lang/Class;", args, getThread()); //$NON-NLS-2$ //$NON-NLS-1$ + object = (IJavaObject) classObject + .sendMessage( + "newInstance", "()Ljava/lang/Object;", null, getThread(), false); //$NON-NLS-2$ //$NON-NLS-1$ } else { object = clazz.newInstance("<init>", null, getThread()); //$NON-NLS-1$ } return object; } - + /** - * Interpretts and returns the result of the running the snippet - * class file. The type of the result is described by an instance of - * <code>java.lang.Class</code>. The value is interpretted based - * on the result type. + * Interprets and returns the result of the running the snippet class file. + * The type of the result is described by an instance of + * <code>java.lang.Class</code>. The value is interpreted based on the + * result type. * <p> - * Objects as well as primitve data types (boolean, int, etc.), - * have class objects, which are created by the VM. If the class object - * represents a primitive data type, then the associated value - * is stored in an instance of its "object" class. For example, when - * the result type is the class object for <code>int</code>, the result - * object is an instance of <code>java.lang.Integer</code>, and the - * actual <code>int</code> is stored in the </code>intValue()</code>. - * When the result type is the class object for <code>java.lang.Integer</code> - * the result object is an instance of <code>java.lang.Integer</code>, - * to be interpretted as a <ocde>java.lang.Integer</code>. + * Objects as well as primitive data types (boolean, int, etc.), have class + * objects, which are created by the VM. If the class object represents a + * primitive data type, then the associated value is stored in an instance + * of its "object" class. For example, when the result type is the class + * object for <code>int</code>, the result object is an instance of + * <code>java.lang.Integer</code>, and the actual <code>int</code> is stored + * in the </code>intValue()</code>. When the result type is the class object + * for <code>java.lang.Integer</code> the result object is an instance of + * <code>java.lang.Integer</code>, to be interpreted as a + * <code>java.lang.Integer</code>. * </p> * - * @param resultType the class of the result - * @param resultValue the value of ther result, to be interpretted - * based on resultType - * @return the result of running the code snipped class file - */ - protected IJavaValue convertResult(IJavaClassObject resultType, IJavaValue result) throws DebugException { + * @param resultType + * the class of the result + * @param resultValue + * the value of the result, to be interpreted based on + * resultType + * @return the result of running the code snippet class file + */ + protected IJavaValue convertResult(IJavaClassObject resultType, + IJavaValue result) throws DebugException { if (resultType == null) { // there was an exception or compilation problem - no result return null; @@ -1062,35 +1129,38 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS // null result return result; } - + if (sig.length() == 1) { // primitive type - find the instance variable with the // signature of the result type we are looking for IVariable[] vars = result.getVariables(); IJavaVariable var = null; - for (int i = 0; i < vars.length; i++) { - IJavaVariable jv = (IJavaVariable)vars[i]; + for (IVariable var2 : vars) { + IJavaVariable jv = (IJavaVariable) var2; if (!jv.isStatic() && jv.getSignature().equals(sig)) { var = jv; break; } } if (var != null) { - return (IJavaValue)var.getValue(); + return (IJavaValue) var.getValue(); } } else { // an object return result; } throw new DebugException( - new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), - DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___internal_error_retreiving_result__17, null) - ); + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___internal_error_retreiving_result__17, + null)); } - + /** - * Returns the modifiers of the local variables - * visible in this evaluation, possibly empty. + * Returns the modifiers of the local variables visible in this evaluation, + * possibly empty. * * @return array of modifiers */ @@ -1099,90 +1169,95 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS } /** - * Sets the modifiers of the local variables - * visible in this evaluation, possibly empty. + * Sets the modifiers of the local variables visible in this evaluation, + * possibly empty. * - * @param localVariableModifiers array of modifiers + * @param localVariableModifiers + * array of modifiers */ private void setLocalVariableModifiers(int[] localVariableModifiers) { fLocalVariableModifiers = localVariableModifiers; } - + /** - * Returns the names of the local variables - * visible in this evaluation, possibly empty. + * Returns the names of the local variables visible in this evaluation, + * possibly empty. * - * @param array of names - */ + * @param array + * of names + */ private String[] getLocalVariableNames() { return fLocalVariableNames; } - + /** - * Sets the names of the local variables - * visible in this evaluation, possibly empty. + * Sets the names of the local variables visible in this evaluation, + * possibly empty. * - * @param localVariableNames array of names + * @param localVariableNames + * array of names */ private void setLocalVariableNames(String[] localVariableNames) { fLocalVariableNames = localVariableNames; } /** - * Returns the type names of the local variables - * visible in this evaluation, possibly empty. + * Returns the type names of the local variables visible in this evaluation, + * possibly empty. * - * @param array of type names + * @param array + * of type names */ private String[] getLocalVariableTypeNames() { return fLocalVariableTypeNames; } /** - * Sets the type names of the local variables - * visible in this evaluation, possibly empty. + * Sets the type names of the local variables visible in this evaluation, + * possibly empty. * - * @param localVariableTypeNames array of type names + * @param localVariableTypeNames + * array of type names */ private void setLocalVariableTypeNames(String[] localVariableTypeNames) { fLocalVariableTypeNames = localVariableTypeNames; - } - + } + /** - * Sets the receiver context for the associated evaluation, - * possibly <code>null</code> if the evaluation is - * in the context of a static method or there is - * no object context. + * Sets the receiver context for the associated evaluation, possibly + * <code>null</code> if the evaluation is in the context of a static method + * or there is no object context. * - * @param thisObject the receiver content of the - * associated evaluation, or <code>null</code> + * @param thisObject + * the receiver content of the associated evaluation, or + * <code>null</code> */ private void setThis(IJavaObject thisObject) { fThis = thisObject; } - + /** - * Returns the receiver context for the associated evaluation, - * or <code>null</code> if the evaluation is - * in the context of a static method or there is - * no object context. + * Returns the receiver context for the associated evaluation, or + * <code>null</code> if the evaluation is in the context of a static method + * or there is no object context. * - * @return the receiver context of the associated - * evaluation or <code>null</code> + * @return the receiver context of the associated evaluation or + * <code>null</code> */ private IJavaObject getThis() { return fThis; } - + /** - * Returns a copy of the type name with '$' replaced by - * '.', or returns <code>null</code> if the given type - * name refers to an anonymous inner class. + * Returns a copy of the type name with '$' replaced by '.', or returns + * <code>null</code> if the given type name refers to an anonymous inner + * class. * - * @param typeName a fully qualified type name - * @return a copy of the type name with '$' replaced by - * '.', or returns <code>null</code> if the given type - * name refers to an anonymous inner class. + * @param typeName + * a fully qualified type name + * @return a copy of the type name with '$' replaced by '.', or returns + * <code>null</code> if the given type name refers to an anonymous + * inner class. */ protected String getTranslatedTypeName(String typeName) { int index = typeName.lastIndexOf('$'); @@ -1203,30 +1278,30 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS } /** - * Returns an array of simple type names that are - * part of the given type's qualified name. For - * example, if the given name is <code>x.y.A$B</code>, + * Returns an array of simple type names that are part of the given type's + * qualified name. For example, if the given name is <code>x.y.A$B</code>, * an array with <code>["A", "B"]</code> is returned. * - * @param typeName fully qualified type name + * @param typeName + * fully qualified type name * @return array of nested type names */ protected String[] getNestedTypeNames(String typeName) { int index = typeName.lastIndexOf('.'); if (index >= 0) { - typeName= typeName.substring(index + 1); + typeName = typeName.substring(index + 1); } index = typeName.indexOf('$'); - ArrayList list = new ArrayList(1); + ArrayList<String> list = new ArrayList<String>(1); while (index >= 0) { list.add(typeName.substring(0, index)); typeName = typeName.substring(index + 1); index = typeName.indexOf('$'); } list.add(typeName); - return (String[])list.toArray(new String[list.size()]); + return list.toArray(new String[list.size()]); } - + /** * @see IClassFileEvaluationEngine#getImports() */ @@ -1240,25 +1315,24 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS public void setImports(String[] imports) { getEvaluationContext().setImports(imports); } - + /** - * Sets the name of the code snippet to instantiate - * to run the current evaluation. + * Sets the name of the code snippet to instantiate to run the current + * evaluation. * - * @param name the name of the deployed code snippet - * to instantiate and run + * @param name + * the name of the deployed code snippet to instantiate and run */ private void setCodeSnippetClassName(String name) { fCodeSnippetClassName = name; } /** - * Returns the name of the code snippet to instantiate - * to run the current evaluation. + * Returns the name of the code snippet to instantiate to run the current + * evaluation. * - * @return the name of the deployed code snippet - * to instantiate and run - */ + * @return the name of the deployed code snippet to instantiate and run + */ protected String getCodeSnippetClassName() { return fCodeSnippetClassName; } @@ -1281,7 +1355,9 @@ public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeS /** * Sets whether to hit breakpoints in the evaluation thread. - * @param hit whether to hit breakpoints in the evaluation thread + * + * @param hit + * whether to hit breakpoints in the evaluation thread */ private void setHitBreakpoints(boolean hit) { fHitBreakpoints = hit; diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java index 741260ea2..5f2651299 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import java.util.Date; import java.util.HashSet; import java.util.Map; @@ -64,44 +63,52 @@ import com.sun.jdi.InvocationException; import com.sun.jdi.ObjectReference; public class ASTEvaluationEngine implements IAstEvaluationEngine { - + private IJavaProject fProject; - + private IJavaDebugTarget fDebugTarget; - + /** * Regex to find occurrences of 'this' in a code snippet */ - private static Pattern fgThisPattern = Pattern.compile("(.*[^a-zA-Z0-9]+|^)(this)([^a-zA-Z0-9]+|$).*"); //$NON-NLS-1$ - + private static Pattern fgThisPattern = Pattern + .compile("(.*[^a-zA-Z0-9]+|^)(this)([^a-zA-Z0-9]+|$).*"); //$NON-NLS-1$ + /** - * Filters variable change events during an evaluation to avoid refreshing the variables - * view until done. + * Filters variable change events during an evaluation to avoid refreshing + * the variables view until done. */ class EventFilter implements IDebugEventFilter { - /* (non-Javadoc) - * @see org.eclipse.debug.core.IDebugEventFilter#filterDebugEvents(org.eclipse.debug.core.DebugEvent[]) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.core.IDebugEventFilter#filterDebugEvents(org.eclipse + * .debug.core.DebugEvent[]) */ public DebugEvent[] filterDebugEvents(DebugEvent[] events) { if (events.length == 1) { DebugEvent event = events[0]; - if (event.getSource() instanceof IJavaVariable && event.getKind() == DebugEvent.CHANGE) { - if (((IJavaVariable)event.getSource()).getDebugTarget().equals(getDebugTarget())) { + if (event.getSource() instanceof IJavaVariable + && event.getKind() == DebugEvent.CHANGE) { + if (((IJavaVariable) event.getSource()).getDebugTarget() + .equals(getDebugTarget())) { return null; } } } return events; } - + } - - public ASTEvaluationEngine(IJavaProject project, IJavaDebugTarget debugTarget) { + + public ASTEvaluationEngine(IJavaProject project, + IJavaDebugTarget debugTarget) { setJavaProject(project); setDebugTarget(debugTarget); } - + public void setJavaProject(IJavaProject project) { fProject = project; } @@ -110,30 +117,50 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { fDebugTarget = debugTarget; } - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IEvaluationEngine#evaluate(java.lang.String, org.eclipse.jdt.debug.core.IJavaStackFrame, org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IEvaluationEngine#evaluate(java.lang.String, + * org.eclipse.jdt.debug.core.IJavaStackFrame, + * org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) */ - public void evaluate(String snippet, IJavaStackFrame frame, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { + public void evaluate(String snippet, IJavaStackFrame frame, + IEvaluationListener listener, int evaluationDetail, + boolean hitBreakpoints) throws DebugException { traceCaller(snippet, frame.getThread()); - checkInterface(frame); - ICompiledExpression expression= getCompiledExpression(snippet, frame); - evaluateExpression(expression, frame, listener, evaluationDetail, hitBreakpoints); + checkInterface(frame); + ICompiledExpression expression = getCompiledExpression(snippet, frame); + evaluateExpression(expression, frame, listener, evaluationDetail, + hitBreakpoints); } - - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IEvaluationEngine#evaluate(java.lang.String, org.eclipse.jdt.debug.core.IJavaObject, org.eclipse.jdt.debug.core.IJavaThread, org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IEvaluationEngine#evaluate(java.lang.String, + * org.eclipse.jdt.debug.core.IJavaObject, + * org.eclipse.jdt.debug.core.IJavaThread, + * org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) */ - public void evaluate(String snippet, IJavaObject thisContext, IJavaThread thread, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { + public void evaluate(String snippet, IJavaObject thisContext, + IJavaThread thread, IEvaluationListener listener, + int evaluationDetail, boolean hitBreakpoints) throws DebugException { traceCaller(snippet, thread); - ICompiledExpression expression= getCompiledExpression(snippet, thisContext); - evaluateExpression(expression, thisContext, thread, listener, evaluationDetail, hitBreakpoints); + ICompiledExpression expression = getCompiledExpression(snippet, + thisContext); + evaluateExpression(expression, thisContext, thread, listener, + evaluationDetail, hitBreakpoints); } - + /** * Writes a stack dump to trace the calling thread. * - * @param snippet expression to evaluate - * @param thread thread to evaluate in + * @param snippet + * expression to evaluate + * @param thread + * thread to evaluate in */ private void traceCaller(String snippet, IThread thread) { if (JDIDebugOptions.DEBUG_AST_EVAL_THREAD_TRACE) { @@ -154,68 +181,114 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { System.out.flush(); Thread.dumpStack(); } - } - - /** - * Checks if the stack frame is declared in an interface an aborts - * if so. - * - * @param frame stack frame - * @throws DebugException if declaring type is an interface - */ - private void checkInterface(IJavaStackFrame frame) throws DebugException { - if (frame.getReferenceType() instanceof IJavaInterfaceType) { - IStatus status = new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, - EvaluationEngineMessages.ASTEvaluationEngine_0, null); - throw new DebugException(status); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IAstEvaluationEngine#evaluateExpression(org.eclipse.jdt.debug.eval.ICompiledExpression, org.eclipse.jdt.debug.core.IJavaStackFrame, org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) + } + + /** + * Checks if the stack frame is declared in an interface an aborts if so. + * + * @param frame + * stack frame + * @throws DebugException + * if declaring type is an interface */ - public void evaluateExpression(ICompiledExpression expression, IJavaStackFrame frame, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { + private void checkInterface(IJavaStackFrame frame) throws DebugException { + if (frame.getReferenceType() instanceof IJavaInterfaceType) { + IStatus status = new Status(IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.REQUEST_FAILED, + EvaluationEngineMessages.ASTEvaluationEngine_0, null); + throw new DebugException(status); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IAstEvaluationEngine#evaluateExpression(org + * .eclipse.jdt.debug.eval.ICompiledExpression, + * org.eclipse.jdt.debug.core.IJavaStackFrame, + * org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) + */ + public void evaluateExpression(ICompiledExpression expression, + IJavaStackFrame frame, IEvaluationListener listener, + int evaluationDetail, boolean hitBreakpoints) throws DebugException { traceCaller(expression.getSnippet(), frame.getThread()); RuntimeContext context = new RuntimeContext(getJavaProject(), frame); - doEvaluation(expression, context, (IJavaThread)frame.getThread(), listener, evaluationDetail, hitBreakpoints); + doEvaluation(expression, context, (IJavaThread) frame.getThread(), + listener, evaluationDetail, hitBreakpoints); } - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IAstEvaluationEngine#evaluateExpression(org.eclipse.jdt.debug.eval.ICompiledExpression, org.eclipse.jdt.debug.core.IJavaObject, org.eclipse.jdt.debug.core.IJavaThread, org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IAstEvaluationEngine#evaluateExpression(org + * .eclipse.jdt.debug.eval.ICompiledExpression, + * org.eclipse.jdt.debug.core.IJavaObject, + * org.eclipse.jdt.debug.core.IJavaThread, + * org.eclipse.jdt.debug.eval.IEvaluationListener, int, boolean) */ - public void evaluateExpression(ICompiledExpression expression, IJavaObject thisContext, IJavaThread thread, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { + public void evaluateExpression(ICompiledExpression expression, + IJavaObject thisContext, IJavaThread thread, + IEvaluationListener listener, int evaluationDetail, + boolean hitBreakpoints) throws DebugException { traceCaller(expression.getSnippet(), thread); IRuntimeContext context = null; if (thisContext instanceof IJavaArray) { - context = new ArrayRuntimeContext((IJavaArray) thisContext, thread, getJavaProject()); + context = new ArrayRuntimeContext((IJavaArray) thisContext, thread, + getJavaProject()); } else { - context = new JavaObjectRuntimeContext(thisContext, getJavaProject(), thread); + context = new JavaObjectRuntimeContext(thisContext, + getJavaProject(), thread); } - doEvaluation(expression, context, thread, listener, evaluationDetail, hitBreakpoints); + doEvaluation(expression, context, thread, listener, evaluationDetail, + hitBreakpoints); } - + /** - * Evaluates the given expression in the given thread and the given runtime context. + * Evaluates the given expression in the given thread and the given runtime + * context. */ - private void doEvaluation(ICompiledExpression expression, IRuntimeContext context, IJavaThread thread, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { + private void doEvaluation(ICompiledExpression expression, + IRuntimeContext context, IJavaThread thread, + IEvaluationListener listener, int evaluationDetail, + boolean hitBreakpoints) throws DebugException { if (expression instanceof InstructionSequence) { - // don't queue explicit evaluation if the thread is all ready performing an evaluation. - if (thread.isSuspended() && ((JDIThread)thread).isInvokingMethod() || thread.isPerformingEvaluation() && evaluationDetail == DebugEvent.EVALUATION) { - EvaluationResult result= new EvaluationResult(this, expression.getSnippet(), thread); - result.addError(EvaluationEngineMessages.ASTEvaluationEngine_Cannot_perform_nested_evaluations); + // don't queue explicit evaluation if the thread is all ready + // performing an evaluation. + if (thread.isSuspended() && ((JDIThread) thread).isInvokingMethod() + || thread.isPerformingEvaluation() + && evaluationDetail == DebugEvent.EVALUATION) { + EvaluationResult result = new EvaluationResult(this, + expression.getSnippet(), thread); + result.addError(EvaluationEngineMessages.ASTEvaluationEngine_Cannot_perform_nested_evaluations); listener.evaluationComplete(result); return; } - thread.queueRunnable(new EvalRunnable((InstructionSequence)expression, thread, context, listener, evaluationDetail, hitBreakpoints)); + thread.queueRunnable(new EvalRunnable( + (InstructionSequence) expression, thread, context, + listener, evaluationDetail, hitBreakpoints)); } else { - throw new DebugException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, EvaluationEngineMessages.ASTEvaluationEngine_AST_evaluation_engine_cannot_evaluate_expression, null)); + throw new DebugException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + EvaluationEngineMessages.ASTEvaluationEngine_AST_evaluation_engine_cannot_evaluate_expression, + null)); } } - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression(java.lang.String, org.eclipse.jdt.debug.core.IJavaStackFrame) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression + * (java.lang.String, org.eclipse.jdt.debug.core.IJavaStackFrame) */ - public ICompiledExpression getCompiledExpression(String snippet, IJavaStackFrame frame) { + public ICompiledExpression getCompiledExpression(String snippet, + IJavaStackFrame frame) { IJavaProject javaProject = getJavaProject(); RuntimeContext context = new RuntimeContext(javaProject, frame); @@ -223,57 +296,69 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { CompilationUnit unit = null; try { IJavaVariable[] localsVar = context.getLocals(); - int numLocalsVar= localsVar.length; - Set names = new HashSet(); + int numLocalsVar = localsVar.length; + Set<String> names = new HashSet<String>(); // ****** - // to hide problems with local variable declare as instance of Local Types + // to hide problems with local variable declare as instance of Local + // Types // and to remove locals with duplicate names - IJavaVariable[] locals= new IJavaVariable[numLocalsVar]; - int numLocals= 0; + IJavaVariable[] locals = new IJavaVariable[numLocalsVar]; + int numLocals = 0; for (int i = 0; i < numLocalsVar; i++) { - if (!isLocalType(localsVar[i].getSignature()) && !names.contains(localsVar[i].getName())) { - locals[numLocals++]= localsVar[i]; + if (!isLocalType(localsVar[i].getSignature()) + && !names.contains(localsVar[i].getName())) { + locals[numLocals++] = localsVar[i]; names.add(localsVar[i].getName()); } } // to solve and remove // ****** - String[] localTypesNames= new String[numLocals]; - String[] localVariables= new String[numLocals]; + String[] localTypesNames = new String[numLocals]; + String[] localVariables = new String[numLocals]; for (int i = 0; i < numLocals; i++) { localVariables[i] = locals[i].getName(); - localTypesNames[i] = Signature.toString(locals[i].getGenericSignature()).replace('/', '.'); + localTypesNames[i] = Signature.toString( + locals[i].getGenericSignature()).replace('/', '.'); } - mapper = new EvaluationSourceGenerator(localTypesNames, localVariables, snippet); - // Compile in context of declaring type to get proper visibility of locals and members. - // Compiling in context of receiving type potentially provides access to more members, + mapper = new EvaluationSourceGenerator(localTypesNames, + localVariables, snippet); + // Compile in context of declaring type to get proper visibility of + // locals and members. + // Compiling in context of receiving type potentially provides + // access to more members, // but does not allow access to privates members in declaring type IJavaReferenceType receivingType = frame.getReferenceType(); - -// currently disabled - see bugs 99416 and 106492 -// if (frame.isStatic()) { -// receivingType= frame.getReferenceType(); -// } else { -// receivingType= (IJavaReferenceType) frame.getThis().getJavaType(); -// } - - unit = parseCompilationUnit(mapper.getSource(receivingType, javaProject, frame.isStatic()).toCharArray(), mapper.getCompilationUnitName(), javaProject); + + // currently disabled - see bugs 99416 and 106492 + // if (frame.isStatic()) { + // receivingType= frame.getReferenceType(); + // } else { + // receivingType= (IJavaReferenceType) + // frame.getThis().getJavaType(); + // } + + unit = parseCompilationUnit( + mapper.getSource(receivingType, javaProject, + frame.isStatic()).toCharArray(), + mapper.getCompilationUnitName(), javaProject); } catch (CoreException e) { - InstructionSequence expression= new InstructionSequence(snippet); + InstructionSequence expression = new InstructionSequence(snippet); expression.addError(e.getStatus().getMessage()); return expression; } - + return createExpressionFromAST(snippet, mapper, unit); } - - private CompilationUnit parseCompilationUnit(char[] source, String unitName, IJavaProject project) { + + private CompilationUnit parseCompilationUnit(char[] source, + String unitName, IJavaProject project) { ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(source); parser.setUnitName(unitName); parser.setProject(project); parser.setResolveBindings(true); - Map options=EvaluationSourceGenerator.getCompilerOptions(project); + Map<?, ?> options = EvaluationSourceGenerator + .getCompilerOptions(project); parser.setCompilerOptions(options); return (CompilationUnit) parser.createAST(null); } @@ -281,40 +366,44 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { // ****** // to hide problems with local variable declare as instance of Local Types private boolean isLocalType(String typeName) { - StringTokenizer strTok= new StringTokenizer(typeName,"$"); //$NON-NLS-1$ + StringTokenizer strTok = new StringTokenizer(typeName, "$"); //$NON-NLS-1$ strTok.nextToken(); while (strTok.hasMoreTokens()) { - char char0= strTok.nextToken().charAt(0); + char char0 = strTok.nextToken().charAt(0); if ('0' <= char0 && char0 <= '9') { return true; } } return false; } + // ****** - + /** - * Returns a compiled expression for an evaluation in the context of an array - * as a receiver. + * Returns a compiled expression for an evaluation in the context of an + * array as a receiver. */ - private ICompiledExpression getCompiledExpression(String snippet, IJavaArrayType arrayType) { + private ICompiledExpression getCompiledExpression(String snippet, + IJavaArrayType arrayType) { EvaluationSourceGenerator mapper = null; CompilationUnit unit = null; try { IJavaProject javaProject = getJavaProject(); // replace all occurrences of 'this' with '_a_t' String newSnippet = replaceThisReferences(snippet); - + int dimension = 1; IJavaType componentType = arrayType.getComponentType(); while (componentType instanceof IJavaArrayType) { - componentType = ((IJavaArrayType)componentType).getComponentType(); + componentType = ((IJavaArrayType) componentType) + .getComponentType(); dimension++; } - + // Primitive arrays are evaluated in the context of Object. - // Arrays with a base component type of a class or interface are treated - // as Object arrays and evaluated in Object. + // Arrays with a base component type of a class or interface are + // treated + // as Object arrays and evaluated in Object. String recTypeName = "java.lang.Object"; //$NON-NLS-1$ String typeName = arrayType.getName(); if (componentType instanceof IJavaReferenceType) { @@ -325,70 +414,91 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { } typeName = buf.toString(); } - - - String[] localTypesNames= new String[]{typeName}; - String[] localVariables= new String[]{ArrayRuntimeContext.ARRAY_THIS_VARIABLE}; - mapper = new EvaluationSourceGenerator(localTypesNames, localVariables, newSnippet); - - + + String[] localTypesNames = new String[] { typeName }; + String[] localVariables = new String[] { ArrayRuntimeContext.ARRAY_THIS_VARIABLE }; + mapper = new EvaluationSourceGenerator(localTypesNames, + localVariables, newSnippet); + int index = typeName.indexOf('$'); - // if the argument is an inner type, compile in context of outer type so type is visible + // if the argument is an inner type, compile in context of outer + // type so type is visible if (index >= 0) { recTypeName = typeName.substring(0, index); } IJavaType[] javaTypes = getDebugTarget().getJavaTypes(recTypeName); if (javaTypes.length > 0) { IJavaReferenceType recType = (IJavaReferenceType) javaTypes[0]; - unit = parseCompilationUnit(mapper.getSource(recType, getJavaProject(), false).toCharArray(), mapper.getCompilationUnitName(), javaProject); + unit = parseCompilationUnit( + mapper.getSource(recType, getJavaProject(), false) + .toCharArray(), + mapper.getCompilationUnitName(), javaProject); } else { - IStatus status = new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), JDIDebugPlugin.ERROR, EvaluationEngineMessages.ASTEvaluationEngine_1, null); + IStatus status = new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + JDIDebugPlugin.ERROR, + EvaluationEngineMessages.ASTEvaluationEngine_1, null); throw new CoreException(status); } } catch (CoreException e) { - InstructionSequence expression= new InstructionSequence(snippet); + InstructionSequence expression = new InstructionSequence(snippet); expression.addError(e.getStatus().getMessage()); return expression; } - - return createExpressionFromAST(snippet, mapper, unit); + + return createExpressionFromAST(snippet, mapper, unit); } - - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression(java.lang.String, org.eclipse.jdt.debug.core.IJavaObject) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression + * (java.lang.String, org.eclipse.jdt.debug.core.IJavaObject) */ - public ICompiledExpression getCompiledExpression(String snippet, IJavaObject thisContext) { + public ICompiledExpression getCompiledExpression(String snippet, + IJavaObject thisContext) { try { if (thisContext instanceof IJavaArray) { - return getCompiledExpression(snippet, (IJavaArrayType)thisContext.getJavaType()); + return getCompiledExpression(snippet, + (IJavaArrayType) thisContext.getJavaType()); } - return getCompiledExpression(snippet, (IJavaReferenceType)thisContext.getJavaType()); + return getCompiledExpression(snippet, + (IJavaReferenceType) thisContext.getJavaType()); } catch (DebugException e) { - InstructionSequence expression= new InstructionSequence(snippet); + InstructionSequence expression = new InstructionSequence(snippet); expression.addError(e.getStatus().getMessage()); return expression; } - + } - - /* (non-Javadoc) - * @see org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression(java.lang.String, org.eclipse.jdt.debug.core.IJavaType) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.debug.eval.IAstEvaluationEngine#getCompiledExpression + * (java.lang.String, org.eclipse.jdt.debug.core.IJavaType) */ - public ICompiledExpression getCompiledExpression(String snippet, IJavaReferenceType type) { + public ICompiledExpression getCompiledExpression(String snippet, + IJavaReferenceType type) { if (type instanceof IJavaArrayType) { - return getCompiledExpression(snippet, (IJavaArrayType)type); + return getCompiledExpression(snippet, (IJavaArrayType) type); } IJavaProject javaProject = getJavaProject(); EvaluationSourceGenerator mapper = null; CompilationUnit unit = null; - mapper = new EvaluationSourceGenerator(new String[0], new String[0], snippet); + mapper = new EvaluationSourceGenerator(new String[0], new String[0], + snippet); try { - unit = parseCompilationUnit(mapper.getSource(type, javaProject, false).toCharArray(), mapper.getCompilationUnitName(), javaProject); + unit = parseCompilationUnit( + mapper.getSource(type, javaProject, false).toCharArray(), + mapper.getCompilationUnitName(), javaProject); } catch (CoreException e) { - InstructionSequence expression= new InstructionSequence(snippet); + InstructionSequence expression = new InstructionSequence(snippet); expression.addError(e.getStatus().getMessage()); return expression; } @@ -396,101 +506,118 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { } /** - * Creates a compiled expression for the given snippet using the given mapper and - * compilation unit (AST). - * @param snippet the code snippet to be compiled - * @param mapper the object which will be used to create the expression - * @param unit the compilation unit (AST) generated for the snippet + * Creates a compiled expression for the given snippet using the given + * mapper and compilation unit (AST). + * + * @param snippet + * the code snippet to be compiled + * @param mapper + * the object which will be used to create the expression + * @param unit + * the compilation unit (AST) generated for the snippet */ - private ICompiledExpression createExpressionFromAST(String snippet, EvaluationSourceGenerator mapper, CompilationUnit unit) { - IProblem[] problems= unit.getProblems(); + private ICompiledExpression createExpressionFromAST(String snippet, + EvaluationSourceGenerator mapper, CompilationUnit unit) { + IProblem[] problems = unit.getProblems(); if (problems.length != 0) { - boolean snippetError= false; - boolean runMethodError= false; - InstructionSequence errorSequence= new InstructionSequence(snippet); - int codeSnippetStart= mapper.getSnippetStart(); - int codeSnippetEnd= codeSnippetStart + mapper.getSnippet().length(); - int runMethodStart= mapper.getRunMethodStart(); - int runMethodEnd= runMethodStart + mapper.getRunMethodLength(); - for (int i = 0; i < problems.length; i++) { - IProblem problem= problems[i]; - int errorOffset= problem.getSourceStart(); - int problemId= problem.getID(); + boolean snippetError = false; + boolean runMethodError = false; + InstructionSequence errorSequence = new InstructionSequence(snippet); + int codeSnippetStart = mapper.getSnippetStart(); + int codeSnippetEnd = codeSnippetStart + + mapper.getSnippet().length(); + int runMethodStart = mapper.getRunMethodStart(); + int runMethodEnd = runMethodStart + mapper.getRunMethodLength(); + for (IProblem problem : problems) { + int errorOffset = problem.getSourceStart(); + int problemId = problem.getID(); if (problemId == IProblem.IsClassPathCorrect) { errorSequence.addError(problem.getMessage()); snippetError = true; } if (problemId == IProblem.VoidMethodReturnsValue - || problemId == IProblem.NotVisibleMethod - || problemId == IProblem.NotVisibleConstructor - || problemId == IProblem.NotVisibleField - || problemId == IProblem.NotVisibleType) { + || problemId == IProblem.NotVisibleMethod + || problemId == IProblem.NotVisibleConstructor + || problemId == IProblem.NotVisibleField + || problemId == IProblem.NotVisibleType) { continue; } if (problem.isError()) { - if (codeSnippetStart <= errorOffset && errorOffset <= codeSnippetEnd) { + if (codeSnippetStart <= errorOffset + && errorOffset <= codeSnippetEnd) { errorSequence.addError(problem.getMessage()); snippetError = true; - } else if (runMethodStart <= errorOffset && errorOffset <= runMethodEnd) { + } else if (runMethodStart <= errorOffset + && errorOffset <= runMethodEnd) { runMethodError = true; } } } if (snippetError || runMethodError) { if (runMethodError) { - errorSequence.addError(EvaluationEngineMessages.ASTEvaluationEngine_Evaluations_must_contain_either_an_expression_or_a_block_of_well_formed_statements_1); + errorSequence + .addError(EvaluationEngineMessages.ASTEvaluationEngine_Evaluations_must_contain_either_an_expression_or_a_block_of_well_formed_statements_1); } return errorSequence; } } - - ASTInstructionCompiler visitor = new ASTInstructionCompiler(mapper.getSnippetStart(), snippet); + + ASTInstructionCompiler visitor = new ASTInstructionCompiler( + mapper.getSnippetStart(), snippet); unit.accept(visitor); return visitor.getInstructions(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jdt.debug.eval.IEvaluationEngine#getJavaProject() */ public IJavaProject getJavaProject() { return fProject; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jdt.debug.eval.IEvaluationEngine#getDebugTarget() */ public IJavaDebugTarget getDebugTarget() { return fDebugTarget; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jdt.debug.eval.IEvaluationEngine#dispose() */ public void dispose() { } - + class EvalRunnable implements Runnable { - + private InstructionSequence fExpression; - + private IJavaThread fThread; - + private int fEvaluationDetail; - + private boolean fHitBreakpoints; - + private IRuntimeContext fContext; - + private IEvaluationListener fListener; - - public EvalRunnable(InstructionSequence expression, IJavaThread thread, IRuntimeContext context, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) { - fExpression= expression; - fThread= thread; - fContext= context; - fListener= listener; - fEvaluationDetail= evaluationDetail; - fHitBreakpoints= hitBreakpoints; + + public EvalRunnable(InstructionSequence expression, IJavaThread thread, + IRuntimeContext context, IEvaluationListener listener, + int evaluationDetail, boolean hitBreakpoints) { + fExpression = expression; + fThread = thread; + fContext = context; + fListener = listener; + fEvaluationDetail = evaluationDetail; + fHitBreakpoints = hitBreakpoints; } public void run() { @@ -521,11 +648,12 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { buf.append(fHitBreakpoints); System.out.println(buf.toString()); } - EvaluationResult result = new EvaluationResult(ASTEvaluationEngine.this, fExpression.getSnippet(), fThread); + EvaluationResult result = new EvaluationResult( + ASTEvaluationEngine.this, fExpression.getSnippet(), fThread); if (fExpression.hasErrors()) { String[] errors = fExpression.getErrorMessages(); - for (int i = 0, numErrors = errors.length; i < numErrors; i++) { - result.addError(errors[i]); + for (String error : errors) { + result.addError(error); } evaluationFinished(result); if (JDIDebugOptions.DEBUG_AST_EVAL) { @@ -542,13 +670,14 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { } return; } - final Interpreter interpreter = new Interpreter(fExpression, fContext); - + final Interpreter interpreter = new Interpreter(fExpression, + fContext); + class EvaluationRunnable implements IEvaluationRunnable, ITerminate { - + CoreException fException; boolean fTerminated = false; - + public void run(IJavaThread jt, IProgressMonitor pm) { EventFilter filter = new EventFilter(); try { @@ -556,13 +685,22 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { interpreter.execute(); } catch (CoreException exception) { fException = exception; - if (fEvaluationDetail == DebugEvent.EVALUATION && exception.getStatus().getException() instanceof InvocationException) { - // print the stack trace for the exception if an *explicit* evaluation - InvocationException invocationException = (InvocationException)exception.getStatus().getException(); - ObjectReference exObject = invocationException.exception(); - IJavaObject modelObject = (IJavaObject)JDIValue.createValue((JDIDebugTarget)getDebugTarget(), exObject); + if (fEvaluationDetail == DebugEvent.EVALUATION + && exception.getStatus().getException() instanceof InvocationException) { + // print the stack trace for the exception if an + // *explicit* evaluation + InvocationException invocationException = (InvocationException) exception + .getStatus().getException(); + ObjectReference exObject = invocationException + .exception(); + IJavaObject modelObject = (IJavaObject) JDIValue + .createValue( + (JDIDebugTarget) getDebugTarget(), + exObject); try { - modelObject.sendMessage("printStackTrace", "()V", null, jt, false); //$NON-NLS-1$ //$NON-NLS-2$ + modelObject + .sendMessage( + "printStackTrace", "()V", null, jt, false); //$NON-NLS-1$ //$NON-NLS-2$ } catch (DebugException e) { // unable to print stack trace } @@ -571,17 +709,20 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { DebugPlugin.getDefault().removeDebugEventFilter(filter); } } + public void terminate() { fTerminated = true; interpreter.stop(); } + public boolean canTerminate() { return true; } + public boolean isTerminated() { return false; } - + public CoreException getException() { return fException; } @@ -591,18 +732,19 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { CoreException exception = null; long start = System.currentTimeMillis(); try { - fThread.runEvaluation(er, null, fEvaluationDetail, fHitBreakpoints); + fThread.runEvaluation(er, null, fEvaluationDetail, + fHitBreakpoints); } catch (DebugException e) { exception = e; } long end = System.currentTimeMillis(); - - IJavaValue value = interpreter.getResult(); + + IJavaValue value = interpreter.getResult(); if (exception == null) { exception = er.getException(); } - + result.setTerminated(er.fTerminated); if (exception != null) { if (JDIDebugOptions.DEBUG_AST_EVAL) { @@ -611,25 +753,26 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { buf.append(exception.toString()); System.out.println(buf.toString()); } - if (exception instanceof DebugException) { - result.setException((DebugException)exception); - } else { - result.setException(new DebugException(exception.getStatus())); - } - } else { - if (value != null) { - result.setValue(value); - if (JDIDebugOptions.DEBUG_AST_EVAL) { + if (exception instanceof DebugException) { + result.setException((DebugException) exception); + } else { + result.setException(new DebugException(exception + .getStatus())); + } + } else { + if (value != null) { + result.setValue(value); + if (JDIDebugOptions.DEBUG_AST_EVAL) { StringBuffer buf = new StringBuffer(); buf.append("\tResult: "); //$NON-NLS-1$ buf.append(value); System.out.println(buf.toString()); } - } else { - result.addError(EvaluationEngineMessages.ASTEvaluationEngine_An_unknown_error_occurred_during_evaluation); - } + } else { + result.addError(EvaluationEngineMessages.ASTEvaluationEngine_An_unknown_error_occurred_during_evaluation); + } } - + if (JDIDebugOptions.DEBUG_AST_EVAL) { StringBuffer buf = new StringBuffer(); buf.append("\tDuration: "); //$NON-NLS-1$ @@ -637,22 +780,24 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { buf.append("ms"); //$NON-NLS-1$ System.out.println(buf.toString()); } - + evaluationFinished(result); } + private void evaluationFinished(IEvaluationResult result) { // only notify if plug-in not yet shutdown - bug# 8693 - if(JDIDebugPlugin.getDefault() != null) { + if (JDIDebugPlugin.getDefault() != null) { fListener.evaluationComplete(result); } } - + } - + /** * Replaces references to 'this' with the 'array_this' variable. * - * @param snippet code snippet + * @param snippet + * code snippet * @return snippet with 'this' references replaced */ public static String replaceThisReferences(String snippet) { 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; } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/AbstractRuntimeContext.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/AbstractRuntimeContext.java index e73d87baf..76e5a7495 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/AbstractRuntimeContext.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/AbstractRuntimeContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,149 +29,178 @@ import com.ibm.icu.text.MessageFormat; import com.sun.jdi.InvocationException; /** - * Common runtime context code for class loading and cache of - * class loader/java.lang.Class. + * Common runtime context code for class loading and cache of class + * loader/java.lang.Class. * * @since 3.2 */ public abstract class AbstractRuntimeContext implements IRuntimeContext { - - /** - * Cache of class loader for this runtime context - */ - private IJavaObject fClassLoader; - - /** - * Cache of java.lang.Class type - */ - private IJavaClassType fJavaLangClass; - - /** - * Java project context - */ + + /** + * Cache of class loader for this runtime context + */ + private IJavaObject fClassLoader; + + /** + * Cache of java.lang.Class type + */ + private IJavaClassType fJavaLangClass; + + /** + * Java project context + */ protected IJavaProject fProject; - - public static final String CLASS= "java.lang.Class"; //$NON-NLS-1$ - public static final String FOR_NAME= "forName"; //$NON-NLS-1$ - public static final String FOR_NAME_SIGNATURE= "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"; //$NON-NLS-1$ - - - public AbstractRuntimeContext(IJavaProject project) { - fProject = project; - } - - /** - * Returns the class loader used to load classes for this runtime context - * or <code>null</code> when loaded by the bootstrap loader - * - * @return the class loader used to load classes for this runtime context or - * <code>null</code> when loaded by the bootstrap loader - * @throws CoreException if unable to resolve a class loader - */ - protected IJavaObject getClassLoaderObject() throws CoreException { - if (fClassLoader == null) { - fClassLoader = getReceivingType().getClassLoaderObject(); - } - return fClassLoader; - } - - /** - * Return the java.lang.Class type. - * - * @return the java.lang.Class type - * @throws CoreException if unable to retrive the type - */ - protected IJavaClassType getJavaLangClass() throws CoreException { - if (fJavaLangClass == null) { - IJavaType[] types= getVM().getJavaTypes(CLASS); - if (types == null || types.length != 1) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{CLASS}), null)); - } - fJavaLangClass = (IJavaClassType) types[0]; - } - return fJavaLangClass; - } - - /** - * Invokes Class.classForName(String, boolean, ClassLoader) on the target - * to force load the specified class. - * - * @param qualifiedName name of class to load - * @param loader the class loader to use or <code>null</code> if the bootstrap loader - * @return the loaded class - * @throws CoreException if loading fails - */ - protected IJavaClassObject classForName(String qualifiedName, IJavaObject loader) throws CoreException { - String tname = qualifiedName; - if (tname.startsWith("[")) { //$NON-NLS-1$ - tname = TypeImpl.signatureToName(qualifiedName); - } + + public static final String CLASS = "java.lang.Class"; //$NON-NLS-1$ + public static final String FOR_NAME = "forName"; //$NON-NLS-1$ + public static final String FOR_NAME_SIGNATURE = "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"; //$NON-NLS-1$ + + public AbstractRuntimeContext(IJavaProject project) { + fProject = project; + } + + /** + * Returns the class loader used to load classes for this runtime context or + * <code>null</code> when loaded by the bootstrap loader + * + * @return the class loader used to load classes for this runtime context or + * <code>null</code> when loaded by the bootstrap loader + * @throws CoreException + * if unable to resolve a class loader + */ + protected IJavaObject getClassLoaderObject() throws CoreException { + if (fClassLoader == null) { + fClassLoader = getReceivingType().getClassLoaderObject(); + } + return fClassLoader; + } + + /** + * Return the java.lang.Class type. + * + * @return the java.lang.Class type + * @throws CoreException + * if unable to retrive the type + */ + protected IJavaClassType getJavaLangClass() throws CoreException { + if (fJavaLangClass == null) { + IJavaType[] types = getVM().getJavaTypes(CLASS); + if (types == null || types.length != 1) { + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.Instruction_No_type, + new Object[] { CLASS }), null)); + } + fJavaLangClass = (IJavaClassType) types[0]; + } + return fJavaLangClass; + } + + /** + * Invokes Class.classForName(String, boolean, ClassLoader) on the target to + * force load the specified class. + * + * @param qualifiedName + * name of class to load + * @param loader + * the class loader to use or <code>null</code> if the bootstrap + * loader + * @return the loaded class + * @throws CoreException + * if loading fails + */ + protected IJavaClassObject classForName(String qualifiedName, + IJavaObject loader) throws CoreException { + String tname = qualifiedName; + if (tname.startsWith("[")) { //$NON-NLS-1$ + tname = TypeImpl.signatureToName(qualifiedName); + } IJavaType[] types = getVM().getJavaTypes(tname); if (types != null && types.length > 0) { // find the one with the right class loader - for (int i = 0; i < types.length; i++) { - IJavaReferenceType type = (IJavaReferenceType) types[i]; + for (IJavaType type2 : types) { + IJavaReferenceType type = (IJavaReferenceType) type2; IJavaObject cloader = type.getClassLoaderObject(); if (isCompatibleLoader(loader, cloader)) { return type.getClassObject(); } } } - IJavaValue loaderArg = loader; - if (loader == null) { - loaderArg = getVM().nullValue(); - } - //prevent the name string from being collected during the class lookup call - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=301412 - final IJavaValue name = getVM().newValue(qualifiedName); - ((IJavaObject)name).disableCollection(); - IJavaValue[] args = new IJavaValue[] {name, getVM().newValue(true), loaderArg}; - try { - return (IJavaClassObject) getJavaLangClass().sendMessage(FOR_NAME, FOR_NAME_SIGNATURE, args, getThread()); - } catch (CoreException e) { - if (e.getStatus().getException() instanceof InvocationException) { - // Don't throw ClassNotFoundException - if (((InvocationException)e.getStatus().getException()).exception().referenceType().name().equals("java.lang.ClassNotFoundException")) { //$NON-NLS-1$ - return null; - } - } - throw e; - } - finally { - ((IJavaObject)name).enableCollection(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#classForName(java.lang.String) - */ - public IJavaClassObject classForName(String name) throws CoreException { - return classForName(name, getClassLoaderObject()); - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getProject() + IJavaValue loaderArg = loader; + if (loader == null) { + loaderArg = getVM().nullValue(); + } + // prevent the name string from being collected during the class lookup + // call + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=301412 + final IJavaValue name = getVM().newValue(qualifiedName); + ((IJavaObject) name).disableCollection(); + IJavaValue[] args = new IJavaValue[] { name, getVM().newValue(true), + loaderArg }; + try { + return (IJavaClassObject) getJavaLangClass().sendMessage(FOR_NAME, + FOR_NAME_SIGNATURE, args, getThread()); + } catch (CoreException e) { + if (e.getStatus().getException() instanceof InvocationException) { + // Don't throw ClassNotFoundException + if (((InvocationException) e.getStatus().getException()) + .exception().referenceType().name() + .equals("java.lang.ClassNotFoundException")) { //$NON-NLS-1$ + return null; + } + } + throw e; + } finally { + ((IJavaObject) name).enableCollection(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#classForName + * (java.lang.String) + */ + public IJavaClassObject classForName(String name) throws CoreException { + return classForName(name, getClassLoaderObject()); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getProject + * () */ public IJavaProject getProject() { return fProject; } - + /** - * Returns whether the class loaded by the <code>otherLoader</code> is compatible - * with the receiver's class loader. To be compatible, the other's loader must - * be the same or a parent of the receiver's loader. + * Returns whether the class loaded by the <code>otherLoader</code> is + * compatible with the receiver's class loader. To be compatible, the + * other's loader must be the same or a parent of the receiver's loader. * - * @param recLoader class loader of receiver - * @param otherLoader class loader of other class + * @param recLoader + * class loader of receiver + * @param otherLoader + * class loader of other class * @return whether compatible */ - private boolean isCompatibleLoader(IJavaObject recLoader, IJavaObject otherLoader) throws CoreException { + private boolean isCompatibleLoader(IJavaObject recLoader, + IJavaObject otherLoader) throws CoreException { if (recLoader == null || otherLoader == null) { - // if either class is a bootstrap loader, then they are compatible since all loaders + // if either class is a bootstrap loader, then they are compatible + // since all loaders // stem from the bootstrap loader return true; - } + } if (recLoader.equals(otherLoader)) { return true; } @@ -185,30 +214,33 @@ public abstract class AbstractRuntimeContext implements IRuntimeContext { } return false; } - + /** - * Returns the parent class loader of the given class loader object or <code>null</code> - * if none. + * Returns the parent class loader of the given class loader object or + * <code>null</code> if none. * - * @param loader class loader object + * @param loader + * class loader object * @return parent class loader or <code>null</code> * @throws CoreException */ - private IJavaObject getParentLoader(IJavaObject loader) throws CoreException { + private IJavaObject getParentLoader(IJavaObject loader) + throws CoreException { // to avoid message send, first check for 'parent' field IJavaFieldVariable field = loader.getField("parent", false); //$NON-NLS-1$ if (field != null) { - IJavaValue value = (IJavaValue)field.getValue(); + IJavaValue value = (IJavaValue) field.getValue(); if (value.isNull()) { return null; } - return (IJavaObject)value; + return (IJavaObject) value; } - IJavaValue result = loader.sendMessage("getParent", "()Ljava/lang/ClassLoader;", null, getThread(), false); //$NON-NLS-1$ //$NON-NLS-2$ + IJavaValue result = loader + .sendMessage( + "getParent", "()Ljava/lang/ClassLoader;", null, getThread(), false); //$NON-NLS-1$ //$NON-NLS-2$ if (result.isNull()) { return null; } - return (IJavaObject)result; + return (IJavaObject) result; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ArrayRuntimeContext.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ArrayRuntimeContext.java index ece66aa65..ef1d6a44b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ArrayRuntimeContext.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ArrayRuntimeContext.java @@ -28,41 +28,52 @@ import org.eclipse.jdt.internal.debug.core.logicalstructures.JDIPlaceholderVaria * Context for evaluation of an expression in the receiver context of an array. */ public class ArrayRuntimeContext extends AbstractRuntimeContext { - + /** - * Name used for temp variable referring to array (replaces 'this'). - * The same length as "this" so it does not affect code assist. + * Name used for temp variable referring to array (replaces 'this'). The + * same length as "this" so it does not affect code assist. */ public static String ARRAY_THIS_VARIABLE = "_a_t"; //$NON-NLS-1$ - + private IJavaArray fArray = null; private IJavaReferenceType fReceivingType = null; private IJavaThread fThread = null; private IJavaVariable fLocalArray = null; - - public ArrayRuntimeContext(IJavaArray arrayObject, IJavaThread thread, IJavaProject project) { + + public ArrayRuntimeContext(IJavaArray arrayObject, IJavaThread thread, + IJavaProject project) { super(project); fArray = arrayObject; fThread = thread; - fLocalArray = new JDIPlaceholderVariable(ARRAY_THIS_VARIABLE, arrayObject); + fLocalArray = new JDIPlaceholderVariable(ARRAY_THIS_VARIABLE, + arrayObject); } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getVM() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getVM() */ public IJavaDebugTarget getVM() { return (IJavaDebugTarget) fArray.getDebugTarget(); } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThis() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThis() */ public IJavaObject getThis() throws CoreException { return null; } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getReceivingType() + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext# + * getReceivingType() */ public IJavaReferenceType getReceivingType() throws CoreException { if (fReceivingType == null) { @@ -70,29 +81,44 @@ public class ArrayRuntimeContext extends AbstractRuntimeContext { if (javaTypes.length > 0) { fReceivingType = (IJavaReferenceType) javaTypes[0]; } else { - IStatus status = new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), JDIDebugPlugin.INTERNAL_ERROR, EvaluationEngineMessages.ArrayRuntimeContext_0, null); + IStatus status = new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + JDIDebugPlugin.INTERNAL_ERROR, + EvaluationEngineMessages.ArrayRuntimeContext_0, null); throw new CoreException(status); } } return fReceivingType; } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getLocals() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getLocals + * () */ public IJavaVariable[] getLocals() throws CoreException { - return new IJavaVariable[]{fLocalArray}; + return new IJavaVariable[] { fLocalArray }; } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThread() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThread + * () */ public IJavaThread getThread() { return fThread; } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#isConstructor() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#isConstructor + * () */ public boolean isConstructor() throws CoreException { return false; diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/BinaryBasedSourceGenerator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/BinaryBasedSourceGenerator.java index 58203a1a5..7d9199719 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/BinaryBasedSourceGenerator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/BinaryBasedSourceGenerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import java.util.Iterator; import java.util.List; @@ -28,82 +27,86 @@ import com.sun.jdi.ReferenceType; import com.sun.jdi.Type; public class BinaryBasedSourceGenerator { - - private static final String RUN_METHOD_NAME= "___run"; //$NON-NLS-1$ - private static final String EVAL_METHOD_NAME= "___eval"; //$NON-NLS-1$ - private static final String ANONYMOUS_CLASS_NAME= "___EvalClass"; //$NON-NLS-1$ - - + + private static final String RUN_METHOD_NAME = "___run"; //$NON-NLS-1$ + private static final String EVAL_METHOD_NAME = "___eval"; //$NON-NLS-1$ + private static final String ANONYMOUS_CLASS_NAME = "___EvalClass"; //$NON-NLS-1$ + private String[] fLocalVariableTypeNames; - + private String[] fLocalVariableNames; - + private boolean fIsInStaticMethod; - + private StringBuffer fSource; - + private int fRunMethodStartOffset; private int fRunMethodLength; private int fCodeSnippetPosition; - + private String fCompilationUnitName; - + /** - * Level of source code to generate (major, minor). For example 1 and 4 + * Level of source code to generate (major, minor). For example 1 and 4 * indicates 1.4. */ private int fSourceMajorLevel; private int fSourceMinorLevel; - - public BinaryBasedSourceGenerator(String[] localTypesNames, String[] localVariables, boolean isInStaticMethod, String sourceLevel) { - fLocalVariableTypeNames= localTypesNames; - fLocalVariableNames= localVariables; - fIsInStaticMethod= isInStaticMethod; + + public BinaryBasedSourceGenerator(String[] localTypesNames, + String[] localVariables, boolean isInStaticMethod, + String sourceLevel) { + fLocalVariableTypeNames = localTypesNames; + fLocalVariableNames = localVariables; + fIsInStaticMethod = isInStaticMethod; int index = sourceLevel.indexOf('.'); String num = sourceLevel.substring(0, index); fSourceMajorLevel = Integer.valueOf(num).intValue(); num = sourceLevel.substring(index + 1); fSourceMinorLevel = Integer.valueOf(num).intValue(); } - + /** * Build source for an object value (instance context) */ public void buildSource(JDIReferenceType referenceType) { - ReferenceType reference= (ReferenceType)referenceType.getUnderlyingType(); - fSource= buildTypeDeclaration(reference, buildRunMethod(reference), null); + ReferenceType reference = (ReferenceType) referenceType + .getUnderlyingType(); + fSource = buildTypeDeclaration(reference, buildRunMethod(reference), + null); } - + /** * Build source for a class type (static context) */ public void buildSourceStatic(IJavaReferenceType type) { - Type underlyingType= ((JDIReferenceType)type).getUnderlyingType(); + Type underlyingType = ((JDIReferenceType) type).getUnderlyingType(); if (!(underlyingType instanceof ReferenceType)) { return; } - ReferenceType refType= (ReferenceType)underlyingType; - fSource= buildTypeDeclaration(refType, buildRunMethod(refType), null, false); + ReferenceType refType = (ReferenceType) underlyingType; + fSource = buildTypeDeclaration(refType, buildRunMethod(refType), null, + false); String packageName = getPackageName(refType.name()); if (packageName != null) { fSource.insert(0, "package " + packageName + ";\n"); //$NON-NLS-1$ //$NON-NLS-2$ fCodeSnippetPosition += 10 + packageName.length(); } - fCompilationUnitName= getSimpleName(refType.name()); + fCompilationUnitName = getSimpleName(refType.name()); } - + protected String getUniqueMethodName(String methodName, ReferenceType type) { - List methods= type.methodsByName(methodName); + List<Method> methods = type.methodsByName(methodName); while (!methods.isEmpty()) { methodName += '_'; - methods= type.methodsByName(methodName); + methods = type.methodsByName(methodName); } return methodName; } - + private StringBuffer buildRunMethod(ReferenceType type) { StringBuffer source = new StringBuffer(); - + if (isInStaticMethod()) { source.append("static "); //$NON-NLS-1$ } @@ -111,7 +114,7 @@ public class BinaryBasedSourceGenerator { source.append("void "); //$NON-NLS-1$ source.append(getUniqueMethodName(RUN_METHOD_NAME, type)); source.append('('); - for(int i= 0, length= fLocalVariableNames.length; i < length; i++) { + for (int i = 0, length = fLocalVariableNames.length; i < length; i++) { source.append(getDotName(fLocalVariableTypeNames[i])); source.append(' '); source.append(fLocalVariableNames[i]); @@ -120,30 +123,32 @@ public class BinaryBasedSourceGenerator { } source.append(") throws Throwable {"); //$NON-NLS-1$ source.append('\n'); - fCodeSnippetPosition= source.length(); - fRunMethodStartOffset= fCodeSnippetPosition; + fCodeSnippetPosition = source.length(); + fRunMethodStartOffset = fCodeSnippetPosition; source.append('\n'); source.append('}').append('\n'); - fRunMethodLength= source.length(); + fRunMethodLength = source.length(); return source; } - - private StringBuffer buildTypeDeclaration(ReferenceType referenceType, StringBuffer buffer, String nestedTypeName) { - - Field thisField= null; - - List fields= referenceType.visibleFields(); - for (Iterator iterator= fields.iterator(); iterator.hasNext();) { - Field field= (Field) iterator.next(); + + private StringBuffer buildTypeDeclaration(ReferenceType referenceType, + StringBuffer buffer, String nestedTypeName) { + + Field thisField = null; + + List<Field> fields = referenceType.visibleFields(); + for (Iterator<Field> iterator = fields.iterator(); iterator.hasNext();) { + Field field = iterator.next(); if (field.name().startsWith("this$")) { //$NON-NLS-1$ thisField = field; break; } } - - StringBuffer source = buildTypeDeclaration(referenceType, buffer, nestedTypeName, thisField != null); - + + StringBuffer source = buildTypeDeclaration(referenceType, buffer, + nestedTypeName, thisField != null); + if (thisField == null) { String packageName = getPackageName(referenceType.name()); if (packageName != null) { @@ -151,38 +156,43 @@ public class BinaryBasedSourceGenerator { fCodeSnippetPosition += 10 + packageName.length(); } if (isAnonymousTypeName(referenceType.name())) { - fCompilationUnitName= ANONYMOUS_CLASS_NAME; + fCompilationUnitName = ANONYMOUS_CLASS_NAME; } else { - fCompilationUnitName= getSimpleName(referenceType.name()); + fCompilationUnitName = getSimpleName(referenceType.name()); } } else { try { - return buildTypeDeclaration((ReferenceType) thisField.type(), source, referenceType.name()); + return buildTypeDeclaration((ReferenceType) thisField.type(), + source, referenceType.name()); } catch (ClassNotLoadedException e) { } } - + return source; } - private StringBuffer buildTypeDeclaration(ReferenceType referenceType, StringBuffer buffer, String nestedTypeName, boolean hasEnclosingInstance) { - StringBuffer source= new StringBuffer(); - - String typeName= referenceType.name(); - - boolean isAnonymousType= isAnonymousTypeName(typeName); - + private StringBuffer buildTypeDeclaration(ReferenceType referenceType, + StringBuffer buffer, String nestedTypeName, + boolean hasEnclosingInstance) { + StringBuffer source = new StringBuffer(); + + String typeName = referenceType.name(); + + boolean isAnonymousType = isAnonymousTypeName(typeName); + if (isAnonymousType) { - ClassType classType= (ClassType) referenceType; - - List interfaceList= classType.interfaces(); - String superClassName= classType.superclass().name(); + ClassType classType = (ClassType) referenceType; + + List<InterfaceType> interfaceList = classType.interfaces(); + String superClassName = classType.superclass().name(); if (hasEnclosingInstance) { source.append("void "); //$NON-NLS-1$ - source.append(getUniqueMethodName(EVAL_METHOD_NAME, referenceType)); + source.append(getUniqueMethodName(EVAL_METHOD_NAME, + referenceType)); source.append("() {\nnew "); //$NON-NLS-1$ if (interfaceList.size() != 0) { - source.append(getDotName(((InterfaceType)interfaceList.get(0)).name())); + source.append(getDotName(interfaceList + .get(0).name())); } else { source.append(getDotName(superClassName)); } @@ -190,160 +200,178 @@ public class BinaryBasedSourceGenerator { } else { source.append("public class ").append(ANONYMOUS_CLASS_NAME).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ if (interfaceList.size() != 0) { - source.append(" implements ").append(getDotName(((InterfaceType)interfaceList.get(0)).name())); //$NON-NLS-1$ + source.append(" implements ").append(getDotName(interfaceList.get(0).name())); //$NON-NLS-1$ } else { source.append(" extends ").append(getDotName(superClassName)); //$NON-NLS-1$ } } - + } else { if (referenceType.isFinal()) { source.append("final "); //$NON-NLS-1$ } - + if (referenceType.isStatic()) { source.append("static "); //$NON-NLS-1$ } - + if (referenceType instanceof ClassType) { - ClassType classType= (ClassType) referenceType; - + ClassType classType = (ClassType) referenceType; + if (classType.isAbstract()) { source.append("abstract "); //$NON-NLS-1$ } - + source.append("class "); //$NON-NLS-1$ source.append(getSimpleName(typeName)).append(' '); - String genericSignature= referenceType.genericSignature(); - if (genericSignature != null && isSourceLevelGreaterOrEqual(1, 5)) { - String[] typeParameters= Signature.getTypeParameters(genericSignature); + String genericSignature = referenceType.genericSignature(); + if (genericSignature != null + && isSourceLevelGreaterOrEqual(1, 5)) { + String[] typeParameters = Signature + .getTypeParameters(genericSignature); if (typeParameters.length > 0) { source.append('<'); - source.append(Signature.getTypeVariable(typeParameters[0])); - String[] typeParameterBounds= Signature.getTypeParameterBounds(typeParameters[0]); + source.append(Signature + .getTypeVariable(typeParameters[0])); + String[] typeParameterBounds = Signature + .getTypeParameterBounds(typeParameters[0]); source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$ - for (int i= 1; i < typeParameterBounds.length; i++) { + for (int i = 1; i < typeParameterBounds.length; i++) { source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$ } - for (int j= 1; j < typeParameters.length; j++) { - source.append(',').append(Signature.getTypeVariable(typeParameters[j])); - typeParameterBounds= Signature.getTypeParameterBounds(typeParameters[j]); + for (int j = 1; j < typeParameters.length; j++) { + source.append(',') + .append(Signature + .getTypeVariable(typeParameters[j])); + typeParameterBounds = Signature + .getTypeParameterBounds(typeParameters[j]); source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$ - for (int i= 1; i < typeParameterBounds.length; i++) { + for (int i = 1; i < typeParameterBounds.length; i++) { source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$ } } source.append("> "); //$NON-NLS-1$ } - String[] superClassInterfaces= SignatureExt.getTypeSuperClassInterfaces(genericSignature); - int length= superClassInterfaces.length; + String[] superClassInterfaces = SignatureExt + .getTypeSuperClassInterfaces(genericSignature); + int length = superClassInterfaces.length; if (length > 0) { source.append("extends ").append(Signature.toString(superClassInterfaces[0]).replace('/', '.')); //$NON-NLS-1$ if (length > 1) { source.append(" implements ").append(Signature.toString(superClassInterfaces[1]).replace('/', '.')); //$NON-NLS-1$ for (int i = 2; i < length; i++) { - source.append(',').append(Signature.toString(superClassInterfaces[1])); + source.append(',') + .append(Signature + .toString(superClassInterfaces[1])); } } } } else { - - ClassType superClass= classType.superclass(); + + ClassType superClass = classType.superclass(); if (superClass != null) { source.append("extends ").append(getDotName(superClass.name())).append(' '); //$NON-NLS-1$ } - - List interfaces; + + List<InterfaceType> interfaces; try { - interfaces= classType.interfaces(); + interfaces = classType.interfaces(); } catch (ClassNotPreparedException e) { return new StringBuffer(); } if (interfaces.size() != 0) { source.append("implements "); //$NON-NLS-1$ - Iterator iterator= interfaces.iterator(); - InterfaceType interface_= (InterfaceType)iterator.next(); + Iterator<InterfaceType> iterator = interfaces.iterator(); + InterfaceType interface_ = iterator + .next(); source.append(getDotName(interface_.name())); while (iterator.hasNext()) { - source.append(',').append(getDotName(((InterfaceType)iterator.next()).name())); + source.append(',') + .append(getDotName(iterator + .next().name())); } } } } else if (referenceType instanceof InterfaceType) { if (buffer != null) { source.append("abstract class "); //$NON-NLS-1$ - source.append(getSimpleName(typeName)).append("___ implements "); //$NON-NLS-1$ + source.append(getSimpleName(typeName)).append( + "___ implements "); //$NON-NLS-1$ source.append(typeName.replace('$', '.')).append(" {\n"); //$NON-NLS-1$ fCodeSnippetPosition += source.length(); source.append(buffer).append("}\n"); //$NON-NLS-1$ } - + return source; } } - + source.append(" {\n"); //$NON-NLS-1$ - + if (buffer != null && !(referenceType instanceof InterfaceType)) { fCodeSnippetPosition += source.length(); source.append(buffer); } - - List fields= referenceType.fields(); - for (Iterator iterator= fields.iterator(); iterator.hasNext();) { - Field field= (Field) iterator.next(); + + List<Field> fields = referenceType.fields(); + for (Iterator<Field> iterator = fields.iterator(); iterator.hasNext();) { + Field field = iterator.next(); if (!field.name().startsWith("this$")) { //$NON-NLS-1$ source.append(buildFieldDeclaration(field)); } } - - List methods= referenceType.methods(); - for (Iterator iterator = methods.iterator(); iterator.hasNext();) { - Method method= (Method) iterator.next(); - if (!method.isConstructor() && !method.isStaticInitializer() && !method.isBridge()) { + + List<Method> methods = referenceType.methods(); + for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) { + Method method = iterator.next(); + if (!method.isConstructor() && !method.isStaticInitializer() + && !method.isBridge()) { source.append(buildMethodDeclaration(method)); } } - - List nestedTypes= referenceType.nestedTypes(); + + List<ReferenceType> nestedTypes = referenceType.nestedTypes(); if (nestedTypeName == null) { - for (Iterator iterator = nestedTypes.iterator(); iterator.hasNext();) { - ReferenceType nestedType= (ReferenceType) iterator.next(); + for (Iterator<ReferenceType> iterator = nestedTypes.iterator(); iterator.hasNext();) { + ReferenceType nestedType = iterator.next(); if (isADirectInnerType(typeName, nestedType.name())) { - source.append(buildTypeDeclaration(nestedType, null, null, true)); + source.append(buildTypeDeclaration(nestedType, null, null, + true)); } } } else { - for (Iterator iterator = nestedTypes.iterator(); iterator.hasNext();) { - ReferenceType nestedType= (ReferenceType) iterator.next(); - if (!nestedTypeName.equals(nestedType.name()) && isADirectInnerType(typeName, nestedType.name())) { - source.append(buildTypeDeclaration(nestedType, null, null, true)); + for (Iterator<ReferenceType> iterator = nestedTypes.iterator(); iterator.hasNext();) { + ReferenceType nestedType = iterator.next(); + if (!nestedTypeName.equals(nestedType.name()) + && isADirectInnerType(typeName, nestedType.name())) { + source.append(buildTypeDeclaration(nestedType, null, null, + true)); } } } - + if (isAnonymousType & hasEnclosingInstance) { source.append("};\n"); //$NON-NLS-1$ } - + source.append("}\n"); //$NON-NLS-1$ - + return source; } - + private StringBuffer buildFieldDeclaration(Field field) { StringBuffer source = new StringBuffer(); - + if (field.isFinal()) { source.append("final "); //$NON-NLS-1$ } - + if (field.isStatic()) { source.append("static "); //$NON-NLS-1$ } - + if (field.isPublic()) { source.append("public "); //$NON-NLS-1$ } else if (field.isPrivate()) { @@ -351,29 +379,30 @@ public class BinaryBasedSourceGenerator { } else if (field.isProtected()) { source.append("protected "); //$NON-NLS-1$ } - - source.append(getDotName(field.typeName())).append(' ').append(field.name()).append(';').append('\n'); - + + source.append(getDotName(field.typeName())).append(' ') + .append(field.name()).append(';').append('\n'); + return source; } - + private StringBuffer buildMethodDeclaration(Method method) { - StringBuffer source= new StringBuffer(); - + StringBuffer source = new StringBuffer(); + if (method.isFinal()) { source.append("final "); //$NON-NLS-1$ } - + if (method.isStatic()) { source.append("static "); //$NON-NLS-1$ } - + if (method.isNative()) { source.append("native "); //$NON-NLS-1$ } else if (method.isAbstract()) { source.append("abstract "); //$NON-NLS-1$ } - + if (method.isPublic()) { source.append("public "); //$NON-NLS-1$ } else if (method.isPrivate()) { @@ -381,62 +410,87 @@ public class BinaryBasedSourceGenerator { } else if (method.isProtected()) { source.append("protected "); //$NON-NLS-1$ } - - String genericSignature= method.genericSignature(); + + String genericSignature = method.genericSignature(); if (genericSignature != null && isSourceLevelGreaterOrEqual(1, 5)) { - String[] typeParameters= Signature.getTypeParameters(genericSignature); + String[] typeParameters = Signature + .getTypeParameters(genericSignature); if (typeParameters.length > 0) { source.append('<'); source.append(Signature.getTypeVariable(typeParameters[0])); - String[] typeParameterBounds= Signature.getTypeParameterBounds(typeParameters[0]); + String[] typeParameterBounds = Signature + .getTypeParameterBounds(typeParameters[0]); source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$ - for (int i= 1; i < typeParameterBounds.length; i++) { + for (int i = 1; i < typeParameterBounds.length; i++) { source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$ } - for (int j= 1; j < typeParameters.length; j++) { - source.append(',').append(Signature.getTypeVariable(typeParameters[j])); - typeParameterBounds= Signature.getTypeParameterBounds(typeParameters[j]); + for (int j = 1; j < typeParameters.length; j++) { + source.append(',').append( + Signature.getTypeVariable(typeParameters[j])); + typeParameterBounds = Signature + .getTypeParameterBounds(typeParameters[j]); source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$ - for (int i= 1; i < typeParameterBounds.length; i++) { + for (int i = 1; i < typeParameterBounds.length; i++) { source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$ } } source.append("> "); //$NON-NLS-1$ } - - source.append(Signature.toString(Signature.getReturnType(genericSignature)).replace('/', '.')).append(' ').append(method.name()).append('('); - - String[] parameterTypes= Signature.getParameterTypes(genericSignature); - int i= 0; + + source.append( + Signature.toString( + Signature.getReturnType(genericSignature)).replace( + '/', '.')).append(' ').append(method.name()) + .append('('); + + String[] parameterTypes = Signature + .getParameterTypes(genericSignature); + int i = 0; if (parameterTypes.length != 0) { - source.append(Signature.toString(parameterTypes[0]).replace('/', '.')).append(" arg").append(i++); //$NON-NLS-1$ + source.append( + Signature.toString(parameterTypes[0]).replace('/', '.')) + .append(" arg").append(i++); //$NON-NLS-1$ if (method.isVarArgs()) { - for (int j= 1; j < parameterTypes.length - 1; j++) { - source.append(',').append(Signature.toString(parameterTypes[j]).replace('/', '.')).append(" arg").append(i++); //$NON-NLS-1$ + for (int j = 1; j < parameterTypes.length - 1; j++) { + source.append(',') + .append(Signature.toString(parameterTypes[j]) + .replace('/', '.')) + .append(" arg").append(i++); //$NON-NLS-1$ } - String typeName= Signature.toString(parameterTypes[parameterTypes.length - 1]).replace('/', '.'); - source.append(',').append(typeName.substring(0,typeName.length() - 2)).append("...").append(" arg").append(i++); //$NON-NLS-1$ //$NON-NLS-2$ + String typeName = Signature.toString( + parameterTypes[parameterTypes.length - 1]).replace( + '/', '.'); + source.append(',') + .append(typeName.substring(0, typeName.length() - 2)) + .append("...").append(" arg").append(i++); //$NON-NLS-1$ //$NON-NLS-2$ } else { - for (int j= 1; j < parameterTypes.length; j++) { - source.append(',').append(Signature.toString(parameterTypes[j]).replace('/', '.')).append(" arg").append(i++); //$NON-NLS-1$ + for (int j = 1; j < parameterTypes.length; j++) { + source.append(',') + .append(Signature.toString(parameterTypes[j]) + .replace('/', '.')) + .append(" arg").append(i++); //$NON-NLS-1$ } } } source.append(')'); } else { - source.append(getDotName(method.returnTypeName())).append(' ').append(method.name()).append('('); - - List arguments= method.argumentTypeNames(); - int i= 0; + source.append(getDotName(method.returnTypeName())).append(' ') + .append(method.name()).append('('); + + List<String> arguments = method.argumentTypeNames(); + int i = 0; if (arguments.size() != 0) { - Iterator iterator= arguments.iterator(); - source.append(getDotName((String) iterator.next())).append(" arg").append(i++); //$NON-NLS-1$ + Iterator<String> iterator = arguments.iterator(); + source.append(getDotName(iterator.next())) + .append(" arg").append(i++); //$NON-NLS-1$ if (method.isVarArgs()) { while (iterator.hasNext()) { source.append(','); - String argName = getDotName((String) iterator.next()); + String argName = getDotName(iterator.next()); if (!iterator.hasNext()) { - source.append(argName.substring(0,argName.length() - 2)).append("..."); //$NON-NLS-1$ + source.append( + argName.substring(0, argName.length() - 2)) + .append("..."); //$NON-NLS-1$ } else { source.append(argName); } @@ -444,13 +498,15 @@ public class BinaryBasedSourceGenerator { } } else { while (iterator.hasNext()) { - source.append(',').append(getDotName((String) iterator.next())).append(" arg").append(i++); //$NON-NLS-1$ + source.append(',') + .append(getDotName(iterator.next())) + .append(" arg").append(i++); //$NON-NLS-1$ } } } source.append(')'); } - + if (method.isAbstract() || method.isNative()) { // No body for abstract and native methods source.append(";\n"); //$NON-NLS-1$ @@ -462,35 +518,35 @@ public class BinaryBasedSourceGenerator { return source; } - + private String getReturnStatement(String returnTypeName) { - String typeName= getSimpleName(returnTypeName); + String typeName = getSimpleName(returnTypeName); if (typeName.charAt(typeName.length() - 1) == ']') { return "return null;\n"; //$NON-NLS-1$ } switch (typeName.charAt(0)) { - case 'v': - return ""; //$NON-NLS-1$ - case 'b': - if (typeName.charAt(1) == 'o') { - return "return false;\n"; //$NON-NLS-1$ - } - case 's': - case 'c': - case 'i': - case 'l': - case 'd': - case 'f': - return "return 0;\n"; //$NON-NLS-1$ - default: - return "return null;\n"; //$NON-NLS-1$ + case 'v': + return ""; //$NON-NLS-1$ + case 'b': + if (typeName.charAt(1) == 'o') { + return "return false;\n"; //$NON-NLS-1$ + } + case 's': + case 'c': + case 'i': + case 'l': + case 'd': + case 'f': + return "return 0;\n"; //$NON-NLS-1$ + default: + return "return null;\n"; //$NON-NLS-1$ } } - + private String getDotName(String typeName) { return typeName.replace('$', '.'); } - + private boolean isAnonymousTypeName(String typeName) { char char0 = getSimpleName(typeName).charAt(0); return '0' <= char0 && char0 <= '9'; @@ -501,57 +557,59 @@ public class BinaryBasedSourceGenerator { if (pos == -1) { pos = qualifiedName.lastIndexOf('.'); } - return ((pos == -1)? qualifiedName : qualifiedName.substring(pos + 1)); + return ((pos == -1) ? qualifiedName : qualifiedName.substring(pos + 1)); } - + private String getPackageName(String qualifiedName) { int pos = qualifiedName.lastIndexOf('.'); - return ((pos == -1)? null : qualifiedName.substring(0, pos)); + return ((pos == -1) ? null : qualifiedName.substring(0, pos)); } - + private boolean isADirectInnerType(String typeName, String nestedTypeName) { - String end= nestedTypeName.substring(typeName.length() + 1); + String end = nestedTypeName.substring(typeName.length() + 1); return end.indexOf('$') == -1; } - + private boolean isInStaticMethod() { return fIsInStaticMethod; } - + public StringBuffer getSource() { return fSource; } - + public int getCodeSnippetPosition() { return fCodeSnippetPosition; } - + public String getCompilationUnitName() { return fCompilationUnitName; } - + public int getSnippetStart() { return fCodeSnippetPosition - 2; } - + public int getRunMethodStart() { return fCodeSnippetPosition - fRunMethodStartOffset; } - + public int getRunMethodLength() { return fRunMethodLength; } /** - * Returns whether the source to be generated is greater than or equal to the - * given source level. + * Returns whether the source to be generated is greater than or equal to + * the given source level. * - * @param major major level - e.g. 1 from 1.4 - * @param minor minor level - e.g. 4 from 1.4 + * @param major + * major level - e.g. 1 from 1.4 + * @param minor + * minor level - e.g. 4 from 1.4 * @return */ public boolean isSourceLevelGreaterOrEqual(int major, int minor) { - return (fSourceMajorLevel > major) || - (fSourceMajorLevel == major && fSourceMinorLevel >= minor); - } + return (fSourceMajorLevel > major) + || (fSourceMajorLevel == major && fSourceMinorLevel >= minor); + } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java index ccfba0fbd..3817e88ca 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationEngineMessages.java @@ -59,7 +59,7 @@ public class EvaluationEngineMessages extends NLS { NLS.initializeMessages(BUNDLE_NAME, EvaluationEngineMessages.class); } - public static String ASTEvaluationEngine_0; + public static String ASTEvaluationEngine_0; public static String ASTEvaluationEngine_1; public static String ArrayRuntimeContext_0; } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java index ff090164b..f21a3b91d 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/EvaluationSourceGenerator.java @@ -29,11 +29,10 @@ import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; import org.eclipse.jdt.internal.debug.core.model.JDIReferenceType; /** - * Creates the source code necessary to evaluate a code snippet. - * The (simplified) structure of the source is as follows: - * [package <package name>;] - * [import <import name>;]* - * public class <code snippet class name> extends <global variable class name> { + * Creates the source code necessary to evaluate a code snippet. The + * (simplified) structure of the source is as follows: [package <package name>;] + * [import <import name>;]* public class + * <code snippet class name> extends <global variable class name> { * public void run() { * <code snippet> * } @@ -42,26 +41,26 @@ import org.eclipse.jdt.internal.debug.core.model.JDIReferenceType; public class EvaluationSourceGenerator { private String fCodeSnippet; - + private String[] fLocalVariableTypeNames; private String[] fLocalVariableNames; - - + private String fSource; private String fCompilationUnitName; private int fSnippetStartPosition; private int fRunMethodStartPosition; private int fRunMethodLength; - + /** * Rebuild source in presence of external local variables */ - public EvaluationSourceGenerator(String[] localVariableTypesNames, String[] localVariableNames, String codeSnippet) { + public EvaluationSourceGenerator(String[] localVariableTypesNames, + String[] localVariableNames, String codeSnippet) { fLocalVariableTypeNames = localVariableTypesNames; fLocalVariableNames = localVariableNames; - fCodeSnippet= getCompleteSnippet(codeSnippet); + fCodeSnippet = getCompleteSnippet(codeSnippet); } - + public EvaluationSourceGenerator(String codeSnippet) { this(new String[0], new String[0], codeSnippet); } @@ -73,80 +72,91 @@ public class EvaluationSourceGenerator { } return codeSnippet; } - + /** - * Returns whether the given snippet represents an expression. - * This is determined by examining the snippet for non-quoted semicolons. + * Returns whether the given snippet represents an expression. This is + * determined by examining the snippet for non-quoted semicolons. * * Returns <code>true</code> if the snippet is an expression, or - * <code>false</code> if the expresssion contains a statement. + * <code>false</code> if the expression contains a statement. */ protected boolean isExpression(String codeSnippet) { - boolean inString= false; - byte[] chars= codeSnippet.getBytes(); - for (int i= 0, numChars= chars.length; i < numChars; i++) { + boolean inString = false; + byte[] chars = codeSnippet.getBytes(); + for (int i = 0, numChars = chars.length; i < numChars; i++) { switch (chars[i]) { - case '\\': - if (inString) { // skip the char after an escape char - i++; - } - break; - case '\"': - case '\'': - inString= !inString; - break; - case ';': - if (!inString) { - return false; - } - break; + case '\\': + if (inString) { // skip the char after an escape char + i++; + } + break; + case '\"': + case '\'': + inString = !inString; + break; + case ';': + if (!inString) { + return false; + } + break; } } return true; } - + public String getCompilationUnitName() { return fCompilationUnitName; } - + public int getSnippetStart() { return fSnippetStartPosition; } + public int getRunMethodStart() { return fRunMethodStartPosition; } + public int getRunMethodLength() { return fRunMethodLength; } + protected void setSnippetStart(int position) { - fSnippetStartPosition= position; + fSnippetStartPosition = position; } + protected void setRunMethodStart(int position) { - fRunMethodStartPosition= position; + fRunMethodStartPosition = position; } + protected void setRunMethodLength(int length) { - fRunMethodLength= length; + fRunMethodLength = length; } - + public String getSnippet() { return fCodeSnippet; } - private void createEvaluationSourceFromSource(String source, IType type, boolean createInAStaticMethod, IJavaProject project) throws DebugException { + private void createEvaluationSourceFromSource(String source, IType type, + boolean createInAStaticMethod, IJavaProject project) + throws DebugException { ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(source.toCharArray()); - Map options=getCompilerOptions(project); + Map<String, String> options = getCompilerOptions(project); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); parser.setCompilerOptions(options); - CompilationUnit unit= (CompilationUnit)parser.createAST(null); - SourceBasedSourceGenerator visitor= new SourceBasedSourceGenerator(type, createInAStaticMethod, fLocalVariableTypeNames, fLocalVariableNames, fCodeSnippet, sourceLevel); + CompilationUnit unit = (CompilationUnit) parser.createAST(null); + SourceBasedSourceGenerator visitor = new SourceBasedSourceGenerator( + type, createInAStaticMethod, fLocalVariableTypeNames, + fLocalVariableNames, fCodeSnippet, sourceLevel); unit.accept(visitor); - + if (visitor.hasError()) { - throw new DebugException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, visitor.getError(), null)); + throw new DebugException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + visitor.getError(), null)); } - - String sourceRes= visitor.getSource(); + + String sourceRes = visitor.getSource(); if (sourceRes == null) { return; } @@ -156,47 +166,59 @@ public class EvaluationSourceGenerator { setRunMethodStart(visitor.getRunMethodStart()); setRunMethodLength(visitor.getRunMethodLength()); } - + /** * Returns the compiler options used for compiling the expression. * <p> - * Turns all errors and warnings into ignore and disables task tags. The customizable set of - * compiler options only contains additional Eclipse options. The standard JDK compiler options - * can't be changed anyway. + * Turns all errors and warnings into ignore and disables task tags. The + * customizable set of compiler options only contains additional Eclipse + * options. The standard JDK compiler options can't be changed anyway. * - * @param element an element (not the Java model) + * @param element + * an element (not the Java model) * @return compiler options */ - public static Map getCompilerOptions(IJavaProject project) { - Map options= project.getOptions(true); - for (Iterator iter= options.keySet().iterator(); iter.hasNext();) { - String key= (String)iter.next(); - String value= (String)options.get(key); + public static Map<String, String> getCompilerOptions(IJavaProject project) { + Map<String, String> options = project.getOptions(true); + for (Iterator<String> iter = options.keySet().iterator(); iter.hasNext();) { + String key = iter.next(); + String value = options.get(key); if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value)) { options.put(key, JavaCore.IGNORE); } } options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$ return options; - } - - private void createEvaluationSourceFromJDIObject(BinaryBasedSourceGenerator objectToEvaluationSourceMapper) { - - setCompilationUnitName(objectToEvaluationSourceMapper.getCompilationUnitName()); + } + + private void createEvaluationSourceFromJDIObject( + BinaryBasedSourceGenerator objectToEvaluationSourceMapper) { + + setCompilationUnitName(objectToEvaluationSourceMapper + .getCompilationUnitName()); setSnippetStart(objectToEvaluationSourceMapper.getSnippetStart()); setRunMethodStart(objectToEvaluationSourceMapper.getRunMethodStart()); - setRunMethodLength(fCodeSnippet.length() + objectToEvaluationSourceMapper.getRunMethodLength()); - setSource(objectToEvaluationSourceMapper.getSource().insert(objectToEvaluationSourceMapper.getCodeSnippetPosition(), fCodeSnippet).toString()); + setRunMethodLength(fCodeSnippet.length() + + objectToEvaluationSourceMapper.getRunMethodLength()); + setSource(objectToEvaluationSourceMapper + .getSource() + .insert(objectToEvaluationSourceMapper.getCodeSnippetPosition(), + fCodeSnippet).toString()); } - - private BinaryBasedSourceGenerator getInstanceSourceMapper(JDIReferenceType referenceType, boolean isInStaticMethod, IJavaProject project) { + + private BinaryBasedSourceGenerator getInstanceSourceMapper( + JDIReferenceType referenceType, boolean isInStaticMethod, + IJavaProject project) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); - BinaryBasedSourceGenerator objectToEvaluationSourceMapper = new BinaryBasedSourceGenerator(fLocalVariableTypeNames, fLocalVariableNames, isInStaticMethod, sourceLevel); + BinaryBasedSourceGenerator objectToEvaluationSourceMapper = new BinaryBasedSourceGenerator( + fLocalVariableTypeNames, fLocalVariableNames, isInStaticMethod, + sourceLevel); objectToEvaluationSourceMapper.buildSource(referenceType); return objectToEvaluationSourceMapper; } - - public String getSource(IJavaReferenceType type, IJavaProject javaProject, boolean isStatic) throws CoreException { + + public String getSource(IJavaReferenceType type, IJavaProject javaProject, + boolean isStatic) throws CoreException { if (fSource == null) { IType iType = JavaDebugUtils.resolveType(type); if (iType != null && !iType.isInterface()) { @@ -207,11 +229,13 @@ public class EvaluationSourceGenerator { baseSource = iType.getCompilationUnit().getSource(); } if (baseSource != null) { - createEvaluationSourceFromSource(baseSource, iType, isStatic, javaProject); + createEvaluationSourceFromSource(baseSource, iType, + isStatic, javaProject); } } if (fSource == null) { - BinaryBasedSourceGenerator mapper= getInstanceSourceMapper((JDIReferenceType) type, isStatic, javaProject); + BinaryBasedSourceGenerator mapper = getInstanceSourceMapper( + (JDIReferenceType) type, isStatic, javaProject); createEvaluationSourceFromJDIObject(mapper); } } @@ -219,11 +243,11 @@ public class EvaluationSourceGenerator { } protected void setCompilationUnitName(String name) { - fCompilationUnitName= name; + fCompilationUnitName = name; } - + protected void setSource(String source) { - fSource= source; + fSource = source; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/IRuntimeContext.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/IRuntimeContext.java index 8c68f51eb..9c53f8ef4 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/IRuntimeContext.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/IRuntimeContext.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.debug.core.IJavaClassObject; @@ -19,107 +18,113 @@ import org.eclipse.jdt.debug.core.IJavaObject; import org.eclipse.jdt.debug.core.IJavaReferenceType; import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.core.IJavaVariable; - + /** - * The context in which an evaluation is to be performed. An - * evaluation is performed in the context of an object or class. - * The evaluation may be in the context of a method, in which case - * there could be local variables. + * The context in which an evaluation is to be performed. An evaluation is + * performed in the context of an object or class. The evaluation may be in the + * context of a method, in which case there could be local variables. * <p> * Clients are not intended to implement this interface. */ public interface IRuntimeContext { - + /** - * Returns the virtual machine in which to perform the - * evaluation. + * Returns the virtual machine in which to perform the evaluation. * * @return virtual machine */ IJavaDebugTarget getVM(); - + /** - * Returns the receiving object context in which to perform - * the evaluation - equivalent to 'this'. Returns <code>null</code> - * if the context of an evaluation is in a class rather than - * an object. + * Returns the receiving object context in which to perform the evaluation - + * equivalent to 'this'. Returns <code>null</code> if the context of an + * evaluation is in a class rather than an object. * * @return 'this', or <code>null</code> - * @exception EvaluationException if this method fails. Reasons include: - * <ul><li>Failure communicating with the VM. The exception's - * status code contains the underlying exception responsible for - * the failure.</li></ul> + * @exception EvaluationException + * if this method fails. Reasons include: + * <ul> + * <li>Failure communicating with the VM. The exception's + * status code contains the underlying exception responsible + * for the failure.</li> + * </ul> */ IJavaObject getThis() throws CoreException; - + /** - * Returns the receiving type context in which to perform - * the evaluation. The type of 'this', or in the case of a - * static context, the class or interface in which the evaluation is being - * performed. + * Returns the receiving type context in which to perform the evaluation. + * The type of 'this', or in the case of a static context, the class or + * interface in which the evaluation is being performed. * * @return receiving class - * @exception EvaluationException if this method fails. Reasons include: - * <ul><li>Failure communicating with the VM. The exception's - * status code contains the underlying exception responsible for - * the failure.</li></ul> + * @exception EvaluationException + * if this method fails. Reasons include: + * <ul> + * <li>Failure communicating with the VM. The exception's + * status code contains the underlying exception responsible + * for the failure.</li> + * </ul> */ IJavaReferenceType getReceivingType() throws CoreException; - + /** - * Returns the local variables visible for the evaluation. - * This includes method arguments, if any. Does not return - * <code>null</code> returns an empty collection if there - * are no locals. + * Returns the local variables visible for the evaluation. This includes + * method arguments, if any. Does not return <code>null</code> returns an + * empty collection if there are no locals. * * @return local variables - * @exception EvaluationException if this method fails. Reasons include: - * <ul><li>Failure communicating with the VM. The exception's - * status code contains the underlying exception responsible for - * the failure.</li></ul> + * @exception EvaluationException + * if this method fails. Reasons include: + * <ul> + * <li>Failure communicating with the VM. The exception's + * status code contains the underlying exception responsible + * for the failure.</li> + * </ul> */ IJavaVariable[] getLocals() throws CoreException; /** - * Returns the Java project context in which this expression - * should be compiled. + * Returns the Java project context in which this expression should be + * compiled. * * @return project */ IJavaProject getProject(); - + /** * Returns the thread in which message sends may be performed. * * @return thread */ IJavaThread getThread(); - + /** - * Returns whether the context of this evaluation is within - * a constructor. + * Returns whether the context of this evaluation is within a constructor. * - * @return whether the context of this evaluation is within - * a constructor - * @exception EvaluationException if this method fails. Reasons include: - * <ul><li>Failure communicating with the VM. The exception's - * status code contains the underlying exception responsible for - * the failure.</li></ul> + * @return whether the context of this evaluation is within a constructor + * @exception EvaluationException + * if this method fails. Reasons include: + * <ul> + * <li>Failure communicating with the VM. The exception's + * status code contains the underlying exception responsible + * for the failure.</li> + * </ul> */ public boolean isConstructor() throws CoreException; - /** - * Loads, prepares and returns the class with the given name in this runtime - * context's receiving type's class loader. If the class is already loaded, - * it is simply returned. - * - * @param name fully qualified class name - * @return class object - * @throws CoreException if unable to load the class - * @since 3.2 - */ - public IJavaClassObject classForName(String name) throws CoreException; - -} + /** + * Loads, prepares and returns the class with the given name in this runtime + * context's receiving type's class loader. If the class is already loaded, + * it is simply returned. + * + * @param name + * fully qualified class name + * @return class object + * @throws CoreException + * if unable to load the class + * @since 3.2 + */ + public IJavaClassObject classForName(String name) throws CoreException; +} diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/Interpreter.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/Interpreter.java index 19f9d1259..1d3dfa493 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/Interpreter.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/Interpreter.java @@ -36,79 +36,81 @@ public class Interpreter { private Instruction[] fInstructions; private int fInstructionCounter; private IRuntimeContext fContext; - private Stack fStack; + private Stack<Object> fStack; private IJavaValue fLastValue; - + /** * The list of internal variables */ - private Map fInternalVariables; - + private Map<String, IVariable> fInternalVariables; + /** * List of objects for which GC has been disabled */ - private List fPermStorage = null; - - private boolean fStopped= false; - + private List<IJavaObject> fPermStorage = null; + + private boolean fStopped = false; + public Interpreter(InstructionSequence instructions, IRuntimeContext context) { - fInstructions= instructions.getInstructions(); - fContext= context; - fInternalVariables= new HashMap(); + fInstructions = instructions.getInstructions(); + fContext = context; + fInternalVariables = new HashMap<String, IVariable>(); } - + public void execute() throws CoreException { try { reset(); - while(fInstructionCounter < fInstructions.length && !fStopped) { - Instruction instruction= fInstructions[fInstructionCounter++]; + while (fInstructionCounter < fInstructions.length && !fStopped) { + Instruction instruction = fInstructions[fInstructionCounter++]; instruction.setInterpreter(this); instruction.execute(); instruction.setInterpreter(null); } } catch (VMDisconnectedException e) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), e.getMessage(), e)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), e.getMessage(), e)); } finally { releaseObjects(); } } - + public void stop() { - fStopped= true; + fStopped = true; } private void reset() { - fStack= new Stack(); - fInstructionCounter= 0; + fStack = new Stack<Object>(); + fInstructionCounter = 0; } - + /** * Jumps to a given address */ public void jump(int offset) { - fInstructionCounter+= offset; - } - + fInstructionCounter += offset; + } + /** * Pushes an object onto the stack. Disables garbage collection for any - * interim object pushed onto the stack. Objects are released after the + * interim object pushed onto the stack. Objects are released after the * evaluation completes. */ public void push(Object object) { fStack.push(object); if (object instanceof IJavaObject) { - disableCollection((IJavaObject)object); + disableCollection((IJavaObject) object); } } - + /** * Avoid garbage collecting interim results. * - * @param value object to disable garbage collection for + * @param value + * object to disable garbage collection for */ private void disableCollection(IJavaObject value) { if (fPermStorage == null) { - fPermStorage = new ArrayList(5); + fPermStorage = new ArrayList<IJavaObject>(5); } try { value.disableCollection(); @@ -117,19 +119,19 @@ public class Interpreter { JDIDebugPlugin.log(e); } } - + /** * Re-enable garbage collection if interim results. */ private void releaseObjects() { if (fPermStorage != null) { - Iterator iterator = fPermStorage.iterator(); + Iterator<IJavaObject> iterator = fPermStorage.iterator(); while (iterator.hasNext()) { - IJavaObject object = (IJavaObject)iterator.next(); + IJavaObject object = iterator.next(); try { object.enableCollection(); } catch (CoreException e) { - // don't worry about GC if the VM has terminated + // don't worry about GC if the VM has terminated if ((e.getStatus().getException() instanceof VMDisconnectedException)) { break; } @@ -145,22 +147,22 @@ public class Interpreter { */ public Object peek() { return fStack.peek(); - } - + } + /** * Pops an object off of the stack */ public Object pop() { return fStack.pop(); } - + /** * Answers the context for the interpreter */ public IRuntimeContext getContext() { return fContext; } - + public IJavaValue getResult() { if (fStack == null || fStack.isEmpty()) { if (fLastValue == null) { @@ -168,48 +170,54 @@ public class Interpreter { } return fLastValue; } - Object top= fStack.peek(); + Object top = fStack.peek(); if (top instanceof IJavaVariable) { try { - return (IJavaValue)((IJavaVariable)top).getValue(); + return (IJavaValue) ((IJavaVariable) top).getValue(); } catch (CoreException exception) { - return getContext().getVM().newValue(exception.getStatus().getMessage()); + return getContext().getVM().newValue( + exception.getStatus().getMessage()); } } if (top instanceof IJavaValue) { - return (IJavaValue)top; + return (IJavaValue) top; } // XXX: exception - return null; + return null; } - + public void setLastValue(IJavaValue value) { - fLastValue= value; + fLastValue = value; } - + /** - * Create a new variable in the interpreter with the given name - * and the given type. + * Create a new variable in the interpreter with the given name and the + * given type. * - * @param name the name of the variable to create. - * @param type the type of the variable to create. + * @param name + * the name of the variable to create. + * @param type + * the type of the variable to create. * @return the created variable. */ public IVariable createInternalVariable(String name, IJavaType referencType) { - IVariable var= new InterpreterVariable(name, referencType, fContext.getVM()); + IVariable var = new InterpreterVariable(name, referencType, + fContext.getVM()); fInternalVariables.put(name, var); return var; } - + /** - * Return the variable with the given name. - * This method only looks in the list of internal variable (i.e. created by + * Return the variable with the given name. This method only looks in the + * list of internal variable (i.e. created by * Interpreter#createInternalVariable(String, IJavaType)) * - * @param name the name of the variable to retrieve. - * @return the corresponding variable, or <code>null</code> if there is none. - */ + * @param name + * the name of the variable to retrieve. + * @return the corresponding variable, or <code>null</code> if there is + * none. + */ public IVariable getInternalVariable(String name) { - return (IVariable)fInternalVariables.get(name); + return fInternalVariables.get(name); } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/InterpreterVariable.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/InterpreterVariable.java index 2ed99a81b..81d7e657b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/InterpreterVariable.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/InterpreterVariable.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugException; @@ -27,23 +26,24 @@ public class InterpreterVariable implements IJavaVariable { * The reference type of this variable. */ private IJavaType fReferenceType; - + /** * The variable name. */ private String fName; - + /** * The variable value. */ private IValue fValue; - + private IDebugTarget fDebugTarget; - public InterpreterVariable(String name, IJavaType referenceType, IDebugTarget debugTarget) { - fName= name; - fReferenceType= referenceType; - fDebugTarget= debugTarget; + public InterpreterVariable(String name, IJavaType referenceType, + IDebugTarget debugTarget) { + fName = name; + fReferenceType = referenceType; + fDebugTarget = debugTarget; } /** @@ -99,14 +99,20 @@ public class InterpreterVariable implements IJavaVariable { * @see org.eclipse.debug.core.model.IValueModification#setValue(String) */ public void setValue(String expression) throws DebugException { - throw new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.NOT_SUPPORTED, EvaluationEngineMessages.InterpreterVariable_setValue_String__not_supported_for_interpreter_variable_1, null)); + throw new DebugException( + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.NOT_SUPPORTED, + EvaluationEngineMessages.InterpreterVariable_setValue_String__not_supported_for_interpreter_variable_1, + null)); } /** * @see org.eclipse.debug.core.model.IValueModification#setValue(IValue) */ public void setValue(IValue value) { - fValue= value; + fValue = value; } /** @@ -120,14 +126,26 @@ public class InterpreterVariable implements IJavaVariable { * @see org.eclipse.debug.core.model.IValueModification#verifyValue(IValue) */ public boolean verifyValue(IValue value) throws DebugException { - throw new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.NOT_SUPPORTED, EvaluationEngineMessages.InterpreterVariable_verifyValue_IValue__not_supported_for_interpreter_variable_2, null)); + throw new DebugException( + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.NOT_SUPPORTED, + EvaluationEngineMessages.InterpreterVariable_verifyValue_IValue__not_supported_for_interpreter_variable_2, + null)); } /** * @see org.eclipse.debug.core.model.IValueModification#verifyValue(String) */ public boolean verifyValue(String expression) throws DebugException { - throw new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.NOT_SUPPORTED, EvaluationEngineMessages.InterpreterVariable_verifyValue_String__not_supported_for_interpreter_variable_3, null)); + throw new DebugException( + new Status( + IStatus.ERROR, + JDIDebugModel.getPluginIdentifier(), + DebugException.NOT_SUPPORTED, + EvaluationEngineMessages.InterpreterVariable_verifyValue_String__not_supported_for_interpreter_variable_3, + null)); } /** @@ -206,8 +224,10 @@ public class InterpreterVariable implements IJavaVariable { public boolean isLocal() { return false; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.jdt.debug.core.IJavaVariable#getGenericSignature() */ public String getGenericSignature() throws DebugException { diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/JavaObjectRuntimeContext.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/JavaObjectRuntimeContext.java index 93b331d2e..ea99441d3 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/JavaObjectRuntimeContext.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/JavaObjectRuntimeContext.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.debug.core.IJavaDebugTarget; @@ -20,35 +19,39 @@ import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.core.IJavaVariable; public class JavaObjectRuntimeContext extends AbstractRuntimeContext { - + /** * <code>this</code> object or this context. */ private IJavaObject fThisObject; - + /** * The thread for this context. */ private IJavaThread fThread; - + /** * ObjectValueRuntimeContext constructor. * - * @param thisObject <code>this</code> object of this context. - * @param javaProject the project for this context. - * @param thread the thread for this context. + * @param thisObject + * <code>this</code> object of this context. + * @param javaProject + * the project for this context. + * @param thread + * the thread for this context. */ - public JavaObjectRuntimeContext(IJavaObject thisObject, IJavaProject javaProject, IJavaThread thread) { + public JavaObjectRuntimeContext(IJavaObject thisObject, + IJavaProject javaProject, IJavaThread thread) { super(javaProject); - fThisObject= thisObject; - fThread= thread; + fThisObject = thisObject; + fThread = thread; } /** * @see IRuntimeContext#getVM() */ public IJavaDebugTarget getVM() { - return (IJavaDebugTarget)fThisObject.getDebugTarget(); + return (IJavaDebugTarget) fThisObject.getDebugTarget(); } /** @@ -62,7 +65,7 @@ public class JavaObjectRuntimeContext extends AbstractRuntimeContext { * @see IRuntimeContext#getReceivingType() */ public IJavaReferenceType getReceivingType() throws CoreException { - return (IJavaReferenceType)getThis().getJavaType(); + return (IJavaReferenceType) getThis().getJavaType(); } /** diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/RuntimeContext.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/RuntimeContext.java index b9e654db4..8e08d693b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/RuntimeContext.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/RuntimeContext.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.debug.core.IJavaDebugTarget; @@ -28,24 +27,24 @@ public class RuntimeContext extends AbstractRuntimeContext { private IJavaStackFrame fFrame; /** - * Creates a runtime context for the given java project and - * stack frame. + * Creates a runtime context for the given java project and stack frame. * - * @param project Java project context used to compile expressions in - * @param frame stack frame used to define locals and receiving type - * context + * @param project + * Java project context used to compile expressions in + * @param frame + * stack frame used to define locals and receiving type context * @return a new runtime context */ public RuntimeContext(IJavaProject project, IJavaStackFrame frame) { super(project); setFrame(frame); } - + /** * @see IRuntimeContext#getVM() */ public IJavaDebugTarget getVM() { - return (IJavaDebugTarget)getFrame().getDebugTarget(); + return (IJavaDebugTarget) getFrame().getDebugTarget(); } /** @@ -61,7 +60,7 @@ public class RuntimeContext extends AbstractRuntimeContext { public IJavaReferenceType getReceivingType() throws CoreException { IJavaObject rec = getThis(); if (rec != null) { - return (IJavaReferenceType)rec.getJavaType(); + return (IJavaReferenceType) rec.getJavaType(); } return getFrame().getReferenceType(); } @@ -72,30 +71,32 @@ public class RuntimeContext extends AbstractRuntimeContext { public IJavaVariable[] getLocals() throws CoreException { return getFrame().getLocalVariables(); } - + /** * Sets the stack frame context used to compile/run expressions * - * @param frame the stack frame context used to compile/run expressions + * @param frame + * the stack frame context used to compile/run expressions */ protected IJavaStackFrame getFrame() { return fFrame; - } - + } + /** * Sets the stack frame context used to compile/run expressions * - * @param frame the stack frame context used to compile/run expressions + * @param frame + * the stack frame context used to compile/run expressions */ private void setFrame(IJavaStackFrame frame) { fFrame = frame; - } + } /** * @see IRuntimeContext#getThread() */ public IJavaThread getThread() { - return (IJavaThread)getFrame().getThread(); + return (IJavaThread) getFrame().getThread(); } /** @@ -106,4 +107,3 @@ public class RuntimeContext extends AbstractRuntimeContext { } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java index 2d43b53a8..3cdf2c866 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,16 +18,21 @@ import org.eclipse.jdt.internal.core.util.Util; public class SignatureExt { - public static char[][] getTypeSuperClassInterfaces(char[] typeSignature) throws IllegalArgumentException { + public static char[][] getTypeSuperClassInterfaces(char[] typeSignature) + throws IllegalArgumentException { try { int length = typeSignature.length; - if (length == 0) return CharOperation.NO_CHAR_CHAR; + if (length == 0) + return CharOperation.NO_CHAR_CHAR; int i = 0; if (typeSignature[0] == Signature.C_GENERIC_START) { i++; // leading '<' - while (i < length && typeSignature[i] != Signature.C_GENERIC_END) { - i = CharOperation.indexOf(Signature.C_COLON, typeSignature, i); - if (i < 0 || i >= length) throw new IllegalArgumentException(); + while (i < length + && typeSignature[i] != Signature.C_GENERIC_END) { + i = CharOperation.indexOf(Signature.C_COLON, typeSignature, + i); + if (i < 0 || i >= length) + throw new IllegalArgumentException(); // iterate over bounds nextBound: while (typeSignature[i] == ':') { i++; // skip colon @@ -38,15 +43,17 @@ public class SignatureExt { i++; // position at start of next param if any } } - if (i < 0 || i >= length) throw new IllegalArgumentException(); + if (i < 0 || i >= length) + throw new IllegalArgumentException(); i++; // trailing '>' } - ArrayList superList= new ArrayList(); + ArrayList<char[]> superList = new ArrayList<char[]>(); while (i < length) { - int superStart= i; - i= Util.scanTypeSignature(typeSignature, i); + int superStart = i; + i = Util.scanTypeSignature(typeSignature, i); i++; - superList.add(CharOperation.subarray(typeSignature, superStart, i)); + superList.add(CharOperation.subarray(typeSignature, superStart, + i)); } char[][] result; superList.toArray(result = new char[superList.size()][]); @@ -57,8 +64,10 @@ public class SignatureExt { throw new IllegalArgumentException(); } - public static String[] getTypeSuperClassInterfaces(String typeSignature) throws IllegalArgumentException { - char[][] params = getTypeSuperClassInterfaces(typeSignature.toCharArray()); + public static String[] getTypeSuperClassInterfaces(String typeSignature) + throws IllegalArgumentException { + char[][] params = getTypeSuperClassInterfaces(typeSignature + .toCharArray()); return CharOperation.toStrings(params); } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SourceBasedSourceGenerator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SourceBasedSourceGenerator.java index 9a86812c5..dbbd7d950 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SourceBasedSourceGenerator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SourceBasedSourceGenerator.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.engine; - import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -113,74 +112,83 @@ import org.eclipse.jdt.core.dom.WhileStatement; import org.eclipse.jdt.core.dom.WildcardType; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; +public class SourceBasedSourceGenerator extends ASTVisitor { -public class SourceBasedSourceGenerator extends ASTVisitor { - - private static final String RUN_METHOD_NAME= "___run"; //$NON-NLS-1$ - private static final String EVAL_METHOD_NAME= "___eval"; //$NON-NLS-1$ - private static final String EVAL_FIELD_NAME= "___field"; //$NON-NLS-1$ + private static final String RUN_METHOD_NAME = "___run"; //$NON-NLS-1$ + private static final String EVAL_METHOD_NAME = "___eval"; //$NON-NLS-1$ + private static final String EVAL_FIELD_NAME = "___field"; //$NON-NLS-1$ private String[] fLocalVariableTypeNames; private String[] fLocalVariableNames; private String fCodeSnippet; - + private boolean fRightTypeFound; - + private boolean fCreateInAStaticMethod; - + private boolean fEvaluateNextEndTypeDeclaration; - + private String fError; - + private IType fType; - + private StringBuffer fSource; - + private String fLastTypeName; - + private String fCompilationUnitName; - + private int fSnippetStartPosition; private int fRunMethodStartOffset; private int fRunMethodLength; - + /** - * Level of source code to generate (major, minor). For example 1 and 4 + * Level of source code to generate (major, minor). For example 1 and 4 * indicates 1.4. */ private int fSourceMajorLevel; private int fSourceMinorLevel; - - private Set fTypeParameters = new HashSet(); - + + private Set<String> fTypeParameters = new HashSet<String>(); + /** - * if the <code>createInAnInstanceMethod</code> flag is set, the method created - * which contains the code snippet is an no-static method, even if <code>position</code> - * is in a static method. + * if the <code>createInAnInstanceMethod</code> flag is set, the method + * created which contains the code snippet is an no-static method, even if + * <code>position</code> is in a static method. * - * @param type the root {@link IType} - * @param createInAStaticMethod if the source should be generated - * @param localTypesNames the array of local type names - * @param localVariables the listing of local variable names - * @param codeSnippet the code snippet - * @param sourceLevel the desired source level - */ - public SourceBasedSourceGenerator(IType type, boolean createInAStaticMethod, String[] localTypesNames, String[] localVariables, String codeSnippet, String sourceLevel) { - fRightTypeFound= false; - fType= type; - fLocalVariableTypeNames= localTypesNames; - fLocalVariableNames= localVariables; - fCodeSnippet= codeSnippet; - fCreateInAStaticMethod= createInAStaticMethod; + * @param type + * the root {@link IType} + * @param createInAStaticMethod + * if the source should be generated + * @param localTypesNames + * the array of local type names + * @param localVariables + * the listing of local variable names + * @param codeSnippet + * the code snippet + * @param sourceLevel + * the desired source level + */ + public SourceBasedSourceGenerator(IType type, + boolean createInAStaticMethod, String[] localTypesNames, + String[] localVariables, String codeSnippet, String sourceLevel) { + fRightTypeFound = false; + fType = type; + fLocalVariableTypeNames = localTypesNames; + fLocalVariableNames = localVariables; + fCodeSnippet = codeSnippet; + fCreateInAStaticMethod = createInAStaticMethod; int index = sourceLevel.indexOf('.'); String num = sourceLevel.substring(0, index); fSourceMajorLevel = Integer.valueOf(num).intValue(); num = sourceLevel.substring(index + 1); fSourceMinorLevel = Integer.valueOf(num).intValue(); } - + /** - * Returns the generated source or <code>null</code> if no source can be generated. + * Returns the generated source or <code>null</code> if no source can be + * generated. + * * @return returns the backing source from the generator */ public String getSource() { @@ -189,55 +197,57 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } return fSource.toString(); } - + public String getCompilationUnitName() { return fCompilationUnitName; } - + public int getSnippetStart() { return fSnippetStartPosition; } + public int getRunMethodStart() { return fSnippetStartPosition - fRunMethodStartOffset; } + public int getRunMethodLength() { return fRunMethodLength; } - + private boolean rightTypeFound() { - return fRightTypeFound; + return fRightTypeFound; } - + private void setRightTypeFound(boolean value) { - fRightTypeFound= value; + fRightTypeFound = value; } - + public boolean hasError() { return fError != null; } - + public void setError(String errorDesc) { - fError= errorDesc; + fError = errorDesc; } - + public String getError() { return fError; } - - private StringBuffer buildRunMethod(List bodyDeclarations) { + + private StringBuffer buildRunMethod(List<BodyDeclaration> bodyDeclarations) { StringBuffer buffer = new StringBuffer(); if (fCreateInAStaticMethod) { buffer.append("static "); //$NON-NLS-1$ } - + // add type parameters as required if (isSourceLevelGreaterOrEqual(1, 5)) { if (!fTypeParameters.isEmpty()) { - Iterator iterator = fTypeParameters.iterator(); + Iterator<String> iterator = fTypeParameters.iterator(); buffer.append(Signature.C_GENERIC_START); while (iterator.hasNext()) { - String name = (String) iterator.next(); + String name = iterator.next(); buffer.append(name); if (iterator.hasNext()) { buffer.append(", "); //$NON-NLS-1$ @@ -245,12 +255,12 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } buffer.append(Signature.C_GENERIC_END); } - } - + } + buffer.append("void "); //$NON-NLS-1$ buffer.append(getUniqueMethodName(RUN_METHOD_NAME, bodyDeclarations)); buffer.append('('); - for(int i= 0, length= fLocalVariableNames.length; i < length; i++) { + for (int i = 0, length = fLocalVariableNames.length; i < length; i++) { buffer.append(getDotName(fLocalVariableTypeNames[i])); buffer.append(' '); buffer.append(fLocalVariableNames[i]); @@ -259,31 +269,34 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } buffer.append(") throws Throwable {"); //$NON-NLS-1$ buffer.append('\n'); - fSnippetStartPosition= buffer.length() - 2; - fRunMethodStartOffset= fSnippetStartPosition; - String codeSnippet= new String(fCodeSnippet).trim(); - + fSnippetStartPosition = buffer.length() - 2; + fRunMethodStartOffset = fSnippetStartPosition; + String codeSnippet = new String(fCodeSnippet).trim(); + buffer.append(codeSnippet); buffer.append('\n'); buffer.append('}').append('\n'); - fRunMethodLength= buffer.length(); + fRunMethodLength = buffer.length(); return buffer; } - + private String getDotName(String typeName) { return typeName.replace('$', '.'); } /** - * Returns if the specified {@link ASTNode} has the 'correct' parent type to match the current - * type name context - * @param node the {@link ASTNode} to check source ranges for - * @return true if the parent type of the given node matches the current type name context, - * false otherwise + * Returns if the specified {@link ASTNode} has the 'correct' parent type to + * match the current type name context + * + * @param node + * the {@link ASTNode} to check source ranges for + * @return true if the parent type of the given node matches the current + * type name context, false otherwise */ private boolean isRightType(ASTNode node) { - SourceRange range = new SourceRange(node.getStartPosition(), node.getLength()); + SourceRange range = new SourceRange(node.getStartPosition(), + node.getLength()); try { return fType.getSourceRange().equals(range); } catch (JavaModelException e) { @@ -291,31 +304,34 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } return false; } - - private StringBuffer buildTypeBody(StringBuffer buffer, List list) { + + private StringBuffer buildTypeBody(StringBuffer buffer, List<BodyDeclaration> list) { StringBuffer source = new StringBuffer(); - + source.append('{').append('\n'); - + if (buffer != null) { - fSnippetStartPosition+= source.length(); + fSnippetStartPosition += source.length(); } - + source.append(buildBody(buffer, list)); source.append('}').append('\n'); - + return source; } - - private StringBuffer buildEnumBody(StringBuffer buffer, List constantDeclarations, List bodyDeclarations) { + + private StringBuffer buildEnumBody(StringBuffer buffer, + List<EnumConstantDeclaration> constantDeclarations, List<BodyDeclaration> bodyDeclarations) { StringBuffer source = new StringBuffer(); - + source.append('{').append('\n'); if (constantDeclarations.isEmpty()) { source.append(';').append('\n'); } else { - for (Iterator iter= constantDeclarations.iterator(); iter.hasNext();) { - source.append(((EnumConstantDeclaration) iter.next()).getName().getIdentifier()); + for (Iterator<EnumConstantDeclaration> iter = constantDeclarations.iterator(); iter + .hasNext();) { + source.append(iter.next().getName() + .getIdentifier()); if (iter.hasNext()) { source.append(','); } else { @@ -324,120 +340,135 @@ public class SourceBasedSourceGenerator extends ASTVisitor { source.append('\n'); } } - + if (buffer != null) { - fSnippetStartPosition+= source.length(); + fSnippetStartPosition += source.length(); } - + source.append(buildBody(buffer, bodyDeclarations)); source.append('}').append('\n'); - + return source; - + } /** - * Builds up the given buffer with the source from each of {@link BodyDeclaration}s in the - * given list - * @param buffer the buffer to clone and append to - * @param list the list of {@link BodyDeclaration}s - * @return the new source buffer + * Builds up the given buffer with the source from each of + * {@link BodyDeclaration}s in the given list + * + * @param buffer + * the buffer to clone and append to + * @param list + * the list of {@link BodyDeclaration}s + * @return the new source buffer */ - private StringBuffer buildBody(StringBuffer buffer, List list) { - StringBuffer source= new StringBuffer(); + private StringBuffer buildBody(StringBuffer buffer, List<BodyDeclaration> list) { + StringBuffer source = new StringBuffer(); if (buffer != null) { fSnippetStartPosition += source.length(); source.append(buffer.toString()); } - for (Iterator iterator= list.iterator(); iterator.hasNext();) { - BodyDeclaration bodyDeclaration= (BodyDeclaration) iterator.next(); + for (Iterator<BodyDeclaration> iterator = list.iterator(); iterator.hasNext();) { + BodyDeclaration bodyDeclaration = iterator.next(); if (bodyDeclaration instanceof FieldDeclaration) { source.append(buildFieldDeclaration((FieldDeclaration) bodyDeclaration)); } else if (bodyDeclaration instanceof MethodDeclaration) { source.append(buildMethodDeclaration((MethodDeclaration) bodyDeclaration)); } else if (bodyDeclaration instanceof TypeDeclaration) { TypeDeclaration typeDeclaration = (TypeDeclaration) bodyDeclaration; - if (!typeDeclaration.getName().getIdentifier().equals(fLastTypeName)) { + if (!typeDeclaration.getName().getIdentifier() + .equals(fLastTypeName)) { source.append(buildTypeDeclaration(null, typeDeclaration)); } } else if (bodyDeclaration instanceof EnumDeclaration) { - EnumDeclaration enumDeclaration= (EnumDeclaration) bodyDeclaration; - if (!enumDeclaration.getName().getIdentifier().equals(fLastTypeName)) { + EnumDeclaration enumDeclaration = (EnumDeclaration) bodyDeclaration; + if (!enumDeclaration.getName().getIdentifier() + .equals(fLastTypeName)) { source.append(buildEnumDeclaration(null, enumDeclaration)); } } } return source; } - + private StringBuffer buildFieldDeclaration(FieldDeclaration fieldDeclaration) { StringBuffer source = new StringBuffer(); - + source.append(Flags.toString(fieldDeclaration.getModifiers())); source.append(' '); source.append(getDotName(getTypeName(fieldDeclaration.getType()))); source.append(' '); - - boolean first= true; - for (Iterator iterator= fieldDeclaration.fragments().iterator(); iterator.hasNext();) { - VariableDeclarationFragment variableDeclarationFragment= (VariableDeclarationFragment) iterator.next(); + + boolean first = true; + for (Iterator<VariableDeclarationFragment> iterator = fieldDeclaration.fragments().iterator(); iterator + .hasNext();) { + VariableDeclarationFragment variableDeclarationFragment = iterator + .next(); if (first) { first = false; } else { source.append(','); } source.append(variableDeclarationFragment.getName().getIdentifier()); - for (int i= 0, dim= variableDeclarationFragment.getExtraDimensions(); i < dim; i++) { + for (int i = 0, dim = variableDeclarationFragment + .getExtraDimensions(); i < dim; i++) { source.append('[').append(']'); } } - + source.append(';').append('\n'); - + return source; } - - private StringBuffer buildMethodDeclaration(MethodDeclaration methodDeclaration) { + + private StringBuffer buildMethodDeclaration( + MethodDeclaration methodDeclaration) { StringBuffer source = new StringBuffer(); - int modifiers= methodDeclaration.getModifiers(); + int modifiers = methodDeclaration.getModifiers(); source.append(Flags.toString(modifiers)); source.append(' '); - + appendTypeParameters(source, methodDeclaration.typeParameters()); - - boolean isConstructor= methodDeclaration.isConstructor(); + + boolean isConstructor = methodDeclaration.isConstructor(); if (!isConstructor) { - source.append(getDotName(getTypeName(methodDeclaration.getReturnType2()))); + source.append(getDotName(getTypeName(methodDeclaration + .getReturnType2()))); source.append(' '); } - + source.append(methodDeclaration.getName().getIdentifier()); source.append(' ').append('('); - - boolean first= true; - for (Iterator iterator = methodDeclaration.parameters().iterator(); iterator.hasNext();) { - SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) iterator.next(); + + boolean first = true; + for (Iterator<SingleVariableDeclaration> iterator = methodDeclaration.parameters().iterator(); iterator + .hasNext();) { + SingleVariableDeclaration singleVariableDeclaration = iterator + .next(); if (first) { first = false; } else { source.append(','); } - source.append(getDotName(getTypeName(singleVariableDeclaration.getType()))); + source.append(getDotName(getTypeName(singleVariableDeclaration + .getType()))); if (singleVariableDeclaration.isVarargs()) { source.append("..."); //$NON-NLS-1$ } source.append(' '); source.append(singleVariableDeclaration.getName().getIdentifier()); - appendExtraDimensions(source, singleVariableDeclaration.getExtraDimensions()); + appendExtraDimensions(source, + singleVariableDeclaration.getExtraDimensions()); } - + source.append(')'); - + appendExtraDimensions(source, methodDeclaration.getExtraDimensions()); - + first = true; - for (Iterator iterator = methodDeclaration.thrownExceptions().iterator(); iterator.hasNext();) { - Name name = (Name) iterator.next(); + for (Iterator<Name> iterator = methodDeclaration.thrownExceptions() + .iterator(); iterator.hasNext();) { + Name name = iterator.next(); if (first) { first = false; source.append(" throws "); //$NON-NLS-1$ @@ -446,58 +477,61 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } source.append(getQualifiedIdentifier(name)); } - + if (Flags.isAbstract(modifiers) || Flags.isNative(modifiers)) { // No body for abstract and native methods source.append(";\n"); //$NON-NLS-1$ } else { source.append('{').append('\n'); if (!isConstructor) { - source.append(getReturnExpression(methodDeclaration.getReturnType2())); + source.append(getReturnExpression(methodDeclaration + .getReturnType2())); } source.append('}').append('\n'); } - + return source; } private void appendExtraDimensions(StringBuffer source, int extraDimension) { if (extraDimension > 0) { source.append(' '); - for (int i= 0; i < extraDimension; i ++) { + for (int i = 0; i < extraDimension; i++) { source.append("[]"); //$NON-NLS-1$ } } } - private StringBuffer buildEnumDeclaration(StringBuffer buffer, EnumDeclaration enumDeclaration) { + private StringBuffer buildEnumDeclaration(StringBuffer buffer, + EnumDeclaration enumDeclaration) { StringBuffer source = new StringBuffer(); source.append(Flags.toString(enumDeclaration.getModifiers())); source.append(" enum "); //$NON-NLS-1$ - + source.append(enumDeclaration.getName().getIdentifier()); - - Iterator iterator= enumDeclaration.superInterfaceTypes().iterator(); + + Iterator<Type> iterator = enumDeclaration.superInterfaceTypes().iterator(); if (iterator.hasNext()) { source.append(" implements "); //$NON-NLS-1$ - source.append(getTypeName((Type) iterator.next())); + source.append(getTypeName(iterator.next())); while (iterator.hasNext()) { source.append(','); - source.append(getTypeName((Type) iterator.next())); + source.append(getTypeName(iterator.next())); } } if (buffer != null) { - fSnippetStartPosition+= source.length(); + fSnippetStartPosition += source.length(); } - source.append(buildEnumBody(buffer, enumDeclaration.enumConstants(), enumDeclaration.bodyDeclarations())); - + source.append(buildEnumBody(buffer, enumDeclaration.enumConstants(), + enumDeclaration.bodyDeclarations())); + return source; } - - private StringBuffer buildTypeDeclaration(StringBuffer buffer, TypeDeclaration typeDeclaration) { - + private StringBuffer buildTypeDeclaration(StringBuffer buffer, + TypeDeclaration typeDeclaration) { + StringBuffer source = new StringBuffer(); source.append(Flags.toString(typeDeclaration.getModifiers())); if (typeDeclaration.isInterface()) { @@ -505,37 +539,37 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } else { source.append(" class "); //$NON-NLS-1$ } - + source.append(typeDeclaration.getName().getIdentifier()); - List typeParameters= typeDeclaration.typeParameters(); + List<TypeParameter> typeParameters = typeDeclaration.typeParameters(); if (!typeParameters.isEmpty() && isSourceLevelGreaterOrEqual(1, 5)) { source.append('<'); - Iterator iter= typeParameters.iterator(); - TypeParameter typeParameter= (TypeParameter) iter.next(); + Iterator<TypeParameter> iter = typeParameters.iterator(); + TypeParameter typeParameter = iter.next(); source.append(typeParameter.getName().getIdentifier()); - List typeBounds= typeParameter.typeBounds(); + List<Type> typeBounds = typeParameter.typeBounds(); if (!typeBounds.isEmpty()) { source.append(" extends "); //$NON-NLS-1$ - Iterator iter2= typeBounds.iterator(); - source.append(getTypeName((Type) iter2.next())); + Iterator<Type> iter2 = typeBounds.iterator(); + source.append(getTypeName(iter2.next())); while (iter2.hasNext()) { source.append('&'); - source.append(getTypeName((Type) iter2.next())); + source.append(getTypeName(iter2.next())); } } while (iter.hasNext()) { source.append(','); - typeParameter= (TypeParameter) iter.next(); + typeParameter = iter.next(); source.append(typeParameter.getName().getIdentifier()); - typeBounds= typeParameter.typeBounds(); + typeBounds = typeParameter.typeBounds(); if (!typeBounds.isEmpty()) { source.append(" extends "); //$NON-NLS-1$ - Iterator iter2= typeBounds.iterator(); - source.append(getTypeName((Type) iter2.next())); + Iterator<Type> iter2 = typeBounds.iterator(); + source.append(getTypeName(iter2.next())); while (iter2.hasNext()) { source.append('&'); - source.append(getTypeName((Type) iter2.next())); + source.append(getTypeName(iter2.next())); } } } @@ -548,150 +582,165 @@ public class SourceBasedSourceGenerator extends ASTVisitor { source.append(getTypeName(superClass)); } - Iterator iter= typeDeclaration.superInterfaceTypes().iterator(); + Iterator<Type> iter = typeDeclaration.superInterfaceTypes().iterator(); if (iter.hasNext()) { if (typeDeclaration.isInterface()) { source.append(" extends "); //$NON-NLS-1$ } else { source.append(" implements "); //$NON-NLS-1$ } - source.append(getTypeName((Type) iter.next())); + source.append(getTypeName(iter.next())); while (iter.hasNext()) { source.append(','); - source.append(getTypeName((Type) iter.next())); + source.append(getTypeName(iter.next())); } } - + if (buffer != null) { - fSnippetStartPosition+= source.length(); + fSnippetStartPosition += source.length(); } source.append(buildTypeBody(buffer, typeDeclaration.bodyDeclarations())); - + return source; } - private StringBuffer buildCompilationUnit(StringBuffer buffer, CompilationUnit compilationUnit) { + private StringBuffer buildCompilationUnit(StringBuffer buffer, + CompilationUnit compilationUnit) { StringBuffer source = new StringBuffer(); - + PackageDeclaration packageDeclaration = compilationUnit.getPackage(); if (packageDeclaration != null) { source.append("package "); //$NON-NLS-1$ source.append(getQualifiedIdentifier(packageDeclaration.getName())); source.append(";\n"); //$NON-NLS-1$ } - - for (Iterator iterator = compilationUnit.imports().iterator(); iterator.hasNext();) { - ImportDeclaration importDeclaration = (ImportDeclaration) iterator.next(); + + for (Iterator<ImportDeclaration> iterator = compilationUnit.imports().iterator(); iterator + .hasNext();) { + ImportDeclaration importDeclaration = iterator + .next(); source.append("import "); //$NON-NLS-1$ - if (importDeclaration.isStatic()) { - source.append("static "); //$NON-NLS-1$ - } + if (importDeclaration.isStatic()) { + source.append("static "); //$NON-NLS-1$ + } source.append(getQualifiedIdentifier(importDeclaration.getName())); if (importDeclaration.isOnDemand()) { source.append(".*"); //$NON-NLS-1$ } source.append(";\n"); //$NON-NLS-1$ } - + fSnippetStartPosition += source.length(); source.append(buffer); - - for (Iterator iterator = compilationUnit.types().iterator(); iterator.hasNext();) { - AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) iterator.next(); + + for (Iterator<TypeDeclaration> iterator = compilationUnit.types().iterator(); iterator + .hasNext();) { + AbstractTypeDeclaration typeDeclaration = iterator.next(); if (Flags.isPublic(typeDeclaration.getModifiers())) { - fCompilationUnitName = typeDeclaration.getName().getIdentifier(); + fCompilationUnitName = typeDeclaration.getName() + .getIdentifier(); } - if (!fLastTypeName.equals(typeDeclaration.getName().getIdentifier())) { + if (!fLastTypeName + .equals(typeDeclaration.getName().getIdentifier())) { if (typeDeclaration instanceof TypeDeclaration) { - source.append(buildTypeDeclaration(null, (TypeDeclaration)typeDeclaration)); + source.append(buildTypeDeclaration(null, + (TypeDeclaration) typeDeclaration)); } else if (typeDeclaration instanceof EnumDeclaration) { - source.append(buildEnumDeclaration(null, (EnumDeclaration)typeDeclaration)); + source.append(buildEnumDeclaration(null, + (EnumDeclaration) typeDeclaration)); } } } - if (fCompilationUnitName == null) { + if (fCompilationUnitName == null) { // If no public class was found, the compilation unit // name doesn't matter. - fCompilationUnitName= "Eval"; //$NON-NLS-1$ + fCompilationUnitName = "Eval"; //$NON-NLS-1$ } return source; } - + /** - * Returns a method name that will be unique in the generated source. - * The generated name is baseName plus as many '_' characters as necessary - * to not duplicate an existing method name. + * Returns a method name that will be unique in the generated source. The + * generated name is baseName plus as many '_' characters as necessary to + * not duplicate an existing method name. * - * @param methodName the method name to look for - * @param bodyDeclarations the listing of {@link BodyDeclaration}s to search through + * @param methodName + * the method name to look for + * @param bodyDeclarations + * the listing of {@link BodyDeclaration}s to search through * @return the unique method name */ - private String getUniqueMethodName(String methodName, List bodyDeclarations) { - Iterator iter= bodyDeclarations.iterator(); + private String getUniqueMethodName(String methodName, List<BodyDeclaration> bodyDeclarations) { + Iterator<BodyDeclaration> iter = bodyDeclarations.iterator(); BodyDeclaration bodyDeclaration; MethodDeclaration method; String foundName; while (iter.hasNext()) { - bodyDeclaration= (BodyDeclaration) iter.next(); + bodyDeclaration = iter.next(); if (bodyDeclaration instanceof MethodDeclaration) { - method= (MethodDeclaration)bodyDeclaration; - foundName= method.getName().getIdentifier(); + method = (MethodDeclaration) bodyDeclaration; + foundName = method.getName().getIdentifier(); if (foundName.startsWith(methodName)) { - methodName= foundName + '_'; + methodName = foundName + '_'; } } } return methodName; } - + /** - * Returns a field name that will be unique in the generated source. - * The generated name is baseName plus as many '_' characters as necessary - * to not duplicate an existing method name. + * Returns a field name that will be unique in the generated source. The + * generated name is baseName plus as many '_' characters as necessary to + * not duplicate an existing method name. * - * @param fieldName the name of the field to look for - * @param bodyDeclarations the list of {@link BodyDeclaration}s to search through + * @param fieldName + * the name of the field to look for + * @param bodyDeclarations + * the list of {@link BodyDeclaration}s to search through * @return the unique field name */ - private String getUniqueFieldName(String fieldName, List bodyDeclarations) { - Iterator iter= bodyDeclarations.iterator(); + private String getUniqueFieldName(String fieldName, List<BodyDeclaration> bodyDeclarations) { + Iterator<BodyDeclaration> iter = bodyDeclarations.iterator(); BodyDeclaration bodyDeclaration; FieldDeclaration fieldDeclaration; String foundName; while (iter.hasNext()) { - bodyDeclaration= (BodyDeclaration) iter.next(); + bodyDeclaration = iter.next(); if (bodyDeclaration instanceof FieldDeclaration) { - fieldDeclaration= (FieldDeclaration)bodyDeclaration; - for (Iterator iterator= fieldDeclaration.fragments().iterator(); iterator.hasNext();) { - foundName= ((VariableDeclarationFragment) iterator.next()).getName().getIdentifier(); + fieldDeclaration = (FieldDeclaration) bodyDeclaration; + for (Iterator<VariableDeclarationFragment> iterator = fieldDeclaration.fragments() + .iterator(); iterator.hasNext();) { + foundName = iterator.next() + .getName().getIdentifier(); if (foundName.startsWith(fieldName)) { - fieldName= foundName + '_'; + fieldName = foundName + '_'; } } } } return fieldName; } - + private String getQualifiedIdentifier(Name name) { - String typeName= ""; //$NON-NLS-1$ + String typeName = ""; //$NON-NLS-1$ while (name.isQualifiedName()) { QualifiedName qualifiedName = (QualifiedName) name; - typeName= "." + qualifiedName.getName().getIdentifier() + typeName; //$NON-NLS-1$ - name= qualifiedName.getQualifier(); + typeName = "." + qualifiedName.getName().getIdentifier() + typeName; //$NON-NLS-1$ + name = qualifiedName.getQualifier(); } if (name.isSimpleName()) { - typeName= ((SimpleName)name).getIdentifier() + typeName; + typeName = ((SimpleName) name).getIdentifier() + typeName; } else { return null; } return typeName; } - + public String getTypeName(Type type) { if (type.isSimpleType()) { String name = getQualifiedIdentifier(((SimpleType) type).getName()); - if (!isSourceLevelGreaterOrEqual(1, 5) && fTypeParameters.contains(name)) { + if (!isSourceLevelGreaterOrEqual(1, 5) + && fTypeParameters.contains(name)) { return "Object"; //$NON-NLS-1$ } return name; @@ -700,26 +749,28 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } else if (type.isPrimitiveType()) { return ((PrimitiveType) type).getPrimitiveTypeCode().toString(); } else if (type.isQualifiedType()) { - QualifiedType qualifiedType= (QualifiedType) type; - return getTypeName(qualifiedType.getQualifier()) + '.' + qualifiedType.getName().getIdentifier(); + QualifiedType qualifiedType = (QualifiedType) type; + return getTypeName(qualifiedType.getQualifier()) + '.' + + qualifiedType.getName().getIdentifier(); } else if (type.isParameterizedType()) { - ParameterizedType parameterizedType= (ParameterizedType)type; - StringBuffer buff= new StringBuffer(getTypeName(parameterizedType.getType())); - Iterator iter= parameterizedType.typeArguments().iterator(); + ParameterizedType parameterizedType = (ParameterizedType) type; + StringBuffer buff = new StringBuffer( + getTypeName(parameterizedType.getType())); + Iterator<Type> iter = parameterizedType.typeArguments().iterator(); if (iter.hasNext() && isSourceLevelGreaterOrEqual(1, 5)) { buff.append('<'); - buff.append(getTypeName((Type)iter.next())); + buff.append(getTypeName(iter.next())); while (iter.hasNext()) { buff.append(','); - buff.append(getTypeName((Type)iter.next())); + buff.append(getTypeName(iter.next())); } buff.append('>'); } return buff.toString(); } else if (type.isWildcardType()) { - WildcardType wildcardType= (WildcardType)type; - StringBuffer buff= new StringBuffer("?"); //$NON-NLS-1$ - Type bound= wildcardType.getBound(); + WildcardType wildcardType = (WildcardType) type; + StringBuffer buff = new StringBuffer("?"); //$NON-NLS-1$ + Type bound = wildcardType.getBound(); if (bound != null) { buff.append(wildcardType.isUpperBound() ? " extends " : " super "); //$NON-NLS-1$ //$NON-NLS-2$ buff.append(getTypeName(bound)); @@ -727,14 +778,16 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return buff.toString(); } return null; - + } - + public String getReturnExpression(Type type) { - if (type.isSimpleType() || type.isArrayType() || type.isQualifiedType() || type.isWildcardType() || type.isParameterizedType()) { + if (type.isSimpleType() || type.isArrayType() || type.isQualifiedType() + || type.isWildcardType() || type.isParameterizedType()) { return "return null;"; //$NON-NLS-1$ } else if (type.isPrimitiveType()) { - String typeName= ((PrimitiveType) type).getPrimitiveTypeCode().toString(); + String typeName = ((PrimitiveType) type).getPrimitiveTypeCode() + .toString(); char char0 = typeName.charAt(0); if (char0 == 'v') { return ""; //$NON-NLS-1$ @@ -747,179 +800,206 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } return null; } - - //---------------------- + // ---------------------- /** * @see ASTVisitor#endVisit(ClassInstanceCreation) */ + @Override public void endVisit(ClassInstanceCreation node) { if (hasError()) { return; } - AnonymousClassDeclaration anonymousClassDeclaration = node.getAnonymousClassDeclaration(); + AnonymousClassDeclaration anonymousClassDeclaration = node + .getAnonymousClassDeclaration(); if (anonymousClassDeclaration != null) { if (!rightTypeFound() && isRightType(node)) { setRightTypeFound(true); - - fSource= buildRunMethod(anonymousClassDeclaration.bodyDeclarations()); + + fSource = buildRunMethod(anonymousClassDeclaration + .bodyDeclarations()); fEvaluateNextEndTypeDeclaration = true; } - + if (rightTypeFound()) { - - List bodyDeclarations= anonymousClassDeclaration.bodyDeclarations(); - + + List<BodyDeclaration> bodyDeclarations = anonymousClassDeclaration + .bodyDeclarations(); + StringBuffer source = buildTypeBody(fSource, bodyDeclarations); - + ASTNode parent = node.getParent(); - while (!(parent instanceof MethodDeclaration || - parent instanceof FieldDeclaration || - parent instanceof Initializer) && parent != null) { - parent= parent.getParent(); - } - - fSource= new StringBuffer(); - - if(parent instanceof Initializer) { - createAnonymousEvalMethod(true, bodyDeclarations, getTypeName(node.getType()), source); + while (!(parent instanceof MethodDeclaration + || parent instanceof FieldDeclaration || parent instanceof Initializer) + && parent != null) { + parent = parent.getParent(); } - else if (parent instanceof MethodDeclaration) { + + fSource = new StringBuffer(); + + if (parent instanceof Initializer) { + createAnonymousEvalMethod(true, bodyDeclarations, + getTypeName(node.getType()), source); + } else if (parent instanceof MethodDeclaration) { MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration) parent; - createAnonymousEvalMethod(Flags.isStatic(enclosingMethodDeclaration.getModifiers()), - bodyDeclarations, - getTypeName(node.getType()), - source); - + createAnonymousEvalMethod( + Flags.isStatic(enclosingMethodDeclaration + .getModifiers()), bodyDeclarations, + getTypeName(node.getType()), source); + } else if (parent instanceof FieldDeclaration) { FieldDeclaration enclosingFieldDeclaration = (FieldDeclaration) parent; - - if (Flags.isStatic(enclosingFieldDeclaration.getModifiers())) { + + if (Flags + .isStatic(enclosingFieldDeclaration.getModifiers())) { fSource.append("static "); //$NON-NLS-1$ } - - Type type = getParentType(enclosingFieldDeclaration.getType()); - fSource.append(getQualifiedIdentifier(((SimpleType)type).getName())); + + Type type = getParentType(enclosingFieldDeclaration + .getType()); + fSource.append(getQualifiedIdentifier(((SimpleType) type) + .getName())); fSource.append(' '); - fSource.append(getUniqueFieldName(EVAL_FIELD_NAME, bodyDeclarations)); + fSource.append(getUniqueFieldName(EVAL_FIELD_NAME, + bodyDeclarations)); fSource.append(" = new "); //$NON-NLS-1$ fSource.append(getTypeName(node.getType())); fSource.append("()"); //$NON-NLS-1$ - - fSnippetStartPosition+= fSource.length(); + + fSnippetStartPosition += fSource.length(); fSource.append(source); fSource.append(";\n"); //$NON-NLS-1$ - + } - fLastTypeName= ""; //$NON-NLS-1$ + fLastTypeName = ""; //$NON-NLS-1$ } - } + } } /** - * Create a <code>void ____eval()</code> method considering the given {@link BodyDeclaration}s, type name and existing - * body source when an anonymous {@link ClassInstanceCreation} is visited. - * <br><br> - * This method adds the new <code>___eval</code> method source to the root {@link #fSource} variable directly + * Create a <code>void ____eval()</code> method considering the given + * {@link BodyDeclaration}s, type name and existing body source when an + * anonymous {@link ClassInstanceCreation} is visited. <br> + * <br> + * This method adds the new <code>___eval</code> method source to the root + * {@link #fSource} variable directly * - * @param isstatic if the keyword <code>static</code> should be added to the method source - * @param bodydecls the existing listing of {@link BodyDeclaration}s to consider when creating the <code>___eval</code> method name - * @param typename the raw type name of the type to instantiate in the <code>___eval</code> method - * @param body the existing body of source to append to the remainder of the new method + * @param isstatic + * if the keyword <code>static</code> should be added to the + * method source + * @param bodydecls + * the existing listing of {@link BodyDeclaration}s to consider + * when creating the <code>___eval</code> method name + * @param typename + * the raw type name of the type to instantiate in the + * <code>___eval</code> method + * @param body + * the existing body of source to append to the remainder of the + * new method * @since 3.7 */ - void createAnonymousEvalMethod(boolean isstatic, List bodydecls, String typename, StringBuffer body) { - if(isstatic) { + void createAnonymousEvalMethod(boolean isstatic, List<BodyDeclaration> bodydecls, + String typename, StringBuffer body) { + if (isstatic) { fSource.append("static "); //$NON-NLS-1$ } fSource.append("void "); //$NON-NLS-1$ fSource.append(getUniqueMethodName(EVAL_METHOD_NAME, bodydecls)); fSource.append("() {\n"); //$NON-NLS-1$ fSource.append("new "); //$NON-NLS-1$ - fSource.append(typename); + fSource.append(typename); fSource.append("()"); //$NON-NLS-1$ - - fSnippetStartPosition+= fSource.length(); + + fSnippetStartPosition += fSource.length(); fSource.append(body); fSource.append(";}\n"); //$NON-NLS-1$ } - + /** - * Recursively finds the parent {@link Type} from the given type, in the cases where - * the type is an {@link ArrayType} or a {@link ParameterizedType} - * @param type the {@link Type} + * Recursively finds the parent {@link Type} from the given type, in the + * cases where the type is an {@link ArrayType} or a + * {@link ParameterizedType} + * + * @param type + * the {@link Type} * @return the parent {@link Type} */ private Type getParentType(Type type) { - if(type instanceof ArrayType) { - return getParentType(((ArrayType)type).getComponentType()); + if (type instanceof ArrayType) { + return getParentType(((ArrayType) type).getComponentType()); } - if(type instanceof ParameterizedType) { - return getParentType(((ParameterizedType)type).getType()); + if (type instanceof ParameterizedType) { + return getParentType(((ParameterizedType) type).getType()); } return type; } - + /** * @see ASTVisitor#endVisit(CompilationUnit) */ + @Override public void endVisit(CompilationUnit node) { if (hasError()) { return; } if (!rightTypeFound()) { // if the right type hasn't been found - fSource= null; + fSource = null; return; } fSource = buildCompilationUnit(fSource, node); } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.EnumDeclaration) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom + * .EnumDeclaration) */ + @Override public void endVisit(EnumDeclaration node) { - + if (hasError()) { return; } - + if (!rightTypeFound() && isRightType(node)) { setRightTypeFound(true); - - fSource= buildRunMethod(node.bodyDeclarations()); + + fSource = buildRunMethod(node.bodyDeclarations()); fEvaluateNextEndTypeDeclaration = true; } - + if (!fEvaluateNextEndTypeDeclaration) { fEvaluateNextEndTypeDeclaration = true; return; } - + if (rightTypeFound()) { - + StringBuffer source = buildEnumDeclaration(fSource, node); - + if (node.isLocalTypeDeclaration()) { // enclose in a method if necessary - + ASTNode parent = node.getParent(); while (!(parent instanceof MethodDeclaration)) { - parent= parent.getParent(); + parent = parent.getParent(); } MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration) parent; - + fSource = new StringBuffer(); - + if (Flags.isStatic(enclosingMethodDeclaration.getModifiers())) { fSource.append("static "); //$NON-NLS-1$ } - + fSource.append("void ___eval() {\n"); //$NON-NLS-1$ - fSnippetStartPosition+= fSource.length(); + fSnippetStartPosition += fSource.length(); fSource.append(source); fSource.append("}\n"); //$NON-NLS-1$ - + fLastTypeName = ""; //$NON-NLS-1$ } else { fSource = source; @@ -931,48 +1011,49 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#endVisit(TypeDeclaration) */ + @Override public void endVisit(TypeDeclaration node) { - + if (hasError()) { return; } - + if (!rightTypeFound() && isRightType(node)) { setRightTypeFound(true); - - fSource= buildRunMethod(node.bodyDeclarations()); + + fSource = buildRunMethod(node.bodyDeclarations()); fEvaluateNextEndTypeDeclaration = true; } - + if (!fEvaluateNextEndTypeDeclaration) { fEvaluateNextEndTypeDeclaration = true; return; } - + if (rightTypeFound()) { - + StringBuffer source = buildTypeDeclaration(fSource, node); - + if (node.isLocalTypeDeclaration()) { // enclose in a method if nessecary - + ASTNode parent = node.getParent(); while (!(parent instanceof MethodDeclaration)) { - parent= parent.getParent(); + parent = parent.getParent(); } MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration) parent; - + fSource = new StringBuffer(); - + if (Flags.isStatic(enclosingMethodDeclaration.getModifiers())) { fSource.append("static "); //$NON-NLS-1$ } - + fSource.append("void ___eval() {\n"); //$NON-NLS-1$ - fSnippetStartPosition+= fSource.length(); + fSnippetStartPosition += fSource.length(); fSource.append(source); fSource.append("}\n"); //$NON-NLS-1$ - + fLastTypeName = ""; //$NON-NLS-1$ } else { fSource = source; @@ -981,23 +1062,32 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } } - /* (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; } - + /** * @see ASTVisitor#visit(AnonymousClassDeclaration) */ + @Override public boolean visit(AnonymousClassDeclaration node) { if (rightTypeFound()) { return false; @@ -1008,6 +1098,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayAccess) */ + @Override public boolean visit(ArrayAccess node) { if (rightTypeFound()) { return false; @@ -1018,6 +1109,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayCreation) */ + @Override public boolean visit(ArrayCreation node) { if (rightTypeFound()) { return false; @@ -1028,6 +1120,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayInitializer) */ + @Override public boolean visit(ArrayInitializer node) { if (rightTypeFound()) { return false; @@ -1038,6 +1131,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ArrayType) */ + @Override public boolean visit(ArrayType node) { if (rightTypeFound()) { return false; @@ -1048,6 +1142,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(AssertStatement) */ + @Override public boolean visit(AssertStatement node) { if (rightTypeFound()) { return false; @@ -1058,6 +1153,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(Assignment) */ + @Override public boolean visit(Assignment node) { if (rightTypeFound()) { return false; @@ -1068,6 +1164,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(Block) */ + @Override public boolean visit(Block node) { if (rightTypeFound()) { return false; @@ -1075,9 +1172,13 @@ public class SourceBasedSourceGenerator 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; } @@ -1085,6 +1186,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(BooleanLiteral) */ + @Override public boolean visit(BooleanLiteral node) { if (rightTypeFound()) { return false; @@ -1095,6 +1197,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(BreakStatement) */ + @Override public boolean visit(BreakStatement node) { if (rightTypeFound()) { return false; @@ -1105,6 +1208,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(CastExpression) */ + @Override public boolean visit(CastExpression node) { if (rightTypeFound()) { return false; @@ -1115,6 +1219,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(CatchClause) */ + @Override public boolean visit(CatchClause node) { if (rightTypeFound()) { return false; @@ -1125,6 +1230,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(CharacterLiteral) */ + @Override public boolean visit(CharacterLiteral node) { if (rightTypeFound()) { return false; @@ -1135,6 +1241,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ClassInstanceCreation) */ + @Override public boolean visit(ClassInstanceCreation node) { if (rightTypeFound()) { return false; @@ -1145,7 +1252,8 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(CompilationUnit) */ - public boolean visit(CompilationUnit node) { + @Override + public boolean visit(CompilationUnit node) { if (rightTypeFound()) { return false; } @@ -1155,6 +1263,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ConditionalExpression) */ + @Override public boolean visit(ConditionalExpression node) { if (rightTypeFound()) { return false; @@ -1165,6 +1274,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ConstructorInvocation) */ + @Override public boolean visit(ConstructorInvocation node) { if (rightTypeFound()) { return false; @@ -1175,6 +1285,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ContinueStatement) */ + @Override public boolean visit(ContinueStatement node) { if (rightTypeFound()) { return false; @@ -1185,6 +1296,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(DoStatement) */ + @Override public boolean visit(DoStatement node) { if (rightTypeFound()) { return false; @@ -1195,6 +1307,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(EmptyStatement) */ + @Override public boolean visit(EmptyStatement node) { if (rightTypeFound()) { return false; @@ -1202,9 +1315,13 @@ public class SourceBasedSourceGenerator 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 (rightTypeFound()) { return false; @@ -1212,19 +1329,27 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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 (rightTypeFound()) { return false; } return true; } - - /* (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 (rightTypeFound()) { fEvaluateNextEndTypeDeclaration = false; @@ -1232,10 +1357,11 @@ public class SourceBasedSourceGenerator extends ASTVisitor { } return true; } - + /** * @see ASTVisitor#visit(ExpressionStatement) */ + @Override public boolean visit(ExpressionStatement node) { if (rightTypeFound()) { return false; @@ -1246,6 +1372,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(FieldAccess) */ + @Override public boolean visit(FieldAccess node) { if (rightTypeFound()) { return false; @@ -1256,6 +1383,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(FieldDeclaration) */ + @Override public boolean visit(FieldDeclaration node) { if (rightTypeFound()) { return false; @@ -1266,6 +1394,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ForStatement) */ + @Override public boolean visit(ForStatement node) { if (rightTypeFound()) { return false; @@ -1276,6 +1405,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(IfStatement) */ + @Override public boolean visit(IfStatement node) { if (rightTypeFound()) { return false; @@ -1286,6 +1416,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ImportDeclaration) */ + @Override public boolean visit(ImportDeclaration node) { if (rightTypeFound()) { return false; @@ -1296,6 +1427,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(InfixExpression) */ + @Override public boolean visit(InfixExpression node) { if (rightTypeFound()) { return false; @@ -1306,6 +1438,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(Initializer) */ + @Override public boolean visit(Initializer node) { if (rightTypeFound()) { return false; @@ -1313,18 +1446,24 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.InstanceofExpression) + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. + * InstanceofExpression) */ + @Override public boolean visit(InstanceofExpression node) { if (rightTypeFound()) { return false; } return true; } + /** * @see ASTVisitor#visit(Javadoc) */ + @Override public boolean visit(Javadoc node) { if (rightTypeFound()) { return false; @@ -1335,6 +1474,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(LabeledStatement) */ + @Override public boolean visit(LabeledStatement node) { if (rightTypeFound()) { return false; @@ -1342,42 +1482,61 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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) { - List typeParameters = node.typeParameters(); + List<TypeParameter> typeParameters = node.typeParameters(); if (!typeParameters.isEmpty()) { - Iterator iterator = typeParameters.iterator(); + Iterator<TypeParameter> iterator = typeParameters.iterator(); while (iterator.hasNext()) { - TypeParameter typeParameter= (TypeParameter) iterator.next(); + TypeParameter typeParameter = iterator.next(); fTypeParameters.add(typeParameter.toString()); } } @@ -1390,6 +1549,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(MethodInvocation) */ + @Override public boolean visit(MethodInvocation node) { if (rightTypeFound()) { return false; @@ -1397,37 +1557,56 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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; } - + /** * @see ASTVisitor#visit(NullLiteral) */ + @Override public boolean visit(NullLiteral node) { if (rightTypeFound()) { return false; @@ -1438,6 +1617,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(NumberLiteral) */ + @Override public boolean visit(NumberLiteral node) { if (rightTypeFound()) { return false; @@ -1448,6 +1628,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(PackageDeclaration) */ + @Override public boolean visit(PackageDeclaration node) { if (rightTypeFound()) { return false; @@ -1455,9 +1636,13 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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 (rightTypeFound()) { return false; @@ -1468,6 +1653,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ParenthesizedExpression) */ + @Override public boolean visit(ParenthesizedExpression node) { if (rightTypeFound()) { return false; @@ -1478,6 +1664,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(PostfixExpression) */ + @Override public boolean visit(PostfixExpression node) { if (rightTypeFound()) { return false; @@ -1488,6 +1675,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(PrefixExpression) */ + @Override public boolean visit(PrefixExpression node) { if (rightTypeFound()) { return false; @@ -1498,6 +1686,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(PrimitiveType) */ + @Override public boolean visit(PrimitiveType node) { if (rightTypeFound()) { return false; @@ -1508,6 +1697,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(QualifiedName) */ + @Override public boolean visit(QualifiedName node) { if (rightTypeFound()) { return false; @@ -1515,15 +1705,21 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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) { return false; } + /** * @see ASTVisitor#visit(ReturnStatement) */ + @Override public boolean visit(ReturnStatement node) { if (rightTypeFound()) { return false; @@ -1534,6 +1730,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SimpleName) */ + @Override public boolean visit(SimpleName node) { if (rightTypeFound()) { return false; @@ -1544,6 +1741,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SimpleType) */ + @Override public boolean visit(SimpleType node) { if (rightTypeFound()) { return false; @@ -1551,16 +1749,21 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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) */ + @Override public boolean visit(SingleVariableDeclaration node) { if (rightTypeFound()) { return false; @@ -1571,6 +1774,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(StringLiteral) */ + @Override public boolean visit(StringLiteral node) { if (rightTypeFound()) { return false; @@ -1581,6 +1785,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SuperConstructorInvocation) */ + @Override public boolean visit(SuperConstructorInvocation node) { if (rightTypeFound()) { return false; @@ -1591,6 +1796,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SuperFieldAccess) */ + @Override public boolean visit(SuperFieldAccess node) { if (rightTypeFound()) { return false; @@ -1601,6 +1807,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SuperMethodInvocation) */ + @Override public boolean visit(SuperMethodInvocation node) { if (rightTypeFound()) { return false; @@ -1611,6 +1818,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SwitchCase) */ + @Override public boolean visit(SwitchCase node) { if (rightTypeFound()) { return false; @@ -1621,6 +1829,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SwitchStatement) */ + @Override public boolean visit(SwitchStatement node) { if (rightTypeFound()) { return false; @@ -1631,6 +1840,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(SynchronizedStatement) */ + @Override public boolean visit(SynchronizedStatement node) { if (rightTypeFound()) { return false; @@ -1638,16 +1848,25 @@ public class SourceBasedSourceGenerator 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; } @@ -1655,6 +1874,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ThisExpression) */ + @Override public boolean visit(ThisExpression node) { if (rightTypeFound()) { return false; @@ -1665,6 +1885,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(ThrowStatement) */ + @Override public boolean visit(ThrowStatement node) { if (rightTypeFound()) { return false; @@ -1675,6 +1896,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(TryStatement) */ + @Override public boolean visit(TryStatement node) { if (rightTypeFound()) { return false; @@ -1682,25 +1904,31 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (non-Javadoc) - * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.UnionType) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.UnionType + * ) */ + @Override public boolean visit(UnionType node) { if (rightTypeFound()) { return false; } return true; } - + /** * @see ASTVisitor#visit(TypeDeclaration) */ + @Override public boolean visit(TypeDeclaration node) { - List typeParameters = node.typeParameters(); + List<TypeParameter> typeParameters = node.typeParameters(); if (!typeParameters.isEmpty()) { - Iterator iterator = typeParameters.iterator(); + Iterator<TypeParameter> iterator = typeParameters.iterator(); while (iterator.hasNext()) { - TypeParameter typeParameter= (TypeParameter) iterator.next(); + TypeParameter typeParameter = iterator.next(); fTypeParameters.add(typeParameter.getName().getIdentifier()); } } @@ -1714,6 +1942,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(TypeDeclarationStatement) */ + @Override public boolean visit(TypeDeclarationStatement node) { if (rightTypeFound()) { return false; @@ -1724,6 +1953,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(TypeLiteral) */ + @Override public boolean visit(TypeLiteral node) { if (rightTypeFound()) { return false; @@ -1731,9 +1961,13 @@ public class SourceBasedSourceGenerator extends ASTVisitor { return true; } - /* (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; } @@ -1741,6 +1975,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationExpression) */ + @Override public boolean visit(VariableDeclarationExpression node) { if (rightTypeFound()) { return false; @@ -1751,6 +1986,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationFragment) */ + @Override public boolean visit(VariableDeclarationFragment node) { if (rightTypeFound()) { return false; @@ -1761,6 +1997,7 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(VariableDeclarationStatement) */ + @Override public boolean visit(VariableDeclarationStatement node) { if (rightTypeFound()) { return false; @@ -1771,72 +2008,82 @@ public class SourceBasedSourceGenerator extends ASTVisitor { /** * @see ASTVisitor#visit(WhileStatement) */ + @Override public boolean visit(WhileStatement node) { if (rightTypeFound()) { return false; } return true; } - - /* (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) { return false; } /** - * Returns whether the source to be generated is greater than or equal to the - * given source level. + * Returns whether the source to be generated is greater than or equal to + * the given source level. * - * @param major major level - e.g. 1 from 1.4 - * @param minor minor level - e.g. 4 from 1.4 - * @return <code>true</code> if the given major / minor version is less than or equal to the backing source level + * @param major + * major level - e.g. 1 from 1.4 + * @param minor + * minor level - e.g. 4 from 1.4 + * @return <code>true</code> if the given major / minor version is less than + * or equal to the backing source level */ public boolean isSourceLevelGreaterOrEqual(int major, int minor) { - return (fSourceMajorLevel > major) || - (fSourceMajorLevel == major && fSourceMinorLevel >= minor); + return (fSourceMajorLevel > major) + || (fSourceMajorLevel == major && fSourceMinorLevel >= minor); } - + /** * Appends type parameters to source. * - * @param source the current buffer of source to append to - * @param typeParameters the list of {@link TypeParameter}s to add + * @param source + * the current buffer of source to append to + * @param typeParameters + * the list of {@link TypeParameter}s to add */ - private void appendTypeParameters(StringBuffer source, List typeParameters) { + private void appendTypeParameters(StringBuffer source, List<TypeParameter> typeParameters) { if (!typeParameters.isEmpty() && isSourceLevelGreaterOrEqual(1, 5)) { source.append('<'); - Iterator iter= typeParameters.iterator(); - TypeParameter typeParameter= (TypeParameter) iter.next(); + Iterator<TypeParameter> iter = typeParameters.iterator(); + TypeParameter typeParameter = iter.next(); source.append(typeParameter.getName().getIdentifier()); - List typeBounds= typeParameter.typeBounds(); + List<Type> typeBounds = typeParameter.typeBounds(); if (!typeBounds.isEmpty()) { source.append(" extends "); //$NON-NLS-1$ - Iterator iter2= typeBounds.iterator(); - source.append(getTypeName((Type) iter2.next())); + Iterator<Type> iter2 = typeBounds.iterator(); + source.append(getTypeName(iter2.next())); while (iter2.hasNext()) { source.append('&'); - source.append(getTypeName((Type) iter2.next())); + source.append(getTypeName(iter2.next())); } } while (iter.hasNext()) { source.append(','); - typeParameter= (TypeParameter) iter.next(); + typeParameter = iter.next(); source.append(typeParameter.getName().getIdentifier()); - typeBounds= typeParameter.typeBounds(); + typeBounds = typeParameter.typeBounds(); if (!typeBounds.isEmpty()) { source.append(" extends "); //$NON-NLS-1$ - Iterator iter2= typeBounds.iterator(); - source.append(getTypeName((Type) iter2.next())); + Iterator<Type> iter2 = typeBounds.iterator(); + source.append(getTypeName(iter2.next())); while (iter2.hasNext()) { source.append('&'); - source.append(getTypeName((Type) iter2.next())); + source.append(getTypeName(iter2.next())); } } } source.append('>'); source.append(' '); - } - } + } + } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndAssignmentOperator.java index 1e9c36bcd..2909c8f9c 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndAssignmentOperator.java @@ -15,8 +15,9 @@ public class AndAssignmentOperator extends AndOperator { public AndAssignmentOperator(int variableTypeId, int valueTypeId, int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.AndAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.AndAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndOperator.java index d536e20a5..a1509d329 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AndOperator.java @@ -13,60 +13,74 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; - public class AndOperator extends BinaryOperator { public AndOperator(int resultId, int leftTypeId, int rightTypeId, int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected AndOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperateur, int start) { + protected AndOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperateur, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperateur, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() & ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() + & ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getIntValue() & ((IJavaPrimitiveValue) rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + & ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getLongValue() & ((IJavaPrimitiveValue) rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + & ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.AndOperator_____operator_1; + return InstructionsEvaluationMessages.AndOperator_____operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAccess.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAccess.java index de0b2c70f..7493dda72 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAccess.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAccess.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -20,49 +19,62 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import com.ibm.icu.text.MessageFormat; - + /** - * Resolves an array access - the top of the stack is - * the position, and the second from top is the array - * object. + * Resolves an array access - the top of the stack is the position, and the + * second from top is the array object. */ public class ArrayAccess extends ArrayInstruction { - + public ArrayAccess(int start) { super(start); } - + + @Override public void execute() throws CoreException { - int index = ((IJavaPrimitiveValue)popValue()).getIntValue(); + int index = ((IJavaPrimitiveValue) popValue()).getIntValue(); IJavaArray array = popArray(); if (index >= array.getLength() || index < 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.ArrayAccess_illegal_index, new Object[] {new Integer(index)}), null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.ArrayAccess_illegal_index, + new Object[] { new Integer(index) }), + null)); } push(array.getVariable(index)); } + @Override public String toString() { - return InstructionsEvaluationMessages.ArrayAccess_array_access_1; + return InstructionsEvaluationMessages.ArrayAccess_array_access_1; } - + /** - * Pops an array object off the top of the stack. Throws an exception if not an array - * object or <code>null</code>. + * Pops an array object off the top of the stack. Throws an exception if not + * an array object or <code>null</code>. * * @return array object on top of the stack - * @throws CoreException if not available + * @throws CoreException + * if not available */ protected IJavaArray popArray() throws CoreException { IJavaValue value = popValue(); if (value instanceof IJavaArray) { - return (IJavaArray)value; + return (IJavaArray) value; } else if (value.isNull()) { // null pointer - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.ArrayAccess_0, null)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + InstructionsEvaluationMessages.ArrayAccess_0, null)); } else { // internal error - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, "Internal error: attempt to access non-array object", null)); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + "Internal error: attempt to access non-array object", null)); //$NON-NLS-1$ } } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAllocation.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAllocation.java index 14d5a363c..4610538bd 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAllocation.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayAllocation.java @@ -19,18 +19,20 @@ import org.eclipse.jdt.debug.core.IJavaType; public class ArrayAllocation extends ArrayInstruction { private int fDimension; - + private int fExprDimension; - + private boolean fHasInitializer; - + private IJavaArrayType[] fCachedArrayTypes; /** * Constructor for ArrayAllocation. + * * @param start */ - public ArrayAllocation(int dimension, int exprDimension, boolean hasInitializer, int start) { + public ArrayAllocation(int dimension, int exprDimension, + boolean hasInitializer, int start) { super(start); fDimension = dimension; fExprDimension = exprDimension; @@ -40,58 +42,63 @@ public class ArrayAllocation extends ArrayInstruction { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { if (fHasInitializer) { IJavaArray array = (IJavaArray) popValue(); pop(); // pop the type push(array); } else { - + int[] exprDimensions = new int[fExprDimension]; - + for (int i = fExprDimension - 1; i >= 0; i--) { - exprDimensions[i] = ((IJavaPrimitiveValue)popValue()).getIntValue(); + exprDimensions[i] = ((IJavaPrimitiveValue) popValue()) + .getIntValue(); } - + IJavaType type = (IJavaType) pop(); - + fCachedArrayTypes = new IJavaArrayType[fDimension + 1]; - - for (int i =fDimension, lim = fDimension - fExprDimension ; i > lim; i--) { + + for (int i = fDimension, lim = fDimension - fExprDimension; i > lim; i--) { fCachedArrayTypes[i] = (IJavaArrayType) type; - type = ((IJavaArrayType)type).getComponentType(); + type = ((IJavaArrayType) type).getComponentType(); } - + IJavaArray array = createArray(fDimension, exprDimensions); - + push(array); } } - + /** * Create and populate an array. */ - private IJavaArray createArray(int dimension, int[] exprDimensions) throws CoreException { - - IJavaArray array = fCachedArrayTypes[dimension].newInstance(exprDimensions[0]); - + private IJavaArray createArray(int dimension, int[] exprDimensions) + throws CoreException { + + IJavaArray array = fCachedArrayTypes[dimension] + .newInstance(exprDimensions[0]); + if (exprDimensions.length > 1) { int[] newExprDimension = new int[exprDimensions.length - 1]; for (int i = 0; i < newExprDimension.length; i++) { newExprDimension[i] = exprDimensions[i + 1]; } - + for (int i = 0; i < exprDimensions[0]; i++) { array.setValue(i, createArray(dimension - 1, newExprDimension)); } - + } - + return array; - } + } + @Override public String toString() { - return InstructionsEvaluationMessages.ArrayAllocation_array_allocation_1; + return InstructionsEvaluationMessages.ArrayAllocation_array_allocation_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInitializerInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInitializerInstruction.java index c0e89d079..cede6f398 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInitializerInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInitializerInstruction.java @@ -17,16 +17,18 @@ import org.eclipse.jdt.debug.core.IJavaArrayType; public class ArrayInitializerInstruction extends ArrayInstruction { private String fTypeSignature; - + private int fDimensions; - + private int fLength; /** * Constructor for ArrayInitializerInstruction. + * * @param start */ - public ArrayInitializerInstruction(String typeSignature, int length, int dimensions, int start) { + public ArrayInitializerInstruction(String typeSignature, int length, + int dimensions, int start) { super(start); fTypeSignature = typeSignature; fDimensions = dimensions; @@ -36,21 +38,24 @@ public class ArrayInitializerInstruction extends ArrayInstruction { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - - IJavaArrayType arrayType = getArrayType(fTypeSignature.replace('/','.'), fDimensions); + + IJavaArrayType arrayType = getArrayType( + fTypeSignature.replace('/', '.'), fDimensions); IJavaArray array = arrayType.newInstance(fLength); - + for (int i = fLength - 1; i >= 0; i--) { array.setValue(i, popValue()); } - + push(array); - + } + @Override public String toString() { - return InstructionsEvaluationMessages.ArrayInitializerInstruction_array_initializer_1; + return InstructionsEvaluationMessages.ArrayInitializerInstruction_array_initializer_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInstruction.java index 9ed66eaed..2a9ec39a2 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ArrayInstruction.java @@ -10,12 +10,10 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - public abstract class ArrayInstruction extends CompoundInstruction { - public ArrayInstruction(int start) { super(start); } - + } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java index f7fdae66d..12a1b9ac9 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java @@ -20,7 +20,6 @@ public class AssignmentOperator extends CompoundInstruction { protected int fVariableTypeId; protected int fValueTypeId; - public AssignmentOperator(int variableTypeId, int valueTypeId, int start) { super(start); fVariableTypeId = variableTypeId; @@ -30,37 +29,38 @@ public class AssignmentOperator extends CompoundInstruction { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaValue value = popValue(); IJavaVariable variable = (IJavaVariable) pop(); - + if (value instanceof IJavaPrimitiveValue) { IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value; switch (fVariableTypeId) { - case T_boolean: - variable.setValue(newValue(primitiveValue.getBooleanValue())); - break; - case T_byte: - variable.setValue(newValue(primitiveValue.getByteValue())); - break; - case T_short: - variable.setValue(newValue(primitiveValue.getShortValue())); - break; - case T_char: - variable.setValue(newValue(primitiveValue.getCharValue())); - break; - case T_int: - variable.setValue(newValue(primitiveValue.getIntValue())); - break; - case T_long: - variable.setValue(newValue(primitiveValue.getLongValue())); - break; - case T_float: - variable.setValue(newValue(primitiveValue.getFloatValue())); - break; - case T_double: - variable.setValue(newValue(primitiveValue.getDoubleValue())); - break; + case T_boolean: + variable.setValue(newValue(primitiveValue.getBooleanValue())); + break; + case T_byte: + variable.setValue(newValue(primitiveValue.getByteValue())); + break; + case T_short: + variable.setValue(newValue(primitiveValue.getShortValue())); + break; + case T_char: + variable.setValue(newValue(primitiveValue.getCharValue())); + break; + case T_int: + variable.setValue(newValue(primitiveValue.getIntValue())); + break; + case T_long: + variable.setValue(newValue(primitiveValue.getLongValue())); + break; + case T_float: + variable.setValue(newValue(primitiveValue.getFloatValue())); + break; + case T_double: + variable.setValue(newValue(primitiveValue.getDoubleValue())); + break; } } else { variable.setValue(value); @@ -68,7 +68,8 @@ public class AssignmentOperator extends CompoundInstruction { push(variable.getValue()); } + @Override public String toString() { - return InstructionsEvaluationMessages.AssignmentOperator_operator_1; + return InstructionsEvaluationMessages.AssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/BinaryOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/BinaryOperator.java index 006c543ee..f26d764f8 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/BinaryOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/BinaryOperator.java @@ -20,17 +20,19 @@ public abstract class BinaryOperator extends CompoundInstruction { protected int fRightTypeId; protected boolean fIsAssignmentOperator; - protected BinaryOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignementOperator, int start) { + protected BinaryOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignementOperator, int start) { super(start); - fResultTypeId= resultId; - fLeftTypeId= leftTypeId; - fRightTypeId= rightTypeId; - fIsAssignmentOperator= isAssignementOperator; + fResultTypeId = resultId; + fLeftTypeId = leftTypeId; + fRightTypeId = rightTypeId; + fIsAssignmentOperator = isAssignementOperator; } - + /* * @see Instruction#execute() */ + @Override final public void execute() throws CoreException { if (fIsAssignmentOperator) { executeAssignment(); @@ -38,195 +40,210 @@ public abstract class BinaryOperator extends CompoundInstruction { executeBinary(); } } - + private void executeAssignment() throws CoreException { IJavaValue value = popValue(); IJavaVariable variable = (IJavaVariable) pop(); - IJavaValue variableValue = (IJavaValue)variable.getValue(); - + IJavaValue variableValue = (IJavaValue) variable.getValue(); + switch (fResultTypeId) { - case T_byte: - variableValue= getByteValueResult(variableValue, value); - break; - case T_short: - variableValue= getShortValueResult(variableValue, value); - break; - case T_char: - variableValue= getCharValueResult(variableValue, value); - break; - case T_int: - variableValue= getIntValueResult(variableValue, value); - break; - case T_long: - variableValue= getLongValueResult(variableValue, value); - break; - case T_float: - variableValue= getFloatValueResult(variableValue, value); - break; - case T_double: - variableValue= getDoubleValueResult(variableValue, value); - break; - case T_boolean: - variableValue= getBooleanValueResult(variableValue, value); - break; - case T_String: - variableValue= getStringValueResult(variableValue, value); - break; + case T_byte: + variableValue = getByteValueResult(variableValue, value); + break; + case T_short: + variableValue = getShortValueResult(variableValue, value); + break; + case T_char: + variableValue = getCharValueResult(variableValue, value); + break; + case T_int: + variableValue = getIntValueResult(variableValue, value); + break; + case T_long: + variableValue = getLongValueResult(variableValue, value); + break; + case T_float: + variableValue = getFloatValueResult(variableValue, value); + break; + case T_double: + variableValue = getDoubleValueResult(variableValue, value); + break; + case T_boolean: + variableValue = getBooleanValueResult(variableValue, value); + break; + case T_String: + variableValue = getStringValueResult(variableValue, value); + break; } variable.setValue(variableValue); push(variableValue); } - + private void executeBinary() throws CoreException { - IJavaValue right= popValue(); - IJavaValue left= popValue(); + IJavaValue right = popValue(); + IJavaValue left = popValue(); switch (fResultTypeId) { - case T_String: - pushNewValue(getStringResult(left, right)); - break; - case T_double: - pushNewValue(getDoubleResult(left, right)); - break; - case T_float: - pushNewValue(getFloatResult(left, right)); - break; - case T_long: - pushNewValue(getLongResult(left, right)); - break; - case T_int: - pushNewValue(getIntResult(left, right)); - break; - case T_boolean: - pushNewValue(getBooleanResult(left, right)); - break; - } + case T_String: + pushNewValue(getStringResult(left, right)); + break; + case T_double: + pushNewValue(getDoubleResult(left, right)); + break; + case T_float: + pushNewValue(getFloatResult(left, right)); + break; + case T_long: + pushNewValue(getLongResult(left, right)); + break; + case T_int: + pushNewValue(getIntResult(left, right)); + break; + case T_boolean: + pushNewValue(getBooleanResult(left, right)); + break; + } } - - private IJavaValue getByteValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getByteValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((byte) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((byte) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((byte) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((byte) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((byte) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((byte) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((byte) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((byte) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getShortValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getShortValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((short) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((short) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((short) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((short) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((short) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((short) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((short) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((short) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getCharValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getCharValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((char) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((char) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((char) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((char) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((char) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((char) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((char) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((char) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getIntValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getIntValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((int) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((int) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((int) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue(getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((int) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((int) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((int) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue(getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getLongValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getLongValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((long) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((long) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue(getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((long) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((long) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((long) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue(getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((long) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getFloatValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getFloatValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue((float) getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue(getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((float) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((float) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue((float) getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue(getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((float) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((float) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getDoubleValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getDoubleValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { switch (getInternResultType()) { - case T_double: - return newValue(getDoubleResult(leftOperand, rightOperand)); - case T_float: - return newValue((double) getFloatResult(leftOperand, rightOperand)); - case T_long: - return newValue((double) getLongResult(leftOperand, rightOperand)); - case T_int: - return newValue((double) getIntResult(leftOperand, rightOperand)); - default: - return null; + case T_double: + return newValue(getDoubleResult(leftOperand, rightOperand)); + case T_float: + return newValue((double) getFloatResult(leftOperand, rightOperand)); + case T_long: + return newValue((double) getLongResult(leftOperand, rightOperand)); + case T_int: + return newValue((double) getIntResult(leftOperand, rightOperand)); + default: + return null; } } - - private IJavaValue getBooleanValueResult(IJavaValue leftOperand, IJavaValue rightOperand) { + + private IJavaValue getBooleanValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return newValue(getBooleanResult(leftOperand, rightOperand)); } - - private IJavaValue getStringValueResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { + + private IJavaValue getStringValueResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { return newValue(getStringResult(leftOperand, rightOperand)); } - - protected abstract int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException; - - protected abstract long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException; - protected abstract float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand); + protected abstract int getIntResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException; + + protected abstract long getLongResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException; + + protected abstract float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand); - protected abstract double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand); + protected abstract double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand); - protected abstract boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand); + protected abstract boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand); - protected abstract String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException; + protected abstract String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException; protected int getInternResultType() { return getBinaryPromotionType(fLeftTypeId, fRightTypeId); diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Cast.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Cast.java index 1a1e8c72f..171c2d263 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Cast.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Cast.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -22,91 +20,119 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.core.model.JDINullValue; +import com.ibm.icu.text.MessageFormat; + public class Cast extends CompoundInstruction { - public static final String IS_INSTANCE= "isInstance"; //$NON-NLS-1$ - public static final String IS_INSTANCE_SIGNATURE= "(Ljava/lang/Object;)Z"; //$NON-NLS-1$ + public static final String IS_INSTANCE = "isInstance"; //$NON-NLS-1$ + public static final String IS_INSTANCE_SIGNATURE = "(Ljava/lang/Object;)Z"; //$NON-NLS-1$ private int fTypeTypeId; - + private String fBaseTypeName; - + private int fDimension; - + /** * Cast intruction constructor. * - * @param typeTypeId the id of the type to cast into. - * @param baseTypeName the base type name of the type (the type name if the - * type is not an array type. - * @param dimension the dimension of the array type, 0 if the type is not an - * array type. + * @param typeTypeId + * the id of the type to cast into. + * @param baseTypeName + * the base type name of the type (the type name if the type is + * not an array type. + * @param dimension + * the dimension of the array type, 0 if the type is not an array + * type. */ public Cast(int typeTypeId, String baseTypeName, int dimension, int start) { super(start); - fTypeTypeId= typeTypeId; - fBaseTypeName= baseTypeName; - fDimension= dimension; + fTypeTypeId = typeTypeId; + fBaseTypeName = baseTypeName; + fDimension = dimension; } /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaValue value= popValue(); - + IJavaValue value = popValue(); + if (value instanceof IJavaPrimitiveValue) { IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value; switch (fTypeTypeId) { - case T_double: - push(newValue(primitiveValue.getDoubleValue())); - break; - case T_float: - push(newValue(primitiveValue.getFloatValue())); - break; - case T_long: - push(newValue(primitiveValue.getLongValue())); - break; - case T_int: - push(newValue(primitiveValue.getIntValue())); - break; - case T_short: - push(newValue(primitiveValue.getShortValue())); - break; - case T_byte: - push(newValue(primitiveValue.getByteValue())); - break; - case T_char: - push(newValue(primitiveValue.getCharValue())); - break; + case T_double: + push(newValue(primitiveValue.getDoubleValue())); + break; + case T_float: + push(newValue(primitiveValue.getFloatValue())); + break; + case T_long: + push(newValue(primitiveValue.getLongValue())); + break; + case T_int: + push(newValue(primitiveValue.getIntValue())); + break; + case T_short: + push(newValue(primitiveValue.getShortValue())); + break; + case T_byte: + push(newValue(primitiveValue.getByteValue())); + break; + case T_char: + push(newValue(primitiveValue.getCharValue())); + break; } - + } else if (value instanceof JDINullValue) { // null value can be cast to all non-primitive types (bug 31637). push(value); } else { IJavaObject classObject; if (fDimension == 0) { - classObject= getClassObject(getType(fBaseTypeName)); + classObject = getClassObject(getType(fBaseTypeName)); } else { - classObject= getClassObject(getArrayType(Signature.createTypeSignature(fBaseTypeName, true), fDimension)); + classObject = getClassObject(getArrayType( + Signature.createTypeSignature(fBaseTypeName, true), + fDimension)); } if (classObject == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Cast_No_class_object, new String[]{typeName()}), null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.Cast_No_class_object, + new String[] { typeName() }), + null)); } - IJavaPrimitiveValue resultValue = (IJavaPrimitiveValue)classObject.sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE, new IJavaValue[] {value}, getContext().getThread(), false); + IJavaPrimitiveValue resultValue = (IJavaPrimitiveValue) classObject + .sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE, + new IJavaValue[] { value }, getContext() + .getThread(), false); if (!resultValue.getBooleanValue()) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Cast_ClassCastException__Cannot_cast__0__as__1___1, new String[]{value.toString(), typeName()}), null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.Cast_ClassCastException__Cannot_cast__0__as__1___1, + new String[] { + value.toString(), + typeName() }), null)); } - + push(value); } } - + private String typeName() { - String result= fBaseTypeName; - for (int i= 0; i < fDimension; i++) { - result+= "[]"; //$NON-NLS-1$ + String result = fBaseTypeName; + for (int i = 0; i < fDimension; i++) { + result += "[]"; //$NON-NLS-1$ } return result; } @@ -114,8 +140,9 @@ public class Cast extends CompoundInstruction { /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.Cast_cast_3; + return InstructionsEvaluationMessages.Cast_cast_3; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/CompoundInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/CompoundInstruction.java index 5bff1461b..2b0c1f0fa 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/CompoundInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/CompoundInstruction.java @@ -11,25 +11,27 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; /** - * A <code>CompoundInstruction</code> is a container instruction - * and may have a size greater than one. + * A <code>CompoundInstruction</code> is a container instruction and may have a + * size greater than one. */ public abstract class CompoundInstruction extends Instruction { private int fSize; - + /** * Constructor for CompoundInstruction. + * * @param start */ protected CompoundInstruction(int start) { - fSize= -start; + fSize = -start; } public void setEnd(int end) { fSize += end; } + @Override public int getSize() { return fSize; } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ConditionalJump.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ConditionalJump.java index 9c431f416..255ae2f84 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ConditionalJump.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ConditionalJump.java @@ -15,17 +15,18 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; public class ConditionalJump extends Jump { private boolean fJumpOnTrue; - + public ConditionalJump(boolean jumpOnTrue) { - fJumpOnTrue= jumpOnTrue; + fJumpOnTrue = jumpOnTrue; } - + /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaPrimitiveValue condition= (IJavaPrimitiveValue)popValue(); - + IJavaPrimitiveValue condition = (IJavaPrimitiveValue) popValue(); + if (!(fJumpOnTrue ^ condition.getBooleanValue())) { jump(fOffset); } @@ -34,8 +35,9 @@ public class ConditionalJump extends Jump { /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.ConditionalJump_conditional_jump_1; + return InstructionsEvaluationMessages.ConditionalJump_conditional_jump_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Constructor.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Constructor.java index 3c0442e8f..6953b388e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Constructor.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Constructor.java @@ -10,41 +10,42 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.debug.core.IJavaClassType; import org.eclipse.jdt.debug.core.IJavaValue; /** - * Invokes a constructor. The arguments are on the - * stack in reverse order, followed by the type. - * Pushes the result onto the stack + * Invokes a constructor. The arguments are on the stack in reverse order, + * followed by the type. Pushes the result onto the stack */ public class Constructor extends CompoundInstruction { - + private int fArgCount; private String fSignature; - + public Constructor(String signature, int argCount, int start) { super(start); fArgCount = argCount; fSignature = signature; } - + + @Override public void execute() throws CoreException { IJavaValue[] args = new IJavaValue[fArgCount]; // args are in reverse order - for (int i= fArgCount - 1; i >= 0; i--) { + for (int i = fArgCount - 1; i >= 0; i--) { args[i] = popValue(); } - IJavaClassType clazz = (IJavaClassType)pop(); - IJavaValue result = clazz.newInstance(fSignature, args, getContext().getThread()); + IJavaClassType clazz = (IJavaClassType) pop(); + IJavaValue result = clazz.newInstance(fSignature, args, getContext() + .getThread()); push(result); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.Constructor_constructor__1 + fSignature; + return InstructionsEvaluationMessages.Constructor_constructor__1 + + fSignature; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideAssignmentOperator.java index 73db3170a..eaa2ed8ba 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class DivideAssignmentOperator extends DivideOperator { - public DivideAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public DivideAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.DivideAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.DivideAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideOperator.java index 9dc85f904..2d73c6a44 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DivideOperator.java @@ -18,42 +18,60 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; public class DivideOperator extends BinaryOperator { - public DivideOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public DivideOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected DivideOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected DivideOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() / ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() + / ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() / ((IJavaPrimitiveValue) rightOperand).getFloatValue(); + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() + / ((IJavaPrimitiveValue) rightOperand).getFloatValue(); } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ - protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { - int divisor= ((IJavaPrimitiveValue) rightOperand).getIntValue(); + @Override + protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) + throws CoreException { + int divisor = ((IJavaPrimitiveValue) rightOperand).getIntValue(); if (divisor == 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_1, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_1, + null)); } return ((IJavaPrimitiveValue) leftOperand).getIntValue() / divisor; } @@ -61,10 +79,18 @@ public class DivideOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ - protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { - long divisor= ((IJavaPrimitiveValue) rightOperand).getLongValue(); + @Override + protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) + throws CoreException { + long divisor = ((IJavaPrimitiveValue) rightOperand).getLongValue(); if (divisor == 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_2, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_2, + null)); } return ((IJavaPrimitiveValue) leftOperand).getLongValue() / divisor; } @@ -72,12 +98,15 @@ public class DivideOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.DivideOperator______operator_3; + return InstructionsEvaluationMessages.DivideOperator______operator_3; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Dup.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Dup.java index 3efeff7fb..55ba29ea0 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Dup.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Dup.java @@ -15,27 +15,30 @@ import org.eclipse.core.runtime.CoreException; /** * Duplicate the top element of the stack * - * Element - * ... + * Element ... * * -> * - * Element - * Element - * ... + * Element Element ... * */ public class Dup extends SimpleInstruction { - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute + * () */ + @Override public void execute() throws CoreException { - Object element= pop(); + Object element = pop(); push(element); push(element); } - + + @Override public String toString() { return "Dup"; //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DupX1.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DupX1.java index d08f1c849..67e628b2c 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DupX1.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/DupX1.java @@ -13,29 +13,29 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; import org.eclipse.core.runtime.CoreException; /** - * Duplicate the top element of the stack and put in it behind - * the second element of the stack. + * Duplicate the top element of the stack and put in it behind the second + * element of the stack. * - * Element1 - * Element2 - * ... + * Element1 Element2 ... * * -> * - * Element1 - * Element2 - * Element3 - * ... + * Element1 Element2 Element3 ... * */ public class DupX1 extends SimpleInstruction { - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute + * () */ + @Override public void execute() throws CoreException { - Object element1= pop(); - Object element2= pop(); + Object element1 = pop(); + Object element2 = pop(); push(element1); push(element2); push(element1); diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/EqualEqualOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/EqualEqualOperator.java index cb843eba6..ceae27e9e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/EqualEqualOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/EqualEqualOperator.java @@ -15,43 +15,51 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; public class EqualEqualOperator extends BinaryOperator { - + private boolean fIsEquals; - public EqualEqualOperator(int leftTypeId, int rightTypeId, boolean isEquals, int start) { + public EqualEqualOperator(int leftTypeId, int rightTypeId, + boolean isEquals, int start) { super(T_boolean, leftTypeId, rightTypeId, false, start); - fIsEquals= isEquals; + fIsEquals = isEquals; } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { - boolean equals= false; + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + boolean equals = false; switch (getInternResultType()) { - case T_double : - equals= ((IJavaPrimitiveValue) leftOperand).getDoubleValue() == ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); - break; - case T_float : - equals= ((IJavaPrimitiveValue) leftOperand).getFloatValue() == ((IJavaPrimitiveValue) rightOperand).getFloatValue(); - break; - case T_long : - equals= ((IJavaPrimitiveValue) leftOperand).getLongValue() == ((IJavaPrimitiveValue) rightOperand).getLongValue(); - break; - case T_int : - if (leftOperand instanceof IJavaObject) { - // enumerations in switch statement - equals = leftOperand.equals(rightOperand); - } else { - equals= ((IJavaPrimitiveValue) leftOperand).getIntValue() == ((IJavaPrimitiveValue) rightOperand).getIntValue(); - } - break; - case T_boolean : - equals= ((IJavaPrimitiveValue) leftOperand).getBooleanValue() == ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); - break; - default : - equals= leftOperand.equals(rightOperand); - break; + case T_double: + equals = ((IJavaPrimitiveValue) leftOperand).getDoubleValue() == ((IJavaPrimitiveValue) rightOperand) + .getDoubleValue(); + break; + case T_float: + equals = ((IJavaPrimitiveValue) leftOperand).getFloatValue() == ((IJavaPrimitiveValue) rightOperand) + .getFloatValue(); + break; + case T_long: + equals = ((IJavaPrimitiveValue) leftOperand).getLongValue() == ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + break; + case T_int: + if (leftOperand instanceof IJavaObject) { + // enumerations in switch statement + equals = leftOperand.equals(rightOperand); + } else { + equals = ((IJavaPrimitiveValue) leftOperand).getIntValue() == ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + } + break; + case T_boolean: + equals = ((IJavaPrimitiveValue) leftOperand).getBooleanValue() == ((IJavaPrimitiveValue) rightOperand) + .getBooleanValue(); + break; + default: + equals = leftOperand.equals(rightOperand); + break; } return ((fIsEquals) ? equals : !equals); } @@ -59,20 +67,25 @@ public class EqualEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -80,6 +93,7 @@ public class EqualEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -87,12 +101,15 @@ public class EqualEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.EqualEqualOperator_operator_1; + return InstructionsEvaluationMessages.EqualEqualOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterEqualOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterEqualOperator.java index 98e26f511..15299b7d9 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterEqualOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterEqualOperator.java @@ -21,38 +21,49 @@ public class GreaterEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { switch (getInternResultType()) { - case T_double : - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() >= ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); - case T_float : - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() >= ((IJavaPrimitiveValue) rightOperand).getFloatValue(); - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() >= ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() >= ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return false; + case T_double: + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() >= ((IJavaPrimitiveValue) rightOperand) + .getDoubleValue(); + case T_float: + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() >= ((IJavaPrimitiveValue) rightOperand) + .getFloatValue(); + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() >= ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() >= ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return false; } } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -60,6 +71,7 @@ public class GreaterEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -67,12 +79,15 @@ public class GreaterEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.GreaterEqualOperator_operator_1; + return InstructionsEvaluationMessages.GreaterEqualOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterOperator.java index 8e71c8495..0b3926cf2 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/GreaterOperator.java @@ -21,38 +21,49 @@ public class GreaterOperator extends BinaryOperator { /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { switch (getInternResultType()) { - case T_double : - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() > ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); - case T_float : - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() > ((IJavaPrimitiveValue) rightOperand).getFloatValue(); - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() > ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() > ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return false; + case T_double: + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() > ((IJavaPrimitiveValue) rightOperand) + .getDoubleValue(); + case T_float: + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() > ((IJavaPrimitiveValue) rightOperand) + .getFloatValue(); + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() > ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() > ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return false; } } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -60,6 +71,7 @@ public class GreaterOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -67,12 +79,15 @@ public class GreaterOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.GreaterOperator______operator_1; + return InstructionsEvaluationMessages.GreaterOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstanceOfOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstanceOfOperator.java index d766fd5f7..341602248 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstanceOfOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstanceOfOperator.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -21,35 +19,48 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.core.model.JDINullValue; +import com.ibm.icu.text.MessageFormat; + public class InstanceOfOperator extends CompoundInstruction { - public static final String IS_INSTANCE= "isInstance"; //$NON-NLS-1$ - public static final String IS_INSTANCE_SIGNATURE= "(Ljava/lang/Object;)Z"; //$NON-NLS-1$ - + public static final String IS_INSTANCE = "isInstance"; //$NON-NLS-1$ + public static final String IS_INSTANCE_SIGNATURE = "(Ljava/lang/Object;)Z"; //$NON-NLS-1$ + public InstanceOfOperator(int start) { super(start); } - + /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaType type= (IJavaType)pop(); - IJavaValue value= popValue(); + IJavaType type = (IJavaType) pop(); + IJavaValue value = popValue(); if (value instanceof JDINullValue) { pushNewValue(false); return; } - IJavaObject object= (IJavaObject)value; + IJavaObject object = (IJavaObject) value; - IJavaObject classObject= getClassObject(type); + IJavaObject classObject = getClassObject(type); if (classObject == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.InstanceOfOperator_No_class_object, new String[]{type.getName()}), null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.InstanceOfOperator_No_class_object, + new String[] { type.getName() }), + null)); } - push(classObject.sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE, new IJavaValue[] {object}, getContext().getThread(), false)); + push(classObject.sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE, + new IJavaValue[] { object }, getContext().getThread(), false)); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.InstanceOfOperator__instanceof___operator_3; + return InstructionsEvaluationMessages.InstanceOfOperator__instanceof___operator_3; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java index efc9009c5..40f0e118d 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -40,7 +39,7 @@ public abstract class Instruction { public abstract int getSize(); public void setInterpreter(Interpreter interpreter) { - fInterpreter= interpreter; + fInterpreter = interpreter; } public void setLastValue(IJavaValue value) { @@ -54,6 +53,7 @@ public abstract class Instruction { public static int getBinaryPromotionType(int left, int right) { return fTypeTable[left][right]; } + public abstract void execute() throws CoreException; protected IRuntimeContext getContext() { @@ -66,7 +66,7 @@ public abstract class Instruction { /** * Return the internal variable with the given name. - * + * * @see Interpreter#getInternalVariable(String) */ protected IVariable getInternalVariable(String name) { @@ -74,22 +74,22 @@ public abstract class Instruction { } /** - * Create and return a new internal variable with the given name - * and the given type. - * + * Create and return a new internal variable with the given name and the + * given type. + * * @see Interpreter#createInternalVariable(String, String) */ - protected IVariable createInternalVariable(String name, IJavaType referencType) { + protected IVariable createInternalVariable(String name, + IJavaType referencType) { return fInterpreter.createInternalVariable(name, referencType); } - /** * Answers the instance of Class that the given type represents. */ protected IJavaObject getClassObject(IJavaType type) throws CoreException { if (type instanceof IJavaReferenceType) { - return ((IJavaReferenceType)type).getClassObject(); + return ((IJavaReferenceType) type).getClassObject(); } return null; } @@ -109,9 +109,9 @@ public abstract class Instruction { protected IJavaValue popValue() throws CoreException { Object element = fInterpreter.pop(); if (element instanceof IJavaVariable) { - return (IJavaValue)((IJavaVariable)element).getValue(); + return (IJavaValue) ((IJavaVariable) element).getValue(); } - return (IJavaValue)element; + return (IJavaValue) element; } protected void pushNewValue(boolean value) { @@ -198,54 +198,65 @@ public abstract class Instruction { return fTypeTable[typeId][T_int]; } - protected IJavaType getType(String qualifiedName) throws CoreException { - // Force the class to be loaded, and record the class reference - // for later use if there are multiple classes with the same name. - IJavaClassObject classReference= getContext().classForName(qualifiedName); - // Found many classes, look for the right one for this scope. - if (classReference == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{qualifiedName}), null)); - } - return classReference.getInstanceType(); - } - - /** - * Returns the primitive type with the given name. - * - * @param name type name, for example - "int" - * @return primitive type - * @throws CoreException - */ - protected IJavaType getPrimitiveType(String name) throws CoreException { - IJavaReferenceType type = null; - if ("boolean".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Boolean"); //$NON-NLS-1$ - } else if ("byte".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Byte"); //$NON-NLS-1$ - } else if ("char".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Character"); //$NON-NLS-1$ - } else if ("double".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Double"); //$NON-NLS-1$ - } else if ("float".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Float"); //$NON-NLS-1$ - } else if ("int".equals(name)) { //$NON-NLS-1$ + protected IJavaType getType(String qualifiedName) throws CoreException { + // Force the class to be loaded, and record the class reference + // for later use if there are multiple classes with the same name. + IJavaClassObject classReference = getContext().classForName( + qualifiedName); + // Found many classes, look for the right one for this scope. + if (classReference == null) { + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + MessageFormat.format( + InstructionsEvaluationMessages.Instruction_No_type, + new String[] { qualifiedName }), null)); + } + return classReference.getInstanceType(); + } + + /** + * Returns the primitive type with the given name. + * + * @param name + * type name, for example - "int" + * @return primitive type + * @throws CoreException + */ + protected IJavaType getPrimitiveType(String name) throws CoreException { + IJavaReferenceType type = null; + if ("boolean".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Boolean"); //$NON-NLS-1$ + } else if ("byte".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Byte"); //$NON-NLS-1$ + } else if ("char".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Character"); //$NON-NLS-1$ + } else if ("double".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Double"); //$NON-NLS-1$ + } else if ("float".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Float"); //$NON-NLS-1$ + } else if ("int".equals(name)) { //$NON-NLS-1$ type = (IJavaReferenceType) getType("java.lang.Integer"); //$NON-NLS-1$ } else if ("long".equals(name)) { //$NON-NLS-1$ type = (IJavaReferenceType) getType("java.lang.Long"); //$NON-NLS-1$ } else if ("short".equals(name)) { //$NON-NLS-1$ type = (IJavaReferenceType) getType("java.lang.Short"); //$NON-NLS-1$ - } else if ("void".equals(name)) { //$NON-NLS-1$ - type = (IJavaReferenceType) getType("java.lang.Void"); //$NON-NLS-1$ - } - if (type != null) { - IJavaFieldVariable field = type.getField("TYPE"); //$NON-NLS-1$ + } else if ("void".equals(name)) { //$NON-NLS-1$ + type = (IJavaReferenceType) getType("java.lang.Void"); //$NON-NLS-1$ + } + if (type != null) { + IJavaFieldVariable field = type.getField("TYPE"); //$NON-NLS-1$ IJavaClassObject clazz = (IJavaClassObject) field.getValue(); return clazz.getInstanceType(); - } - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{name}), null)); - } + } + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + MessageFormat.format( + InstructionsEvaluationMessages.Instruction_No_type, + new String[] { name }), null)); + } - protected IJavaArrayType getArrayType(String typeSignature, int dimension) throws CoreException { + protected IJavaArrayType getArrayType(String typeSignature, int dimension) + throws CoreException { String qualifiedName = RuntimeSignature.toString(typeSignature); String braces = ""; //$NON-NLS-1$ for (int i = 0; i < dimension; i++) { @@ -255,21 +266,24 @@ public abstract class Instruction { String signature = braces + typeSignature; // Force the class to be loaded, and record the class reference // for later use if there are multiple classes with the same name. - IJavaObject classReference= getContext().classForName(signature); + IJavaObject classReference = getContext().classForName(signature); if (classReference == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{qualifiedName}), null)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + MessageFormat.format( + InstructionsEvaluationMessages.Instruction_No_type, + new String[] { qualifiedName }), null)); } - IJavaType[] types= getVM().getJavaTypes(qualifiedName); + IJavaType[] types = getVM().getJavaTypes(qualifiedName); checkTypes(types, qualifiedName); if (types.length == 1) { // Found only one class. - return (IJavaArrayType)types[0]; + return (IJavaArrayType) types[0]; } // Found many classes, look for the right one for this scope. - for(int i= 0, length= types.length; i < length; i++) { - IJavaType type= types[i]; + for (IJavaType type : types) { if (classReference.equals(getClassObject(type))) { - return (IJavaArrayType)type; + return (IJavaArrayType) type; } } @@ -278,43 +292,81 @@ public abstract class Instruction { // call, but none of them were the class that was returned in // the classForName call. - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{qualifiedName}), null)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + MessageFormat.format( + InstructionsEvaluationMessages.Instruction_No_type, + new String[] { qualifiedName }), null)); } - protected void checkTypes(IJavaType[] types, String qualifiedName) throws CoreException { + protected void checkTypes(IJavaType[] types, String qualifiedName) + throws CoreException { if (types == null || types.length == 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String[]{qualifiedName}), null)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + MessageFormat.format( + InstructionsEvaluationMessages.Instruction_No_type, + new String[] { qualifiedName }), null)); } } - static public final int T_undefined =0; - static public final int T_Object =1; - static public final int T_char =2; - static public final int T_byte =3; - static public final int T_short =4; - static public final int T_boolean =5; - static public final int T_void =6; - static public final int T_long =7; - static public final int T_double =8; - static public final int T_float =9; - static public final int T_int =10; - static public final int T_String =11; - static public final int T_null =12; - - private static final int[][] fTypeTable= { -/* undefined */ {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined}, -/* object */ {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, -/* char */ {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, -/* byte */ {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, -/* short */ {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, -/* boolean */ {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_boolean, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, -/* void */ {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined}, -/* long */ {T_undefined, T_undefined, T_long, T_long, T_long, T_undefined, T_undefined, T_long, T_double, T_float, T_long, T_String, T_undefined}, -/* double */ {T_undefined, T_undefined, T_double, T_double, T_double, T_undefined, T_undefined, T_double, T_double, T_double, T_double, T_String, T_undefined}, -/* float */ {T_undefined, T_undefined, T_float, T_float, T_float, T_undefined, T_undefined, T_float, T_double, T_float, T_float, T_String, T_undefined}, -/* int */ {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, -/* String */ {T_undefined, T_String, T_String, T_String, T_String, T_String, T_undefined, T_String, T_String, T_String, T_String, T_String, T_String}, -/* null */ {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, - }; + static public final int T_undefined = 0; + static public final int T_Object = 1; + static public final int T_char = 2; + static public final int T_byte = 3; + static public final int T_short = 4; + static public final int T_boolean = 5; + static public final int T_void = 6; + static public final int T_long = 7; + static public final int T_double = 8; + static public final int T_float = 9; + static public final int T_int = 10; + static public final int T_String = 11; + static public final int T_null = 12; + + private static final int[][] fTypeTable = { + /* undefined */{ T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined }, + /* object */{ T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_String, + T_undefined }, + /* char */{ T_undefined, T_undefined, T_int, T_int, T_int, + T_undefined, T_undefined, T_long, T_double, T_float, T_int, + T_String, T_undefined }, + /* byte */{ T_undefined, T_undefined, T_int, T_int, T_int, + T_undefined, T_undefined, T_long, T_double, T_float, T_int, + T_String, T_undefined }, + /* short */{ T_undefined, T_undefined, T_int, T_int, T_int, + T_undefined, T_undefined, T_long, T_double, T_float, T_int, + T_String, T_undefined }, + /* boolean */{ T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_boolean, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_String, + T_undefined }, + /* void */{ T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined }, + /* long */{ T_undefined, T_undefined, T_long, T_long, T_long, + T_undefined, T_undefined, T_long, T_double, T_float, + T_long, T_String, T_undefined }, + /* double */{ T_undefined, T_undefined, T_double, T_double, + T_double, T_undefined, T_undefined, T_double, T_double, + T_double, T_double, T_String, T_undefined }, + /* float */{ T_undefined, T_undefined, T_float, T_float, T_float, + T_undefined, T_undefined, T_float, T_double, T_float, + T_float, T_String, T_undefined }, + /* int */{ T_undefined, T_undefined, T_int, T_int, T_int, + T_undefined, T_undefined, T_long, T_double, T_float, T_int, + T_String, T_undefined }, + /* String */{ T_undefined, T_String, T_String, T_String, T_String, + T_String, T_undefined, T_String, T_String, T_String, + T_String, T_String, T_String }, + /* null */{ T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_undefined, + T_undefined, T_undefined, T_undefined, T_String, + T_undefined }, }; } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionSequence.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionSequence.java index 036cef283..d6ae7c0a5 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionSequence.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionSequence.java @@ -20,97 +20,98 @@ import org.eclipse.jdt.debug.eval.ICompiledExpression; public class InstructionSequence implements ICompiledExpression { - private List fInstructions; + private List<Instruction> fInstructions; /** * A collection of error messages (<code>String</code>) that occurred while * creating this expression */ - private List fErrors; + private List<String> fErrors; private String fSnippet; private CoreException fException; - + public InstructionSequence(String snippet) { - fInstructions= new ArrayList(10); - fErrors= new ArrayList(); - fSnippet= snippet; + fInstructions = new ArrayList<Instruction>(10); + fErrors = new ArrayList<String>(); + fSnippet = snippet; } - + /** - * Returns the runtime exception that occurred while evaluating this expression - * or <code>null</code> if no exception occurred. + * Returns the runtime exception that occurred while evaluating this + * expression or <code>null</code> if no exception occurred. */ public CoreException getException() { return fException; } - + /** * @see ICompiledExpression#getSnippet() */ public String getSnippet() { return fSnippet; } - + /** - * Adds the given error to the list of errors that occurred - * while compiling this instruction sequence + * Adds the given error to the list of errors that occurred while compiling + * this instruction sequence */ public void addError(String error) { fErrors.add(error); } - + /** * @see ICompiledExpression#hasErrors() */ public boolean hasErrors() { return !fErrors.isEmpty(); } - + /** * @see ICompiledExpression#getErrors() * @deprecated */ + @Deprecated public Message[] getErrors() { - Message[] messages= new Message[fErrors.size()]; - int i= 0; - for (Iterator iter= fErrors.iterator(); iter.hasNext();) { - messages[i++]= new Message((String) iter.next(), -1); + Message[] messages = new Message[fErrors.size()]; + int i = 0; + for (Iterator<String> iter = fErrors.iterator(); iter.hasNext();) { + messages[i++] = new Message(iter.next(), -1); } return messages; } - + /** * @see org.eclipse.jdt.debug.eval.ICompiledExpression#getErrorMessages() */ public String[] getErrorMessages() { - return (String[])fErrors.toArray(new String[fErrors.size()]); + return fErrors.toArray(new String[fErrors.size()]); } /** * Answers the array of instructions, or an empty array. */ public Instruction[] getInstructions() { - int size= fInstructions.size(); - Instruction[] instructions= new Instruction[size]; + int size = fInstructions.size(); + Instruction[] instructions = new Instruction[size]; if (size > 0) { fInstructions.toArray(instructions); } return instructions; } - + /** * Answer the instruction at the given address */ public Instruction getInstruction(int address) { - return (Instruction)fInstructions.get(address); + return fInstructions.get(address); } - + /** * Add the given instruction to the end of the list */ public void add(Instruction instruction) { fInstructions.add(instruction); } - + public int indexOf(Instruction instruction) { return fInstructions.indexOf(instruction); } @@ -123,21 +124,20 @@ public class InstructionSequence implements ICompiledExpression { } /** - * Inserts the instruction at the given index. If - * the index is less than 0 or greater than the current - * instruction count, the instruction is added at the end - * of the sequence. + * Inserts the instruction at the given index. If the index is less than 0 + * or greater than the current instruction count, the instruction is added + * at the end of the sequence. * * Instructs the instructions to update their program counters. */ public void insert(Instruction instruction, int index) { fInstructions.add(index, instruction); } - + public Instruction get(int address) { - return (Instruction)fInstructions.get(address); + return fInstructions.get(address); } - + public int getEnd() { return fInstructions.size() - 1; } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionsEvaluationMessages.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionsEvaluationMessages.java index e1e3c9cbb..b54f0fc44 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionsEvaluationMessages.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/InstructionsEvaluationMessages.java @@ -102,6 +102,7 @@ public class InstructionsEvaluationMessages extends NLS { static { // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, InstructionsEvaluationMessages.class); + NLS.initializeMessages(BUNDLE_NAME, + InstructionsEvaluationMessages.class); } }
\ No newline at end of file diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Jump.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Jump.java index f4048793c..a82f6256b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Jump.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Jump.java @@ -14,14 +14,15 @@ import org.eclipse.core.runtime.CoreException; public class Jump extends SimpleInstruction { protected int fOffset; - + public void setOffset(int offset) { - fOffset= offset; + fOffset = offset; } /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { jump(fOffset); } @@ -29,8 +30,9 @@ public class Jump extends SimpleInstruction { /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.Jump_jump_1; + return InstructionsEvaluationMessages.Jump_jump_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftAssignmentOperator.java index 27795e4b1..2ccd88d2a 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class LeftShiftAssignmentOperator extends LeftShiftOperator { - public LeftShiftAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public LeftShiftAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.LeftShiftAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.LeftShiftAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftOperator.java index 7fafbcc58..c47f09eb4 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LeftShiftOperator.java @@ -14,85 +14,103 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; public class LeftShiftOperator extends BinaryOperator { - public LeftShiftOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public LeftShiftOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected LeftShiftOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected LeftShiftOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() << ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() << ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() << ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() << ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() << ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() << ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() << ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() << ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override protected int getInternResultType() { // unary type promotion on both operands see 5.6.1 and 15.18 return getUnaryPromotionType(fLeftTypeId); } + @Override public String toString() { - return InstructionsEvaluationMessages.LeftShiftOperator_______operator_1; + return InstructionsEvaluationMessages.LeftShiftOperator_______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessEqualOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessEqualOperator.java index b4d2e7b4b..a61bda778 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessEqualOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessEqualOperator.java @@ -21,38 +21,49 @@ public class LessEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { switch (getInternResultType()) { - case T_double : - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() <= ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); - case T_float : - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() <= ((IJavaPrimitiveValue) rightOperand).getFloatValue(); - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() <= ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() <= ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return false; + case T_double: + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() <= ((IJavaPrimitiveValue) rightOperand) + .getDoubleValue(); + case T_float: + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() <= ((IJavaPrimitiveValue) rightOperand) + .getFloatValue(); + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() <= ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() <= ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return false; } } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -60,6 +71,7 @@ public class LessEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -67,11 +79,15 @@ public class LessEqualOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + + @Override public String toString() { - return InstructionsEvaluationMessages.LessEqualOperator_operator_1; + return InstructionsEvaluationMessages.LessEqualOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessOperator.java index 44a2c30f1..f77aeda4e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LessOperator.java @@ -21,38 +21,49 @@ public class LessOperator extends BinaryOperator { /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { switch (getInternResultType()) { - case T_double : - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() < ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); - case T_float : - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() < ((IJavaPrimitiveValue) rightOperand).getFloatValue(); - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() < ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() < ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return false; + case T_double: + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() < ((IJavaPrimitiveValue) rightOperand) + .getDoubleValue(); + case T_float: + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() < ((IJavaPrimitiveValue) rightOperand) + .getFloatValue(); + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() < ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() < ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return false; } } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -60,6 +71,7 @@ public class LessOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { return 0; } @@ -67,12 +79,15 @@ public class LessOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.LessOperator______operator_1; + return InstructionsEvaluationMessages.LessOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LocalVariableCreation.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LocalVariableCreation.java index c2850aaa8..39119ae6f 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LocalVariableCreation.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/LocalVariableCreation.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.model.IVariable; import org.eclipse.jdi.internal.PrimitiveTypeImpl; @@ -21,6 +18,7 @@ import org.eclipse.jdt.debug.core.IJavaType; import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; import org.eclipse.jdt.internal.debug.core.model.JDIType; +import com.ibm.icu.text.MessageFormat; import com.sun.jdi.VirtualMachine; public class LocalVariableCreation extends CompoundInstruction { @@ -34,17 +32,18 @@ public class LocalVariableCreation extends CompoundInstruction { * The name of the variable to create. */ private String fName; - + /** - * The signature of the type, or of the element type in case of an array type. + * The signature of the type, or of the element type in case of an array + * type. */ private String fTypeSignature; - + /** * The dimension of the array type. */ private int fDimension; - + /** * Indicate if there is an initializer for this variable. */ @@ -53,46 +52,65 @@ public class LocalVariableCreation extends CompoundInstruction { /** * Constructor for LocalVariableCreation. * - * @param name the name of the variable to create. - * @param typeSignature the signature of the type, or of the element type in case of an array type. - * @param dimension the dimension of the array type, <code>0</code> if it's not an array type. - * @param isPrimitiveType indicate if the type is a primitive type. - * @param hasInitializer indicate if there is an initializer for this variable. + * @param name + * the name of the variable to create. + * @param typeSignature + * the signature of the type, or of the element type in case of + * an array type. + * @param dimension + * the dimension of the array type, <code>0</code> if it's not an + * array type. + * @param isPrimitiveType + * indicate if the type is a primitive type. + * @param hasInitializer + * indicate if there is an initializer for this variable. * @param start */ - public LocalVariableCreation(String name, String typeSignature, int dimension, boolean isPrimitiveType, boolean hasInitializer, int start) { + public LocalVariableCreation(String name, String typeSignature, + int dimension, boolean isPrimitiveType, boolean hasInitializer, + int start) { super(start); - fName= name; - fTypeSignature= typeSignature.replace('/', '.'); - fIsPrimitiveType= isPrimitiveType; - fHasInitializer= hasInitializer; - fDimension= dimension; + fName = name; + fTypeSignature = typeSignature.replace('/', '.'); + fIsPrimitiveType = isPrimitiveType; + fHasInitializer = hasInitializer; + fDimension = dimension; } /** * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaType type; if (fIsPrimitiveType) { - JDIDebugTarget debugTarget= (JDIDebugTarget)getVM(); + JDIDebugTarget debugTarget = (JDIDebugTarget) getVM(); VirtualMachine vm = debugTarget.getVM(); if (vm == null) { - debugTarget.requestFailed(InstructionsEvaluationMessages.LocalVariableCreation_Execution_failed___VM_disconnected__1, null); - } - type= JDIType.createType(debugTarget, PrimitiveTypeImpl.create((VirtualMachineImpl)vm, fTypeSignature)); + debugTarget + .requestFailed( + InstructionsEvaluationMessages.LocalVariableCreation_Execution_failed___VM_disconnected__1, + null); + } + type = JDIType.createType(debugTarget, PrimitiveTypeImpl.create( + (VirtualMachineImpl) vm, fTypeSignature)); } else if (fDimension == 0) { - type= getType(RuntimeSignature.toString(fTypeSignature)); // See Bug 22165 + type = getType(RuntimeSignature.toString(fTypeSignature)); // See + // Bug + // 22165 } else { - type= getArrayType(fTypeSignature, fDimension); + type = getArrayType(fTypeSignature, fDimension); } - IVariable var= createInternalVariable(fName, type); + IVariable var = createInternalVariable(fName, type); if (fHasInitializer) { var.setValue(popValue()); } } + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.LocalVariableCreation_create_local_variable__0___1___1, new String[]{fName, fTypeSignature}); + return MessageFormat + .format(InstructionsEvaluationMessages.LocalVariableCreation_create_local_variable__0___1___1, + new String[] { fName, fTypeSignature }); } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusAssignmentOperator.java index a65e1dbd8..2bd4f2c73 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class MinusAssignmentOperator extends MinusOperator { - public MinusAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public MinusAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.MinusAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.MinusAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusOperator.java index 1b1cccd37..d487b3193 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MinusOperator.java @@ -15,58 +15,75 @@ import org.eclipse.jdt.debug.core.IJavaValue; public class MinusOperator extends BinaryOperator { - public MinusOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public MinusOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected MinusOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected MinusOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() - ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() + - ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() - ((IJavaPrimitiveValue) rightOperand).getFloatValue(); + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() + - ((IJavaPrimitiveValue) rightOperand).getFloatValue(); } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getIntValue() - ((IJavaPrimitiveValue) rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + - ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getLongValue() - ((IJavaPrimitiveValue) rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + - ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.MinusOperator______operator_1; + return InstructionsEvaluationMessages.MinusOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyAssignmentOperator.java index 8c7f7b557..d1fc3565f 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class MultiplyAssignmentOperator extends MultiplyOperator { - public MultiplyAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public MultiplyAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.MultiplyAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.MultiplyAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyOperator.java index 16abe675e..e4b73e248 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/MultiplyOperator.java @@ -14,58 +14,75 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; public class MultiplyOperator extends BinaryOperator { - public MultiplyOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public MultiplyOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected MultiplyOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected MultiplyOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() * ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() + * ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() * ((IJavaPrimitiveValue) rightOperand).getFloatValue(); + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() + * ((IJavaPrimitiveValue) rightOperand).getFloatValue(); } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getIntValue() * ((IJavaPrimitiveValue) rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + * ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getLongValue() * ((IJavaPrimitiveValue) rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + * ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.MultiplyOperator______operator_1; + return InstructionsEvaluationMessages.MultiplyOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NoOp.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NoOp.java index bde25c7cf..5b1335a73 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NoOp.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NoOp.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - public class NoOp extends CompoundInstruction { public NoOp(int start) { @@ -20,14 +19,16 @@ public class NoOp extends CompoundInstruction { /* * @see Instruction#execute() */ + @Override public void execute() { } - + /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.NoOp_no_op_1; + return InstructionsEvaluationMessages.NoOp_no_op_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NotOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NotOperator.java index 5b4d1b023..84cc44281 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NotOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/NotOperator.java @@ -22,13 +22,15 @@ public class NotOperator extends UnaryOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaPrimitiveValue value= (IJavaPrimitiveValue)popValue(); + IJavaPrimitiveValue value = (IJavaPrimitiveValue) popValue(); pushNewValue(!value.getBooleanValue()); } + @Override public String toString() { - return InstructionsEvaluationMessages.NotOperator______operator_1; + return InstructionsEvaluationMessages.NotOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrAssignmentOperator.java index ea40cd62c..b3a20aa0d 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrAssignmentOperator.java @@ -16,8 +16,9 @@ public class OrAssignmentOperator extends OrOperator { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.OrAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.OrAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrOperator.java index 71f5b7e06..864b656e5 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/OrOperator.java @@ -13,60 +13,74 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; - public class OrOperator extends BinaryOperator { public OrOperator(int resultId, int leftTypeId, int rightTypeId, int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected OrOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected OrOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() | ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() + | ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getIntValue() | ((IJavaPrimitiveValue) rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + | ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getLongValue() | ((IJavaPrimitiveValue) rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + | ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.OrOperator______operator_1; + return InstructionsEvaluationMessages.OrOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusAssignmentOperator.java index 44914d391..6fe49b1f0 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusAssignmentOperator.java @@ -16,8 +16,9 @@ public class PlusAssignmentOperator extends PlusOperator { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.PlusAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.PlusAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusOperator.java index 3760d8660..13aa93351 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PlusOperator.java @@ -19,98 +19,118 @@ import org.eclipse.jdt.internal.debug.core.model.JDINullValue; public class PlusOperator extends BinaryOperator { - public static final String NULL= "null"; //$NON-NLS-1$ - public static final String TOSTRING_SELECTOR= "toString"; //$NON-NLS-1$ - public static final String TOSTRING_SIGNATURE= "()Ljava/lang/String;"; //$NON-NLS-1$ + public static final String NULL = "null"; //$NON-NLS-1$ + public static final String TOSTRING_SELECTOR = "toString"; //$NON-NLS-1$ + public static final String TOSTRING_SIGNATURE = "()Ljava/lang/String;"; //$NON-NLS-1$ public PlusOperator(int resultId, int leftTypeId, int rightTypeId, int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - - protected PlusOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + + protected PlusOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } - - private String getString(IJavaValue value, int typeId) throws DebugException { - + + private String getString(IJavaValue value, int typeId) + throws DebugException { + // test if value == null if (value instanceof JDINullValue) { return NULL; } - + if (value instanceof IJavaObject) { if (typeId == T_String) { return value.getValueString(); } - return ((IJavaObject) value).sendMessage(TOSTRING_SELECTOR, TOSTRING_SIGNATURE, null, getContext().getThread(), null).getValueString(); + return ((IJavaObject) value).sendMessage(TOSTRING_SELECTOR, + TOSTRING_SIGNATURE, null, getContext().getThread(), null) + .getValueString(); } - - IJavaPrimitiveValue primitiveValue= (IJavaPrimitiveValue)value; + + IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value; switch (typeId) { - case T_boolean: - return Boolean.valueOf(primitiveValue.getBooleanValue()).toString(); - case T_byte: - return new Integer(primitiveValue.getByteValue()).toString(); - case T_char: - return new Character(primitiveValue.getCharValue()).toString(); - case T_double: - return new Double(primitiveValue.getDoubleValue()).toString(); - case T_float: - return new Float(primitiveValue.getFloatValue()).toString(); - case T_int: - return new Integer(primitiveValue.getIntValue()).toString(); - case T_long: - return new Long(primitiveValue.getLongValue()).toString(); - case T_short: - return new Integer(primitiveValue.getShortValue()).toString(); + case T_boolean: + return Boolean.valueOf(primitiveValue.getBooleanValue()).toString(); + case T_byte: + return new Integer(primitiveValue.getByteValue()).toString(); + case T_char: + return new Character(primitiveValue.getCharValue()).toString(); + case T_double: + return new Double(primitiveValue.getDoubleValue()).toString(); + case T_float: + return new Float(primitiveValue.getFloatValue()).toString(); + case T_int: + return new Integer(primitiveValue.getIntValue()).toString(); + case T_long: + return new Long(primitiveValue.getLongValue()).toString(); + case T_short: + return new Integer(primitiveValue.getShortValue()).toString(); } return NULL; - } - + } + /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue)leftOperand).getDoubleValue() + ((IJavaPrimitiveValue)rightOperand).getDoubleValue(); + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() + + ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue)leftOperand).getFloatValue() + ((IJavaPrimitiveValue)rightOperand).getFloatValue(); + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() + + ((IJavaPrimitiveValue) rightOperand).getFloatValue(); } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue)leftOperand).getIntValue() + ((IJavaPrimitiveValue)rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + + ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue)leftOperand).getLongValue() + ((IJavaPrimitiveValue)rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + + ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { - return getString(leftOperand, fLeftTypeId) + getString(rightOperand, fRightTypeId); + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) throws CoreException { + return getString(leftOperand, fLeftTypeId) + + getString(rightOperand, fRightTypeId); } + @Override public String toString() { - return InstructionsEvaluationMessages.PlusOperator______operator_2; + return InstructionsEvaluationMessages.PlusOperator______operator_2; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Pop.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Pop.java index 54596fbea..0720098ef 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Pop.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Pop.java @@ -10,21 +10,21 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - public class Pop extends Instruction { private int fSize; - + /** * @param start */ public Pop(int size) { - fSize= size; + fSize = size; } /* * @see Instruction#execute() */ + @Override public void execute() { pop(); } @@ -32,13 +32,19 @@ public class Pop extends Instruction { /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.Pop_pop_1; + return InstructionsEvaluationMessages.Pop_pop_1; } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#getSize() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#getSize + * () */ + @Override public int getSize() { return fSize; } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixMinusMinusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixMinusMinusOperator.java index f5eb03268..ff1d5d123 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixMinusMinusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixMinusMinusOperator.java @@ -15,7 +15,7 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaVariable; public class PostfixMinusMinusOperator extends XfixOperator { - + public PostfixMinusMinusOperator(int variableTypeId, int start) { super(variableTypeId, start); } @@ -23,37 +23,46 @@ public class PostfixMinusMinusOperator extends XfixOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaVariable variable = (IJavaVariable) pop(); push(variable.getValue()); - + switch (fVariableTypeId) { - case T_byte : - variable.setValue(newValue((byte)(((IJavaPrimitiveValue)variable.getValue()).getByteValue() - 1))); - break; - case T_short : - variable.setValue(newValue((short)(((IJavaPrimitiveValue)variable.getValue()).getShortValue() - 1))); - break; - case T_char : - variable.setValue(newValue((char)(((IJavaPrimitiveValue)variable.getValue()).getCharValue() - 1))); - break; - case T_int : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getIntValue() - 1)); - break; - case T_long : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getLongValue() - 1)); - break; - case T_float : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getFloatValue() - 1)); - break; - case T_double : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getDoubleValue() - 1)); - break; + case T_byte: + variable.setValue(newValue((byte) (((IJavaPrimitiveValue) variable + .getValue()).getByteValue() - 1))); + break; + case T_short: + variable.setValue(newValue((short) (((IJavaPrimitiveValue) variable + .getValue()).getShortValue() - 1))); + break; + case T_char: + variable.setValue(newValue((char) (((IJavaPrimitiveValue) variable + .getValue()).getCharValue() - 1))); + break; + case T_int: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getIntValue() - 1)); + break; + case T_long: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getLongValue() - 1)); + break; + case T_float: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getFloatValue() - 1)); + break; + case T_double: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getDoubleValue() - 1)); + break; } } + @Override public String toString() { - return InstructionsEvaluationMessages.PostfixMinusMinusOperator_postfix________operator_1; + return InstructionsEvaluationMessages.PostfixMinusMinusOperator_postfix________operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixPlusPlusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixPlusPlusOperator.java index af952d03a..515b6ab01 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixPlusPlusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PostfixPlusPlusOperator.java @@ -15,7 +15,7 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaVariable; public class PostfixPlusPlusOperator extends XfixOperator { - + public PostfixPlusPlusOperator(int variableTypeId, int start) { super(variableTypeId, start); } @@ -23,37 +23,46 @@ public class PostfixPlusPlusOperator extends XfixOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaVariable variable = (IJavaVariable) pop(); push(variable.getValue()); - + switch (fVariableTypeId) { - case T_byte : - variable.setValue(newValue((byte)(((IJavaPrimitiveValue)variable.getValue()).getByteValue() + 1))); - break; - case T_short : - variable.setValue(newValue((short)(((IJavaPrimitiveValue)variable.getValue()).getShortValue() + 1))); - break; - case T_char : - variable.setValue(newValue((char)(((IJavaPrimitiveValue)variable.getValue()).getCharValue() + 1))); - break; - case T_int : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getIntValue() + 1)); - break; - case T_long : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getLongValue() + 1)); - break; - case T_float : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getFloatValue() + 1)); - break; - case T_double : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getDoubleValue() + 1)); - break; + case T_byte: + variable.setValue(newValue((byte) (((IJavaPrimitiveValue) variable + .getValue()).getByteValue() + 1))); + break; + case T_short: + variable.setValue(newValue((short) (((IJavaPrimitiveValue) variable + .getValue()).getShortValue() + 1))); + break; + case T_char: + variable.setValue(newValue((char) (((IJavaPrimitiveValue) variable + .getValue()).getCharValue() + 1))); + break; + case T_int: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getIntValue() + 1)); + break; + case T_long: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getLongValue() + 1)); + break; + case T_float: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getFloatValue() + 1)); + break; + case T_double: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getDoubleValue() + 1)); + break; } } + @Override public String toString() { - return InstructionsEvaluationMessages.PostfixPlusPlusOperator_postfix________operator_1; + return InstructionsEvaluationMessages.PostfixPlusPlusOperator_postfix________operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixMinusMinusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixMinusMinusOperator.java index ea02f73b9..1a9099aeb 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixMinusMinusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixMinusMinusOperator.java @@ -15,7 +15,7 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaVariable; public class PrefixMinusMinusOperator extends XfixOperator { - + public PrefixMinusMinusOperator(int variableTypeId, int start) { super(variableTypeId, start); } @@ -23,38 +23,47 @@ public class PrefixMinusMinusOperator extends XfixOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaVariable variable = (IJavaVariable) pop(); - + switch (fVariableTypeId) { - case T_byte : - variable.setValue(newValue((byte)(((IJavaPrimitiveValue)variable.getValue()).getByteValue() - 1))); - break; - case T_short : - variable.setValue(newValue((short)(((IJavaPrimitiveValue)variable.getValue()).getShortValue() - 1))); - break; - case T_char : - variable.setValue(newValue((char)(((IJavaPrimitiveValue)variable.getValue()).getCharValue() - 1))); - break; - case T_int : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getIntValue() - 1)); - break; - case T_long : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getLongValue() - 1)); - break; - case T_float : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getFloatValue() - 1)); - break; - case T_double : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getDoubleValue() - 1)); - break; + case T_byte: + variable.setValue(newValue((byte) (((IJavaPrimitiveValue) variable + .getValue()).getByteValue() - 1))); + break; + case T_short: + variable.setValue(newValue((short) (((IJavaPrimitiveValue) variable + .getValue()).getShortValue() - 1))); + break; + case T_char: + variable.setValue(newValue((char) (((IJavaPrimitiveValue) variable + .getValue()).getCharValue() - 1))); + break; + case T_int: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getIntValue() - 1)); + break; + case T_long: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getLongValue() - 1)); + break; + case T_float: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getFloatValue() - 1)); + break; + case T_double: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getDoubleValue() - 1)); + break; } push(variable.getValue()); } + @Override public String toString() { - return InstructionsEvaluationMessages.PrefixMinusMinusOperator_prefix________operator_1; + return InstructionsEvaluationMessages.PrefixMinusMinusOperator_prefix________operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixPlusPlusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixPlusPlusOperator.java index 818b553d2..33200c4e1 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixPlusPlusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PrefixPlusPlusOperator.java @@ -15,7 +15,7 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaVariable; public class PrefixPlusPlusOperator extends XfixOperator { - + public PrefixPlusPlusOperator(int variableTypeId, int start) { super(variableTypeId, start); } @@ -23,38 +23,47 @@ public class PrefixPlusPlusOperator extends XfixOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { IJavaVariable variable = (IJavaVariable) pop(); - + switch (fVariableTypeId) { - case T_byte : - variable.setValue(newValue((byte)(((IJavaPrimitiveValue)variable.getValue()).getByteValue() + 1))); - break; - case T_short : - variable.setValue(newValue((short)(((IJavaPrimitiveValue)variable.getValue()).getShortValue() + 1))); - break; - case T_char : - variable.setValue(newValue((char)(((IJavaPrimitiveValue)variable.getValue()).getCharValue() + 1))); - break; - case T_int : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getIntValue() + 1)); - break; - case T_long : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getLongValue() + 1)); - break; - case T_float : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getFloatValue() + 1)); - break; - case T_double : - variable.setValue(newValue(((IJavaPrimitiveValue)variable.getValue()).getDoubleValue() + 1)); - break; + case T_byte: + variable.setValue(newValue((byte) (((IJavaPrimitiveValue) variable + .getValue()).getByteValue() + 1))); + break; + case T_short: + variable.setValue(newValue((short) (((IJavaPrimitiveValue) variable + .getValue()).getShortValue() + 1))); + break; + case T_char: + variable.setValue(newValue((char) (((IJavaPrimitiveValue) variable + .getValue()).getCharValue() + 1))); + break; + case T_int: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getIntValue() + 1)); + break; + case T_long: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getLongValue() + 1)); + break; + case T_float: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getFloatValue() + 1)); + break; + case T_double: + variable.setValue(newValue(((IJavaPrimitiveValue) variable + .getValue()).getDoubleValue() + 1)); + break; } push(variable.getValue()); } + @Override public String toString() { - return InstructionsEvaluationMessages.PrefixPlusPlusOperator_prefix________operator_1; + return InstructionsEvaluationMessages.PrefixPlusPlusOperator_prefix________operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayLength.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayLength.java index 4d8820fbd..3678d1aa5 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayLength.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayLength.java @@ -10,27 +10,27 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.debug.core.IJavaArray; - + /** * Pops an array object off the stack, and pushes its length. */ public class PushArrayLength extends ArrayAccess { - + public PushArrayLength(int start) { super(start); } - + + @Override public void execute() throws CoreException { - IJavaArray receiver= popArray(); - int length= receiver.getLength(); + IJavaArray receiver = popArray(); + int length = receiver.getLength(); pushNewValue(length); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushArrayLength_push_array_length__1; + return InstructionsEvaluationMessages.PushArrayLength_push_array_length__1; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayType.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayType.java index 87b30056b..93cf0323b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayType.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushArrayType.java @@ -15,21 +15,21 @@ import org.eclipse.core.runtime.CoreException; public class PushArrayType extends ArrayInstruction { private String fTypeSignature; - + private int fDimension; - + public PushArrayType(String typeSignature, int dimension, int start) { super(start); fTypeSignature = typeSignature; fDimension = dimension; } - /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - push(getArrayType(fTypeSignature.replace('/','.'), fDimension)); + push(getArrayType(fTypeSignature.replace('/', '.'), fDimension)); } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushBoolean.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushBoolean.java index 0d6df388b..fa8c86a1a 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushBoolean.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushBoolean.java @@ -10,23 +10,23 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a boolean literal onto the stack. */ public class PushBoolean extends SimpleInstruction { private boolean fValue; - + public PushBoolean(boolean value) { - fValue= value; + fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } + @Override public String toString() { - return InstructionsEvaluationMessages.PushBoolean_push__1 + fValue; + return InstructionsEvaluationMessages.PushBoolean_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushChar.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushChar.java index d06f662eb..576439a3a 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushChar.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushChar.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a char literal onto the stack. */ public class PushChar extends SimpleInstruction { - + private char fValue; - + public PushChar(char value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushChar_push__1 + fValue; + return InstructionsEvaluationMessages.PushChar_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushClassLiteralValue.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushClassLiteralValue.java index 5c452f0fb..68ff72a7b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushClassLiteralValue.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushClassLiteralValue.java @@ -20,20 +20,22 @@ public class PushClassLiteralValue extends CompoundInstruction { public PushClassLiteralValue(int start) { super(start); } - + /** * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaType type = (IJavaType)pop(); + IJavaType type = (IJavaType) pop(); push(getClassObject(type)); } /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.PushClassLiteralValue_push_class_literal_value_1; + return InstructionsEvaluationMessages.PushClassLiteralValue_push_class_literal_value_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushDouble.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushDouble.java index d73030fae..d7aa82ca9 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushDouble.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushDouble.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a double literal onto the stack. */ public class PushDouble extends SimpleInstruction { - + private double fValue; - + public PushDouble(double value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushDouble_push__1 + fValue; + return InstructionsEvaluationMessages.PushDouble_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFieldVariable.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFieldVariable.java index f8dad5cae..ca6015b9b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFieldVariable.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFieldVariable.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -21,54 +18,72 @@ import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.core.model.JDINullValue; import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue; - + +import com.ibm.icu.text.MessageFormat; + /** - * Pops an object off the stack, and pushes the value - * of one of its fields onto the stack. + * Pops an object off the stack, and pushes the value of one of its fields onto + * the stack. */ public class PushFieldVariable extends CompoundInstruction { - + private String fDeclaringTypeSignature; - + private String fName; - - private int fSuperClassLevel; - + + private int fSuperClassLevel; + public PushFieldVariable(String name, int superClassLevel, int start) { super(start); - fName= name; - fSuperClassLevel= superClassLevel; + fName = name; + fSuperClassLevel = superClassLevel; } - - public PushFieldVariable(String name, String declaringTypeSignature, int start) { + + public PushFieldVariable(String name, String declaringTypeSignature, + int start) { super(start); - fName= name; - fDeclaringTypeSignature= declaringTypeSignature; + fName = name; + fDeclaringTypeSignature = declaringTypeSignature; } - + + @Override public void execute() throws CoreException { - Object value= popValue(); + Object value = popValue(); if (value instanceof JDINullValue) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.PushFieldVariable_0, null)); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, + InstructionsEvaluationMessages.PushFieldVariable_0, null)); } - IJavaObject receiver=(IJavaObject) value; - - IJavaVariable field= null; - + IJavaObject receiver = (IJavaObject) value; + + IJavaVariable field = null; + if (fDeclaringTypeSignature == null) { - field= ((JDIObjectValue)receiver).getField(fName, fSuperClassLevel); + field = ((JDIObjectValue) receiver).getField(fName, + fSuperClassLevel); } else { - field= receiver.getField(fName, fDeclaringTypeSignature); + field = receiver.getField(fName, fDeclaringTypeSignature); } - + if (field == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.PushFieldVariable_Cannot_find_the_field__0__for_the_object__1__1, new String[] {fName, receiver.toString()}), null)); // - } + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.PushFieldVariable_Cannot_find_the_field__0__for_the_object__1__1, + new String[] { fName, + receiver.toString() }), + null)); // + } push(field); } - + + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.PushFieldVariable_push_field__0__2, new String[] {fName}); + return MessageFormat + .format(InstructionsEvaluationMessages.PushFieldVariable_push_field__0__2, + new String[] { fName }); } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFloat.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFloat.java index 224cfdada..528f1545a 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFloat.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushFloat.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a float literal onto the stack. */ public class PushFloat extends SimpleInstruction { - + private float fValue; - + public PushFloat(float value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushFloat_push__1 + fValue; + return InstructionsEvaluationMessages.PushFloat_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushInt.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushInt.java index 8bda715e7..2e9a2e155 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushInt.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushInt.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes an int literal onto the stack. */ public class PushInt extends SimpleInstruction { - + private int fValue; - + public PushInt(int value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushInt_push__1 + fValue; + return InstructionsEvaluationMessages.PushInt_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLocalVariable.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLocalVariable.java index 7470c48a6..bb461638e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLocalVariable.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLocalVariable.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -20,53 +17,62 @@ import org.eclipse.debug.core.model.IVariable; import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext; - + +import com.ibm.icu.text.MessageFormat; + /** - * Pushes the value of a local, instance, or static - * variable onto the stack. + * Pushes the value of a local, instance, or static variable onto the stack. */ public class PushLocalVariable extends SimpleInstruction { - + /** * Name of variable to push. */ private String fName; - + public PushLocalVariable(String name) { fName = name; } - + + @Override public void execute() throws CoreException { - IVariable internalVariable= getInternalVariable(fName); + IVariable internalVariable = getInternalVariable(fName); if (internalVariable != null) { push(internalVariable); return; } - IRuntimeContext context= getContext(); + IRuntimeContext context = getContext(); IJavaVariable[] locals = context.getLocals(); - for (int i = 0; i < locals.length; i++) { - if (locals[i].getName().equals(getName())) { - push(locals[i]); + for (IJavaVariable local : locals) { + if (local.getName().equals(getName())) { + push(local); return; } } - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.PushLocalVariable_Cannot_find_the_variable____1, new String[]{fName}), null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + MessageFormat + .format(InstructionsEvaluationMessages.PushLocalVariable_Cannot_find_the_variable____1, + new String[] { fName }), null)); } - + /** - * Returns the name of the variable to push - * onto the stack. + * Returns the name of the variable to push onto the stack. * - * @return the name of the variable to push - * onto the stack + * @return the name of the variable to push onto the stack */ protected String getName() { return fName; } + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.PushLocalVariable_push____0___2, new String[]{getName()}); + return MessageFormat.format( + InstructionsEvaluationMessages.PushLocalVariable_push____0___2, + new String[] { getName() }); } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLong.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLong.java index 63f020018..d34c4d680 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLong.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushLong.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a long literal onto the stack. */ public class PushLong extends SimpleInstruction { - + private long fValue; - + public PushLong(long value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushLong_push__1 + fValue; + return InstructionsEvaluationMessages.PushLong_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushNull.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushNull.java index c65f48d5b..be784f406 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushNull.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushNull.java @@ -10,20 +10,18 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - - - /** * Pushes the 'null' onto the stack. */ public class PushNull extends SimpleInstruction { - + + @Override public void execute() { pushNullValue(); } + @Override public String toString() { - return InstructionsEvaluationMessages.PushNull_push___null__1; + return InstructionsEvaluationMessages.PushNull_push___null__1; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushPrimitiveType.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushPrimitiveType.java index c32517a79..2bea47273 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushPrimitiveType.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushPrimitiveType.java @@ -10,32 +10,29 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; - + /** * Pushes a primitive type onto the stack. - * + * * @since 3.4 */ public class PushPrimitiveType extends SimpleInstruction { - + private String fName; - - + public PushPrimitiveType(String name) { - fName= name; + fName = name; } - + + @Override public void execute() throws CoreException { push(getPrimitiveType(fName)); } - + + @Override public String toString() { - return "Push Primitive Type: " + fName; //$NON-NLS-1$ + return "Push Primitive Type: " + fName; //$NON-NLS-1$ } - - } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushStaticFieldVariable.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushStaticFieldVariable.java index 1b662e8a6..e6f0ce349 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushStaticFieldVariable.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushStaticFieldVariable.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -21,43 +18,52 @@ import org.eclipse.jdt.debug.core.IJavaInterfaceType; import org.eclipse.jdt.debug.core.IJavaType; import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; - + +import com.ibm.icu.text.MessageFormat; + /** - * Pushes the value of the static fields of the given type - * onto the stack. + * Pushes the value of the static fields of the given type onto the stack. */ public class PushStaticFieldVariable extends CompoundInstruction { - + private String fFieldName; - + private String fQualifiedTypeName; - - public PushStaticFieldVariable(String fieldName, String qualifiedTypeName, int start) { + + public PushStaticFieldVariable(String fieldName, String qualifiedTypeName, + int start) { super(start); - fFieldName= fieldName; - fQualifiedTypeName= qualifiedTypeName; + fFieldName = fieldName; + fQualifiedTypeName = qualifiedTypeName; } - + + @Override public void execute() throws CoreException { - IJavaType receiver= getType(fQualifiedTypeName); - - IJavaVariable field= null; + IJavaType receiver = getType(fQualifiedTypeName); + + IJavaVariable field = null; if (receiver instanceof IJavaInterfaceType) { - field= ((IJavaInterfaceType)receiver).getField(fFieldName); + field = ((IJavaInterfaceType) receiver).getField(fFieldName); } else if (receiver instanceof IJavaClassType) { - field= ((IJavaClassType)receiver).getField(fFieldName); + field = ((IJavaClassType) receiver).getField(fFieldName); } if (field == null) { - String message= MessageFormat.format(InstructionsEvaluationMessages.PushStaticFieldVariable_Cannot_find_the_field__0__in__1__1, new String[]{fFieldName, fQualifiedTypeName}); - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, message, null)); // couldn't find the field + String message = MessageFormat + .format(InstructionsEvaluationMessages.PushStaticFieldVariable_Cannot_find_the_field__0__in__1__1, + new String[] { fFieldName, fQualifiedTypeName }); + throw new CoreException(new Status(IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, message, + null)); // couldn't find the field } push(field); } - + + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.PushStaticFieldVariable_push_static_field__0__2, new String[]{fFieldName}); + return MessageFormat + .format(InstructionsEvaluationMessages.PushStaticFieldVariable_push_static_field__0__2, + new String[] { fFieldName }); } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushString.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushString.java index 3ec8dadad..8af33b90b 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushString.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushString.java @@ -10,25 +10,25 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - /** * Pushes a String literal onto the stack. */ public class PushString extends SimpleInstruction { - + private String fValue; - + public PushString(String value) { fValue = value; } - + + @Override public void execute() { pushNewValue(fValue); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushString_push__1 + fValue; + return InstructionsEvaluationMessages.PushString_push__1 + fValue; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushThis.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushThis.java index 592ad6f19..8e8b5d6ba 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushThis.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushThis.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -18,37 +17,45 @@ import org.eclipse.jdt.debug.core.IJavaObject; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue; import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext; - + /** * Pushes the 'this' object onto the stack. */ public class PushThis extends SimpleInstruction { - + private int fEnclosingLevel; - + public PushThis(int enclosingLevel) { - fEnclosingLevel= enclosingLevel; + fEnclosingLevel = enclosingLevel; } - + + @Override public void execute() throws CoreException { - IRuntimeContext context= getContext(); + IRuntimeContext context = getContext(); IJavaObject thisInstance = context.getThis(); if (thisInstance == null) { // static context push(context.getReceivingType()); } else { if (fEnclosingLevel != 0) { - thisInstance= ((JDIObjectValue)thisInstance).getEnclosingObject(fEnclosingLevel); + thisInstance = ((JDIObjectValue) thisInstance) + .getEnclosingObject(fEnclosingLevel); if (thisInstance == null) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.PushThis_Unable_to_retrieve_the_correct_enclosing_instance_of__this__2, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.PushThis_Unable_to_retrieve_the_correct_enclosing_instance_of__this__2, + null)); } } push(thisInstance); } } + @Override public String toString() { - return InstructionsEvaluationMessages.PushThis_push___this__1; + return InstructionsEvaluationMessages.PushThis_push___this__1; } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushType.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushType.java index acb004364..6a2316ee1 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushType.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/PushType.java @@ -10,30 +10,27 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.core.runtime.CoreException; - + /** * Pushes a reference type onto the stack. */ public class PushType extends SimpleInstruction { - + private String fTypeName; - - + public PushType(String signature) { - fTypeName= signature; + fTypeName = signature; } - + + @Override public void execute() throws CoreException { push(getType(fTypeName)); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.PushType_push_type__1 + fTypeName; + return InstructionsEvaluationMessages.PushType_push_type__1 + fTypeName; } - - } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderAssignmentOperator.java index 9255ced65..eff60ad4d 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class RemainderAssignmentOperator extends RemainderOperator { - public RemainderAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public RemainderAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.RemainderAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.RemainderAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderOperator.java index be99d14bb..79ee27acc 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RemainderOperator.java @@ -18,42 +18,60 @@ import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; public class RemainderOperator extends BinaryOperator { - public RemainderOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public RemainderOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected RemainderOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected RemainderOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() % ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() + % ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getFloatValue() % ((IJavaPrimitiveValue) rightOperand).getFloatValue(); + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getFloatValue() + % ((IJavaPrimitiveValue) rightOperand).getFloatValue(); } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ - protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { - int divisor= ((IJavaPrimitiveValue) rightOperand).getIntValue(); + @Override + protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) + throws CoreException { + int divisor = ((IJavaPrimitiveValue) rightOperand).getIntValue(); if (divisor == 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.RemainderOperator_Divide_by_zero_1, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.RemainderOperator_Divide_by_zero_1, + null)); } return ((IJavaPrimitiveValue) leftOperand).getIntValue() % divisor; } @@ -61,10 +79,18 @@ public class RemainderOperator extends BinaryOperator { /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ - protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { - long divisor= ((IJavaPrimitiveValue) rightOperand).getLongValue(); + @Override + protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) + throws CoreException { + long divisor = ((IJavaPrimitiveValue) rightOperand).getLongValue(); if (divisor == 0) { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.RemainderOperator_Divide_by_zero_2, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.RemainderOperator_Divide_by_zero_2, + null)); } return ((IJavaPrimitiveValue) leftOperand).getLongValue() % divisor; } @@ -72,12 +98,15 @@ public class RemainderOperator extends BinaryOperator { /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.RemainderOperator______operator_3; + return InstructionsEvaluationMessages.RemainderOperator______operator_3; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ReturnInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ReturnInstruction.java index 7c865f8d1..1048d34a6 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ReturnInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ReturnInstruction.java @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - - public class ReturnInstruction extends CompoundInstruction { /** * Constructor for ReturnInstruction. + * * @param start */ public ReturnInstruction(int start) { @@ -25,12 +24,14 @@ public class ReturnInstruction extends CompoundInstruction { /** * @see Instruction#execute() */ + @Override public void execute() { stop(); } - + + @Override public String toString() { - return InstructionsEvaluationMessages.ReturnInstruction_return; + return InstructionsEvaluationMessages.ReturnInstruction_return; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftAssignmentOperator.java index 11b508c58..5a0724457 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftAssignmentOperator.java @@ -12,12 +12,14 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public class RightShiftAssignmentOperator extends RightShiftOperator { - public RightShiftAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public RightShiftAssignmentOperator(int variableTypeId, int valueTypeId, + int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.RightShiftAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.RightShiftAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftOperator.java index 8f24db2c7..39cf86721 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RightShiftOperator.java @@ -14,85 +14,103 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; public class RightShiftOperator extends BinaryOperator { - public RightShiftOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public RightShiftOperator(int resultId, int leftTypeId, int rightTypeId, + int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - protected RightShiftOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + protected RightShiftOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() >> ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() >> ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() >> ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() >> ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() >> ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() >> ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() >> ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() >> ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override protected int getInternResultType() { // unary type promotion on both operands see 5.6.1 and 15.18 return getUnaryPromotionType(fLeftTypeId); } + @Override public String toString() { - return InstructionsEvaluationMessages.RightShiftOperator_______operator_1; + return InstructionsEvaluationMessages.RightShiftOperator_______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RuntimeSignature.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RuntimeSignature.java index 91fc7dfe5..c0d550047 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RuntimeSignature.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/RuntimeSignature.java @@ -10,15 +10,12 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - import org.eclipse.jdt.core.compiler.CharOperation; /** - * Copy of org.eclipse.jdt.core.Signature. The class is copied here - * solely for the purpose of commenting out the line: - * CharOperation.replace(result, C_DOLLAR, C_DOT); - * in the method toCharArray(char[]). - * See Bug 22165 + * Copy of org.eclipse.jdt.core.Signature. The class is copied here solely for + * the purpose of commenting out the line: CharOperation.replace(result, + * C_DOLLAR, C_DOT); in the method toCharArray(char[]). See Bug 22165 */ public class RuntimeSignature { public static final char C_BOOLEAN = 'Z'; @@ -60,12 +57,12 @@ public class RuntimeSignature { private static final char[] VOID = { 'v', 'o', 'i', 'd' }; public static String toString(String signature) - throws IllegalArgumentException { + throws IllegalArgumentException { return new String(toCharArray(signature.toCharArray())); } public static char[] toCharArray(char[] signature) - throws IllegalArgumentException { + throws IllegalArgumentException { try { int sigLength = signature.length; @@ -80,57 +77,57 @@ public class RuntimeSignature { resultLength += 2; // [] } switch (signature[index]) { - case C_BOOLEAN : - resultLength += BOOLEAN.length; - break; - case C_BYTE : - resultLength += BYTE.length; - break; - case C_CHAR : - resultLength += CHAR.length; - break; - case C_DOUBLE : - resultLength += DOUBLE.length; - break; - case C_FLOAT : - resultLength += FLOAT.length; - break; - case C_INT : - resultLength += INT.length; - break; - case C_LONG : - resultLength += LONG.length; - break; - case C_SHORT : - resultLength += SHORT.length; - break; - case C_VOID : - resultLength += VOID.length; - break; - case C_RESOLVED : - case C_UNRESOLVED : - int end = - CharOperation.indexOf(C_SEMICOLON, signature, index); - if (end == -1) - throw new IllegalArgumentException(); - int start = index + 1; - resultLength += end - start; - break; - default : + case C_BOOLEAN: + resultLength += BOOLEAN.length; + break; + case C_BYTE: + resultLength += BYTE.length; + break; + case C_CHAR: + resultLength += CHAR.length; + break; + case C_DOUBLE: + resultLength += DOUBLE.length; + break; + case C_FLOAT: + resultLength += FLOAT.length; + break; + case C_INT: + resultLength += INT.length; + break; + case C_LONG: + resultLength += LONG.length; + break; + case C_SHORT: + resultLength += SHORT.length; + break; + case C_VOID: + resultLength += VOID.length; + break; + case C_RESOLVED: + case C_UNRESOLVED: + int end = CharOperation.indexOf(C_SEMICOLON, signature, index); + if (end == -1) throw new IllegalArgumentException(); + int start = index + 1; + resultLength += end - start; + break; + default: + throw new IllegalArgumentException(); } char[] result = new char[resultLength]; copyType(signature, 0, result, 0, true); /** - * Converts '$' separated type signatures into '.' separated type signature. - * NOTE: This assumes that the type signature is an inner type signature. - * This is true in most cases, but someone can define a non-inner type - * name containing a '$'. However to tell the difference, we would have - * to resolve the signature, which cannot be done at this point. + * Converts '$' separated type signatures into '.' separated type + * signature. NOTE: This assumes that the type signature is an inner + * type signature. This is true in most cases, but someone can + * define a non-inner type name containing a '$'. However to tell + * the difference, we would have to resolve the signature, which + * cannot be done at this point. */ -// CharOperation.replace(result, C_DOLLAR, C_DOT); + // CharOperation.replace(result, C_DOLLAR, C_DOT); return result; } catch (ArrayIndexOutOfBoundsException e) { @@ -138,15 +135,12 @@ public class RuntimeSignature { } } - public static char[] toCharArray( - char[] methodSignature, - char[] methodName, - char[][] parameterNames, - boolean fullyQualifyTypeNames, - boolean includeReturnType) { + public static char[] toCharArray(char[] methodSignature, char[] methodName, + char[][] parameterNames, boolean fullyQualifyTypeNames, + boolean includeReturnType) { try { - int firstParen = - CharOperation.indexOf(C_PARAM_START, methodSignature); + int firstParen = CharOperation.indexOf(C_PARAM_START, + methodSignature); if (firstParen == -1) throw new IllegalArgumentException(); @@ -158,102 +152,99 @@ public class RuntimeSignature { int paramCount = 0; int lastParen = -1; int resultLength = 0; - signature : for (int i = firstParen; i < sigLength; i++) { + signature: for (int i = firstParen; i < sigLength; i++) { switch (methodSignature[i]) { - case C_ARRAY : - resultLength += 2; // [] - continue signature; - case C_BOOLEAN : - resultLength += BOOLEAN.length; - break; - case C_BYTE : - resultLength += BYTE.length; - break; - case C_CHAR : - resultLength += CHAR.length; - break; - case C_DOUBLE : - resultLength += DOUBLE.length; - break; - case C_FLOAT : - resultLength += FLOAT.length; - break; - case C_INT : - resultLength += INT.length; - break; - case C_LONG : - resultLength += LONG.length; - break; - case C_SHORT : - resultLength += SHORT.length; - break; - case C_VOID : - resultLength += VOID.length; - break; - case C_RESOLVED : - case C_UNRESOLVED : - int end = - CharOperation.indexOf( - C_SEMICOLON, - methodSignature, - i); - if (end == -1) - throw new IllegalArgumentException(); - int start; - if (fullyQualifyTypeNames) { + case C_ARRAY: + resultLength += 2; // [] + continue signature; + case C_BOOLEAN: + resultLength += BOOLEAN.length; + break; + case C_BYTE: + resultLength += BYTE.length; + break; + case C_CHAR: + resultLength += CHAR.length; + break; + case C_DOUBLE: + resultLength += DOUBLE.length; + break; + case C_FLOAT: + resultLength += FLOAT.length; + break; + case C_INT: + resultLength += INT.length; + break; + case C_LONG: + resultLength += LONG.length; + break; + case C_SHORT: + resultLength += SHORT.length; + break; + case C_VOID: + resultLength += VOID.length; + break; + case C_RESOLVED: + case C_UNRESOLVED: + int end = CharOperation.indexOf(C_SEMICOLON, + methodSignature, i); + if (end == -1) + throw new IllegalArgumentException(); + int start; + if (fullyQualifyTypeNames) { + start = i + 1; + } else { + start = CharOperation.lastIndexOf(C_DOT, + methodSignature, i, end) + 1; + if (start == 0) start = i + 1; - } else { - start = - CharOperation.lastIndexOf( - C_DOT, - methodSignature, - i, - end) - + 1; - if (start == 0) - start = i + 1; - } - resultLength += end - start; - i = end; - break; - case C_PARAM_START : - // add space for "(" - resultLength++; - continue signature; - case C_PARAM_END : - lastParen = i; - if (includeReturnType) { - if (paramCount > 0) { - // remove space for ", " that was added with last parameter and remove space that is going to be added for ", " after return type - // and add space for ") " - resultLength -= 2; - } //else - // remove space that is going to be added for ", " after return type + } + resultLength += end - start; + i = end; + break; + case C_PARAM_START: + // add space for "(" + resultLength++; + continue signature; + case C_PARAM_END: + lastParen = i; + if (includeReturnType) { + if (paramCount > 0) { + // remove space for ", " that was added with last + // parameter and remove space that is going to be + // added for ", " after return type + // and add space for ") " + resultLength -= 2; + } // else + // remove space that is going to be added for ", " + // after return type // and add space for ") " // -> noop - // decrement param count because it is going to be added for return type - paramCount--; - continue signature; - } - if (paramCount > 0) { - // remove space for ", " that was added with last parameter and add space for ")" - resultLength--; - } else { - // add space for ")" - resultLength++; - } - break signature; - default : - throw new IllegalArgumentException(); + // decrement param count because it is going to be added + // for return type + paramCount--; + continue signature; + } + if (paramCount > 0) { + // remove space for ", " that was added with last + // parameter and add space for ")" + resultLength--; + } else { + // add space for ")" + resultLength++; + } + break signature; + default: + throw new IllegalArgumentException(); } resultLength += 2; // add space for ", " paramCount++; } // parameter names - int parameterNamesLength = - parameterNames == null ? 0 : parameterNames.length; + int parameterNamesLength = parameterNames == null ? 0 + : parameterNames.length; for (int i = 0; i < parameterNamesLength; i++) { resultLength += parameterNames[i].length + 1; // parameter name + space @@ -269,13 +260,8 @@ public class RuntimeSignature { // returned type int index = 0; if (includeReturnType) { - long pos = - copyType( - methodSignature, - lastParen + 1, - result, - index, - fullyQualifyTypeNames); + long pos = copyType(methodSignature, lastParen + 1, result, + index, fullyQualifyTypeNames); index = (int) (pos >>> 32); result[index++] = ' '; } @@ -290,12 +276,7 @@ public class RuntimeSignature { result[index++] = C_PARAM_START; int sigPos = firstParen + 1; for (int i = 0; i < paramCount; i++) { - long pos = - copyType( - methodSignature, - sigPos, - result, - index, + long pos = copyType(methodSignature, sigPos, result, index, fullyQualifyTypeNames); index = (int) (pos >>> 32); sigPos = (int) pos; @@ -303,12 +284,8 @@ public class RuntimeSignature { result[index++] = ' '; char[] parameterName = parameterNames[i]; int paramLength = parameterName.length; - System.arraycopy( - parameterName, - 0, - result, - index, - paramLength); + System.arraycopy(parameterName, 0, result, index, + paramLength); index += paramLength; } if (i != paramCount - 1) { @@ -328,88 +305,78 @@ public class RuntimeSignature { } } - private static long copyType( - char[] signature, - int sigPos, - char[] dest, - int index, - boolean fullyQualifyTypeNames) { + private static long copyType(char[] signature, int sigPos, char[] dest, + int index, boolean fullyQualifyTypeNames) { int arrayCount = 0; - loop : while (true) { + loop: while (true) { switch (signature[sigPos++]) { - case C_ARRAY : - arrayCount++; - break; - case C_BOOLEAN : - int length = BOOLEAN.length; - System.arraycopy(BOOLEAN, 0, dest, index, length); - index += length; - break loop; - case C_BYTE : - length = BYTE.length; - System.arraycopy(BYTE, 0, dest, index, length); - index += length; - break loop; - case C_CHAR : - length = CHAR.length; - System.arraycopy(CHAR, 0, dest, index, length); - index += length; - break loop; - case C_DOUBLE : - length = DOUBLE.length; - System.arraycopy(DOUBLE, 0, dest, index, length); - index += length; - break loop; - case C_FLOAT : - length = FLOAT.length; - System.arraycopy(FLOAT, 0, dest, index, length); - index += length; - break loop; - case C_INT : - length = INT.length; - System.arraycopy(INT, 0, dest, index, length); - index += length; - break loop; - case C_LONG : - length = LONG.length; - System.arraycopy(LONG, 0, dest, index, length); - index += length; - break loop; - case C_SHORT : - length = SHORT.length; - System.arraycopy(SHORT, 0, dest, index, length); - index += length; - break loop; - case C_VOID : - length = VOID.length; - System.arraycopy(VOID, 0, dest, index, length); - index += length; - break loop; - case C_RESOLVED : - case C_UNRESOLVED : - int end = - CharOperation.indexOf(C_SEMICOLON, signature, sigPos); - if (end == -1) - throw new IllegalArgumentException(); - int start; - if (fullyQualifyTypeNames) { + case C_ARRAY: + arrayCount++; + break; + case C_BOOLEAN: + int length = BOOLEAN.length; + System.arraycopy(BOOLEAN, 0, dest, index, length); + index += length; + break loop; + case C_BYTE: + length = BYTE.length; + System.arraycopy(BYTE, 0, dest, index, length); + index += length; + break loop; + case C_CHAR: + length = CHAR.length; + System.arraycopy(CHAR, 0, dest, index, length); + index += length; + break loop; + case C_DOUBLE: + length = DOUBLE.length; + System.arraycopy(DOUBLE, 0, dest, index, length); + index += length; + break loop; + case C_FLOAT: + length = FLOAT.length; + System.arraycopy(FLOAT, 0, dest, index, length); + index += length; + break loop; + case C_INT: + length = INT.length; + System.arraycopy(INT, 0, dest, index, length); + index += length; + break loop; + case C_LONG: + length = LONG.length; + System.arraycopy(LONG, 0, dest, index, length); + index += length; + break loop; + case C_SHORT: + length = SHORT.length; + System.arraycopy(SHORT, 0, dest, index, length); + index += length; + break loop; + case C_VOID: + length = VOID.length; + System.arraycopy(VOID, 0, dest, index, length); + index += length; + break loop; + case C_RESOLVED: + case C_UNRESOLVED: + int end = CharOperation.indexOf(C_SEMICOLON, signature, sigPos); + if (end == -1) + throw new IllegalArgumentException(); + int start; + if (fullyQualifyTypeNames) { + start = sigPos; + } else { + start = CharOperation.lastIndexOf(C_DOT, signature, sigPos, + end) + 1; + if (start == 0) start = sigPos; - } else { - start = - CharOperation.lastIndexOf( - C_DOT, - signature, - sigPos, - end) - + 1; - if (start == 0) - start = sigPos; - } - length = end - start; - System.arraycopy(signature, start, dest, index, length); - sigPos = end + 1; - index += length; - break loop; + } + length = end - start; + System.arraycopy(signature, start, dest, index, length); + sigPos = end + 1; + index += length; + break loop; } } while (arrayCount-- > 0) { diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendMessage.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendMessage.java index 39e9a9955..c728bc075 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendMessage.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendMessage.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -20,44 +17,54 @@ import org.eclipse.jdt.debug.core.IJavaObject; import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; - + +import com.ibm.icu.text.MessageFormat; + /** - * Sends an message to an instance. The arguments are on the - * stack in reverse order, followed by the receiver. - * Pushes the result, if any, onto the stack + * Sends an message to an instance. The arguments are on the stack in reverse + * order, followed by the receiver. Pushes the result, if any, onto the stack */ public class SendMessage extends CompoundInstruction { - + private int fArgCount; private String fSelector; private String fSignature; private String fDeclaringType; - - public SendMessage(String selector, String signature, int argCount, String declaringType, int start) { + + public SendMessage(String selector, String signature, int argCount, + String declaringType, int start) { super(start); - fArgCount= argCount; - fSelector= selector; - fSignature= signature; - fDeclaringType= declaringType; + fArgCount = argCount; + fSelector = selector; + fSignature = signature; + fDeclaringType = declaringType; } - + + @Override public void execute() throws CoreException { IJavaValue[] args = new IJavaValue[fArgCount]; // args are in reverse order - for (int i= fArgCount - 1; i >= 0; i--) { + for (int i = fArgCount - 1; i >= 0; i--) { args[i] = popValue(); } Object receiver = pop(); IJavaValue result = null; - + if (receiver instanceof IJavaVariable) { - receiver = ((IJavaVariable) receiver).getValue(); + receiver = ((IJavaVariable) receiver).getValue(); } - + if (receiver instanceof IJavaObject) { - result = ((IJavaObject)receiver).sendMessage(fSelector, fSignature, args, getContext().getThread(), fDeclaringType); + result = ((IJavaObject) receiver).sendMessage(fSelector, + fSignature, args, getContext().getThread(), fDeclaringType); } else { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.SendMessage_Attempt_to_send_a_message_to_a_non_object_value_1, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.SendMessage_Attempt_to_send_a_message_to_a_non_object_value_1, + null)); } setLastValue(result); if (!fSignature.endsWith(")V")) { //$NON-NLS-1$ @@ -65,9 +72,11 @@ public class SendMessage extends CompoundInstruction { push(result); } } - + + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.SendMessage_send_message__0___1__2, new String[]{fSelector,fSignature}); + return MessageFormat + .format(InstructionsEvaluationMessages.SendMessage_send_message__0___1__2, + new String[] { fSelector, fSignature }); } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendStaticMessage.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendStaticMessage.java index d0cf0ab68..f8e1484e9 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendStaticMessage.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SendStaticMessage.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - -import com.ibm.icu.text.MessageFormat; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -20,40 +17,50 @@ import org.eclipse.jdt.debug.core.IJavaClassType; import org.eclipse.jdt.debug.core.IJavaType; import org.eclipse.jdt.debug.core.IJavaValue; import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; - + +import com.ibm.icu.text.MessageFormat; + /** - * Sends a message. The arguments are on the - * stack in reverse order, followed by the receiver. - * Pushes the result, if any, onto the stack + * Sends a message. The arguments are on the stack in reverse order, followed by + * the receiver. Pushes the result, if any, onto the stack */ public class SendStaticMessage extends CompoundInstruction { - + private int fArgCount; private String fSelector; private String fSignature; private String fTypeName; - - public SendStaticMessage(String typeName, String selector, String signature, int argCount, int start) { + + public SendStaticMessage(String typeName, String selector, + String signature, int argCount, int start) { super(start); - fArgCount= argCount; - fSelector= selector; - fSignature= signature; - fTypeName= typeName; + fArgCount = argCount; + fSelector = selector; + fSignature = signature; + fTypeName = typeName; } - + + @Override public void execute() throws CoreException { IJavaValue[] args = new IJavaValue[fArgCount]; // args are in reverse order - for (int i= fArgCount - 1; i >= 0; i--) { + for (int i = fArgCount - 1; i >= 0; i--) { args[i] = popValue(); } - - IJavaType receiver= getType(fTypeName); + + IJavaType receiver = getType(fTypeName); IJavaValue result; if (receiver instanceof IJavaClassType) { - result= ((IJavaClassType)receiver).sendMessage(fSelector, fSignature, args, getContext().getThread()); + result = ((IJavaClassType) receiver).sendMessage(fSelector, + fSignature, args, getContext().getThread()); } else { - throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.SendStaticMessage_Cannot_send_a_static_message_to_a_non_class_type_object_1, null)); + throw new CoreException( + new Status( + IStatus.ERROR, + JDIDebugPlugin.getUniqueIdentifier(), + IStatus.OK, + InstructionsEvaluationMessages.SendStaticMessage_Cannot_send_a_static_message_to_a_non_class_type_object_1, + null)); } setLastValue(result); if (!fSignature.endsWith(")V")) { //$NON-NLS-1$ @@ -61,9 +68,11 @@ public class SendStaticMessage extends CompoundInstruction { push(result); } } - + + @Override public String toString() { - return MessageFormat.format(InstructionsEvaluationMessages.SendStaticMessage_send_static_message__0___1__2, new String[]{fSelector, fSignature}); + return MessageFormat + .format(InstructionsEvaluationMessages.SendStaticMessage_send_static_message__0___1__2, + new String[] { fSelector, fSignature }); } } - diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SimpleInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SimpleInstruction.java index 93e7bbf4b..f10f89101 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SimpleInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/SimpleInstruction.java @@ -10,11 +10,9 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - - /** - * A simple instruction cannot contain other instructions - * so its size is always one. + * A simple instruction cannot contain other instructions so its size is always + * one. */ public abstract class SimpleInstruction extends Instruction { @@ -24,14 +22,10 @@ public abstract class SimpleInstruction extends Instruction { protected SimpleInstruction() { super(); } - + + @Override public int getSize() { return 1; } - - - - - } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ThrowInstruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ThrowInstruction.java index 037f078a2..54e7a10e9 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ThrowInstruction.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/ThrowInstruction.java @@ -30,8 +30,9 @@ public class ThrowInstruction extends CompoundInstruction { /** * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaObject exception= (IJavaObject)popValue(); + IJavaObject exception = (IJavaObject) popValue(); final IJavaThread javaThread = getContext().getThread(); javaThread.stop(exception); javaThread.queueRunnable(new Runnable() { diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/TwiddleOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/TwiddleOperator.java index 92042c7f3..8758deb0e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/TwiddleOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/TwiddleOperator.java @@ -22,23 +22,25 @@ public class TwiddleOperator extends UnaryOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaPrimitiveValue value= (IJavaPrimitiveValue)popValue(); + IJavaPrimitiveValue value = (IJavaPrimitiveValue) popValue(); switch (fExpressionTypeId) { - case T_long: - pushNewValue(~value.getLongValue()); - break; - case T_byte: - case T_short: - case T_int: - case T_char: - pushNewValue(~value.getIntValue()); - break; + case T_long: + pushNewValue(~value.getLongValue()); + break; + case T_byte: + case T_short: + case T_int: + case T_char: + pushNewValue(~value.getIntValue()); + break; } } + @Override public String toString() { - return InstructionsEvaluationMessages.TwiddleOperator______operator_1; + return InstructionsEvaluationMessages.TwiddleOperator______operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryMinusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryMinusOperator.java index f9ebe5913..34a23bc24 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryMinusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryMinusOperator.java @@ -22,32 +22,34 @@ public class UnaryMinusOperator extends UnaryOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaPrimitiveValue value= (IJavaPrimitiveValue)popValue(); + IJavaPrimitiveValue value = (IJavaPrimitiveValue) popValue(); switch (fExpressionTypeId) { - case T_double: - pushNewValue(-value.getDoubleValue()); - break; - case T_float: - pushNewValue(-value.getFloatValue()); - break; - case T_long: - pushNewValue(-value.getLongValue()); - break; - case T_byte: - case T_short: - case T_int: - case T_char: - pushNewValue(-value.getIntValue()); - break; + case T_double: + pushNewValue(-value.getDoubleValue()); + break; + case T_float: + pushNewValue(-value.getFloatValue()); + break; + case T_long: + pushNewValue(-value.getLongValue()); + break; + case T_byte: + case T_short: + case T_int: + case T_char: + pushNewValue(-value.getIntValue()); + break; } } /* * @see Object#toString() */ + @Override public String toString() { - return InstructionsEvaluationMessages.UnaryMinusOperator_unary_minus_operator_1; + return InstructionsEvaluationMessages.UnaryMinusOperator_unary_minus_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryOperator.java index 2866b5730..297f0f546 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryOperator.java @@ -12,9 +12,9 @@ package org.eclipse.jdt.internal.debug.eval.ast.instructions; public abstract class UnaryOperator extends CompoundInstruction { protected int fExpressionTypeId; - + public UnaryOperator(int expressionTypeId, int start) { super(start); - fExpressionTypeId= expressionTypeId; + fExpressionTypeId = expressionTypeId; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryPlusOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryPlusOperator.java index b70d45251..a9ed5b97e 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryPlusOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnaryPlusOperator.java @@ -22,29 +22,31 @@ public class UnaryPlusOperator extends UnaryOperator { /* * @see Instruction#execute() */ + @Override public void execute() throws CoreException { - IJavaPrimitiveValue value= (IJavaPrimitiveValue)popValue(); + IJavaPrimitiveValue value = (IJavaPrimitiveValue) popValue(); switch (fExpressionTypeId) { - case T_double: - pushNewValue(+value.getDoubleValue()); - break; - case T_float: - pushNewValue(+value.getFloatValue()); - break; - case T_long: - pushNewValue(+value.getLongValue()); - break; - case T_byte: - case T_short: - case T_int: - case T_char: - pushNewValue(+value.getIntValue()); - break; + case T_double: + pushNewValue(+value.getDoubleValue()); + break; + case T_float: + pushNewValue(+value.getFloatValue()); + break; + case T_long: + pushNewValue(+value.getLongValue()); + break; + case T_byte: + case T_short: + case T_int: + case T_char: + pushNewValue(+value.getIntValue()); + break; } } + @Override public String toString() { - return InstructionsEvaluationMessages.UnaryPlusOperator_unary_plus_operator_1; + return InstructionsEvaluationMessages.UnaryPlusOperator_unary_plus_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftAssignmentOperator.java index 0f01ff16b..76aceb197 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftAssignmentOperator.java @@ -10,14 +10,17 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; -public class UnsignedRightShiftAssignmentOperator extends UnsignedRightShiftOperator { +public class UnsignedRightShiftAssignmentOperator extends + UnsignedRightShiftOperator { - public UnsignedRightShiftAssignmentOperator(int variableTypeId, int valueTypeId, int start) { + public UnsignedRightShiftAssignmentOperator(int variableTypeId, + int valueTypeId, int start) { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.UnsignedRightShiftAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.UnsignedRightShiftAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftOperator.java index ecbc0aa04..216c5bc2c 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/UnsignedRightShiftOperator.java @@ -14,85 +14,103 @@ import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; import org.eclipse.jdt.debug.core.IJavaValue; public class UnsignedRightShiftOperator extends BinaryOperator { - public UnsignedRightShiftOperator(int resultId, int leftTypeId, int rightTypeId, int start) { + public UnsignedRightShiftOperator(int resultId, int leftTypeId, + int rightTypeId, int start) { this(resultId, leftTypeId, rightTypeId, false, start); } - public UnsignedRightShiftOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + public UnsignedRightShiftOperator(int resultId, int leftTypeId, + int rightTypeId, boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return false; } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() >>> ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getIntValue() >>> ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() >>> ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getIntValue() >>> ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { // unary type promotion on both operands see 5.6.1 and 15.18 switch (fRightTypeId) { - case T_long : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() >>> ((IJavaPrimitiveValue) rightOperand).getLongValue(); - case T_int : - case T_short : - case T_byte : - case T_char : - return ((IJavaPrimitiveValue) leftOperand).getLongValue() >>> ((IJavaPrimitiveValue) rightOperand).getIntValue(); - default : - return 0; + case T_long: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() >>> ((IJavaPrimitiveValue) rightOperand) + .getLongValue(); + case T_int: + case T_short: + case T_byte: + case T_char: + return ((IJavaPrimitiveValue) leftOperand).getLongValue() >>> ((IJavaPrimitiveValue) rightOperand) + .getIntValue(); + default: + return 0; } } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override protected int getInternResultType() { // unary type promotion on both operands see 5.6.1 and 15.18 return getUnaryPromotionType(fLeftTypeId); } + @Override public String toString() { - return InstructionsEvaluationMessages.UnsignedRightShiftOperator________operator_1; + return InstructionsEvaluationMessages.UnsignedRightShiftOperator________operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Value.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Value.java index f1686bc36..014211d77 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Value.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Value.java @@ -17,14 +17,18 @@ import org.eclipse.core.runtime.CoreException; */ public class Value extends CompoundInstruction { - public Value(int start) { super(start); } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute + * () */ + @Override public void execute() throws CoreException { push(popValue()); } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XfixOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XfixOperator.java index 8f0747ed2..36e2dd341 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XfixOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XfixOperator.java @@ -10,16 +10,13 @@ *******************************************************************************/ package org.eclipse.jdt.internal.debug.eval.ast.instructions; - - public abstract class XfixOperator extends CompoundInstruction { protected int fVariableTypeId; - + public XfixOperator(int variableTypeId, int start) { super(start); fVariableTypeId = variableTypeId; } - } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorAssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorAssignmentOperator.java index d57249bc0..73a22a693 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorAssignmentOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorAssignmentOperator.java @@ -16,8 +16,9 @@ public class XorAssignmentOperator extends XorOperator { super(variableTypeId, variableTypeId, valueTypeId, true, start); } + @Override public String toString() { - return InstructionsEvaluationMessages.XorAssignmentOperator_operator_1; + return InstructionsEvaluationMessages.XorAssignmentOperator_operator_1; } } diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorOperator.java index 280ff88bf..81ffbd741 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorOperator.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/XorOperator.java @@ -18,54 +18,69 @@ public class XorOperator extends BinaryOperator { this(resultId, leftTypeId, rightTypeId, false, start); } - public XorOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { + public XorOperator(int resultId, int leftTypeId, int rightTypeId, + boolean isAssignmentOperator, int start) { super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); } /* * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue) */ - protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() ^ ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); + @Override + protected boolean getBooleanResult(IJavaValue leftOperand, + IJavaValue rightOperand) { + return ((IJavaPrimitiveValue) leftOperand).getBooleanValue() + ^ ((IJavaPrimitiveValue) rightOperand).getBooleanValue(); } /* * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue) */ - protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected double getDoubleResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue) */ - protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected float getFloatResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return 0; } /* * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue) */ + @Override protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getIntValue() ^ ((IJavaPrimitiveValue) rightOperand).getIntValue(); + return ((IJavaPrimitiveValue) leftOperand).getIntValue() + ^ ((IJavaPrimitiveValue) rightOperand).getIntValue(); } /* * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue) */ + @Override protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { - return ((IJavaPrimitiveValue) leftOperand).getLongValue() ^ ((IJavaPrimitiveValue) rightOperand).getLongValue(); + return ((IJavaPrimitiveValue) leftOperand).getLongValue() + ^ ((IJavaPrimitiveValue) rightOperand).getLongValue(); } /* * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue) */ - protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { + @Override + protected String getStringResult(IJavaValue leftOperand, + IJavaValue rightOperand) { return null; } + @Override public String toString() { - return InstructionsEvaluationMessages.XorOperator______operator_1; + return InstructionsEvaluationMessages.XorOperator______operator_1; } } |