View | Details | Raw Unified | Return to bug 345334 | Differences between
and this patch

Collapse All | Expand All

(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetEvaluator.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-17 Link Here
12
12
13
import java.util.Map;
13
import java.util.Map;
14
14
15
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.internal.compiler.ClassFile;
17
import org.eclipse.jdt.internal.compiler.ClassFile;
17
import org.eclipse.jdt.internal.compiler.Compiler;
18
import org.eclipse.jdt.internal.compiler.Compiler;
Lines 188-194 Link Here
188
			this.context.localVariableTypeNames,
189
			this.context.localVariableTypeNames,
189
			this.context.localVariableModifiers,
190
			this.context.localVariableModifiers,
190
			this.context.declaringTypeName,
191
			this.context.declaringTypeName,
191
			this.context.lineSeparator
192
			this.context.lineSeparator,
193
			CompilerOptions.versionToJdkLevel(this.options.get(JavaCore.COMPILER_SOURCE))
192
		);
194
		);
193
195
194
	}
196
	}
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetToCuMapper.java (-3 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-23 Link Here
16
import org.eclipse.jdt.core.Flags;
16
import org.eclipse.jdt.core.Flags;
17
import org.eclipse.jdt.core.Signature;
17
import org.eclipse.jdt.core.Signature;
18
import org.eclipse.jdt.core.compiler.*;
18
import org.eclipse.jdt.core.compiler.*;
19
import org.eclipse.jdt.core.compiler.IProblem;
20
import org.eclipse.jdt.internal.codeassist.ISelectionRequestor;
19
import org.eclipse.jdt.internal.codeassist.ISelectionRequestor;
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
21
22
/**
22
/**
23
 * Maps back and forth a code snippet to a compilation unit.
23
 * Maps back and forth a code snippet to a compilation unit.
Lines 56-66 Link Here
56
	// Mapping of external local variables
56
	// Mapping of external local variables
57
	char[][] localVarNames;
57
	char[][] localVarNames;
58
	char[][] localVarTypeNames;
58
	char[][] localVarTypeNames;
59
	
60
	long sourceVersion;
59
61
60
/**
62
/**
61
 * Rebuild source in presence of external local variables
63
 * Rebuild source in presence of external local variables
62
 */
64
 */
63
 public CodeSnippetToCuMapper(char[] codeSnippet, char[] packageName, char[][] imports, char[] className, char[] varClassName, char[][] localVarNames, char[][] localVarTypeNames, int[] localVarModifiers, char[] declaringTypeName, String lineSeparator) {
65
 public CodeSnippetToCuMapper(
66
		char[] codeSnippet,
67
		char[] packageName,
68
		char[][] imports,
69
		char[] className,
70
		char[] varClassName,
71
		char[][] localVarNames,
72
		char[][] localVarTypeNames,
73
		int[] localVarModifiers,
74
		char[] declaringTypeName,
75
		String lineSeparator,
76
		long sourceVersion) {
64
	this.codeSnippet = codeSnippet;
77
	this.codeSnippet = codeSnippet;
65
	this.snippetPackageName = packageName;
78
	this.snippetPackageName = packageName;
66
	this.snippetImports = imports;
79
	this.snippetImports = imports;
Lines 69-74 Link Here
69
	this.localVarNames = localVarNames;
82
	this.localVarNames = localVarNames;
70
	this.localVarTypeNames = localVarTypeNames;
83
	this.localVarTypeNames = localVarTypeNames;
71
	this.snippetDeclaringTypeName = declaringTypeName;
84
	this.snippetDeclaringTypeName = declaringTypeName;
85
	this.sourceVersion = sourceVersion;
72
	buildCUSource(lineSeparator);
86
	buildCUSource(lineSeparator);
73
}
87
}
74
private void buildCUSource(String lineSeparator) {
88
private void buildCUSource(String lineSeparator) {
Lines 129-134 Link Here
129
		}
143
		}
130
	}
144
	}
131
	// run() method declaration
145
	// run() method declaration
146
	if (this.sourceVersion >= ClassFileConstants.JDK1_6) {
147
		buffer.append("@Override "); //$NON-NLS-1$
148
	}
132
	buffer.append("public void run() throws Throwable {").append(lineSeparator); //$NON-NLS-1$
149
	buffer.append("public void run() throws Throwable {").append(lineSeparator); //$NON-NLS-1$
133
	this.lineNumberOffset++;
150
	this.lineNumberOffset++;
134
	this.startPosOffset = buffer.length();
151
	this.startPosOffset = buffer.length();
(-)eval/org/eclipse/jdt/internal/eval/EvaluationContext.java (-3 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.jdt.core.CompletionRequestor;
17
import org.eclipse.jdt.core.CompletionRequestor;
18
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.JavaCore;
19
import org.eclipse.jdt.core.WorkingCopyOwner;
20
import org.eclipse.jdt.core.WorkingCopyOwner;
20
import org.eclipse.jdt.core.compiler.*;
21
import org.eclipse.jdt.core.compiler.*;
21
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
22
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
Lines 28-33 Link Here
28
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
29
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
29
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
30
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
30
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
31
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
32
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
31
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
33
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
32
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
34
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
33
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
35
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Lines 128-133 Link Here
128
		// Do nothing
130
		// Do nothing
129
	}
131
	}
130
	final char[] className = "CodeSnippetCompletion".toCharArray(); //$NON-NLS-1$
132
	final char[] className = "CodeSnippetCompletion".toCharArray(); //$NON-NLS-1$
133
	final long sourceVersion = CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_SOURCE));
131
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
134
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
132
		codeSnippet,
135
		codeSnippet,
133
		this.packageName,
136
		this.packageName,
Lines 138-144 Link Here
138
		this.localVariableTypeNames,
141
		this.localVariableTypeNames,
139
		this.localVariableModifiers,
142
		this.localVariableModifiers,
140
		this.declaringTypeName,
143
		this.declaringTypeName,
141
		this.lineSeparator
144
		this.lineSeparator,
145
		sourceVersion
142
	);
146
	);
143
	ICompilationUnit sourceUnit = new ICompilationUnit() {
147
	ICompilationUnit sourceUnit = new ICompilationUnit() {
144
		public char[] getFileName() {
148
		public char[] getFileName() {
Lines 570-575 Link Here
570
	WorkingCopyOwner owner) {
574
	WorkingCopyOwner owner) {
571
575
572
	final char[] className = "CodeSnippetSelection".toCharArray(); //$NON-NLS-1$
576
	final char[] className = "CodeSnippetSelection".toCharArray(); //$NON-NLS-1$
577
	final long sourceVersion = CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_SOURCE));
573
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
578
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
574
		codeSnippet,
579
		codeSnippet,
575
		this.packageName,
580
		this.packageName,
Lines 580-586 Link Here
580
		this.localVariableTypeNames,
585
		this.localVariableTypeNames,
581
		this.localVariableModifiers,
586
		this.localVariableModifiers,
582
		this.declaringTypeName,
587
		this.declaringTypeName,
583
		this.lineSeparator
588
		this.lineSeparator,
589
		sourceVersion
584
	);
590
	);
585
	ICompilationUnit sourceUnit = new ICompilationUnit() {
591
	ICompilationUnit sourceUnit = new ICompilationUnit() {
586
		public char[] getFileName() {
592
		public char[] getFileName() {
(-)src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.eval;
11
package org.eclipse.jdt.core.tests.eval;
12
12
13
import java.util.Map;
14
13
import junit.framework.Test;
15
import junit.framework.Test;
14
16
15
import org.eclipse.jdt.core.compiler.CategorizedProblem;
17
import org.eclipse.jdt.core.compiler.CategorizedProblem;
16
import org.eclipse.jdt.core.compiler.IProblem;
18
import org.eclipse.jdt.core.compiler.IProblem;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
18
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
21
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
19
import org.eclipse.jdt.internal.eval.EvaluationResult;
22
import org.eclipse.jdt.internal.eval.EvaluationResult;
20
import org.eclipse.jdt.internal.eval.IRequestor;
23
import org.eclipse.jdt.internal.eval.IRequestor;
Lines 43-48 Link Here
43
public static Test suite() {
46
public static Test suite() {
44
	return setupSuite(testClass());
47
	return setupSuite(testClass());
45
}
48
}
49
public Map getCompilerOptions() {
50
	Map defaultOptions = super.getCompilerOptions();
51
	defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
52
	defaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
53
	defaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
54
	defaultOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
55
	defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
56
	defaultOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
57
	defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING);
58
	defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
59
	defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING);
60
	defaultOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.ERROR);
61
	defaultOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.ERROR);
62
	return defaultOptions;
63
}
46
/**
64
/**
47
 * Tests code snippet that throws a checked exception.
65
 * Tests code snippet that throws a checked exception.
48
 * (Regression test for 1G0T5XK)
66
 * (Regression test for 1G0T5XK)

Return to bug 345334