### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetEvaluator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetEvaluator.java,v retrieving revision 1.30 diff -u -r1.30 CodeSnippetEvaluator.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetEvaluator.java 7 Mar 2009 01:08:09 -0000 1.30 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetEvaluator.java 11 May 2011 14:58:48 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 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 @@ -12,6 +12,7 @@ import java.util.Map; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.*; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.Compiler; @@ -188,7 +189,8 @@ this.context.localVariableTypeNames, this.context.localVariableModifiers, this.context.declaringTypeName, - this.context.lineSeparator + this.context.lineSeparator, + CompilerOptions.versionToJdkLevel(this.options.get(JavaCore.COMPILER_COMPLIANCE)) ); } Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetToCuMapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetToCuMapper.java,v retrieving revision 1.69 diff -u -r1.69 CodeSnippetToCuMapper.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetToCuMapper.java 7 Jan 2010 20:18:48 -0000 1.69 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetToCuMapper.java 11 May 2011 14:58:48 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 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 @@ -16,8 +16,8 @@ import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.compiler.*; -import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.codeassist.ISelectionRequestor; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; /** * Maps back and forth a code snippet to a compilation unit. @@ -56,11 +56,24 @@ // Mapping of external local variables char[][] localVarNames; char[][] localVarTypeNames; + + long complianceVersion; /** * Rebuild source in presence of external local variables */ - public CodeSnippetToCuMapper(char[] codeSnippet, char[] packageName, char[][] imports, char[] className, char[] varClassName, char[][] localVarNames, char[][] localVarTypeNames, int[] localVarModifiers, char[] declaringTypeName, String lineSeparator) { + public CodeSnippetToCuMapper( + char[] codeSnippet, + char[] packageName, + char[][] imports, + char[] className, + char[] varClassName, + char[][] localVarNames, + char[][] localVarTypeNames, + int[] localVarModifiers, + char[] declaringTypeName, + String lineSeparator, + long complianceVersion) { this.codeSnippet = codeSnippet; this.snippetPackageName = packageName; this.snippetImports = imports; @@ -69,6 +82,7 @@ this.localVarNames = localVarNames; this.localVarTypeNames = localVarTypeNames; this.snippetDeclaringTypeName = declaringTypeName; + this.complianceVersion = complianceVersion; buildCUSource(lineSeparator); } private void buildCUSource(String lineSeparator) { @@ -129,6 +143,9 @@ } } // run() method declaration + if (this.complianceVersion >= ClassFileConstants.JDK1_6) { + buffer.append("@Override "); //$NON-NLS-1$ + } buffer.append("public void run() throws Throwable {").append(lineSeparator); //$NON-NLS-1$ this.lineNumberOffset++; this.startPosOffset = buffer.length(); Index: eval/org/eclipse/jdt/internal/eval/EvaluationContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/EvaluationContext.java,v retrieving revision 1.65 diff -u -r1.65 EvaluationContext.java --- eval/org/eclipse/jdt/internal/eval/EvaluationContext.java 20 May 2010 14:12:00 -0000 1.65 +++ eval/org/eclipse/jdt/internal/eval/EvaluationContext.java 11 May 2011 14:58:48 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 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 @@ -16,6 +16,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.CompletionRequestor; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.compiler.*; import org.eclipse.jdt.internal.codeassist.CompletionEngine; @@ -28,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.env.IBinaryType; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; @@ -128,6 +130,7 @@ // Do nothing } final char[] className = "CodeSnippetCompletion".toCharArray(); //$NON-NLS-1$ + final long complianceVersion = CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_COMPLIANCE)); final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper( codeSnippet, this.packageName, @@ -138,7 +141,8 @@ this.localVariableTypeNames, this.localVariableModifiers, this.declaringTypeName, - this.lineSeparator + this.lineSeparator, + complianceVersion ); ICompilationUnit sourceUnit = new ICompilationUnit() { public char[] getFileName() { @@ -570,6 +574,7 @@ WorkingCopyOwner owner) { final char[] className = "CodeSnippetSelection".toCharArray(); //$NON-NLS-1$ + final long complianceVersion = CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_COMPLIANCE)); final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper( codeSnippet, this.packageName, @@ -580,7 +585,8 @@ this.localVariableTypeNames, this.localVariableModifiers, this.declaringTypeName, - this.lineSeparator + this.lineSeparator, + complianceVersion ); ICompilationUnit sourceUnit = new ICompilationUnit() { public char[] getFileName() { #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java,v retrieving revision 1.19 diff -u -r1.19 CodeSnippetTest.java --- src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java 28 Apr 2009 17:17:55 -0000 1.19 +++ src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java 11 May 2011 14:58:48 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 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,14 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.eval; +import java.util.Map; + import junit.framework.Test; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; import org.eclipse.jdt.internal.eval.EvaluationResult; import org.eclipse.jdt.internal.eval.IRequestor; @@ -43,6 +46,21 @@ public static Test suite() { return setupSuite(testClass()); } +public Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.ERROR); + return defaultOptions; +} /** * Tests code snippet that throws a checked exception. * (Regression test for 1G0T5XK)