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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor2.java (-13 / +6 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.dom.PrefixExpression.Operator;
19
import org.eclipse.jdt.core.dom.PrefixExpression.Operator;
20
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
20
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
22
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jdt.internal.compiler.parser.Scanner;
23
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
24
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
24
import org.eclipse.jdt.internal.formatter.align.Alignment;
25
import org.eclipse.jdt.internal.formatter.align.Alignment;
Lines 66-86 Link Here
66
	public Scribe2 scribe;
67
	public Scribe2 scribe;
67
68
68
	public CodeFormatterVisitor2(DefaultCodeFormatterOptions preferences, Map settings, int offset, int length, CompilationUnit unit) {
69
	public CodeFormatterVisitor2(DefaultCodeFormatterOptions preferences, Map settings, int offset, int length, CompilationUnit unit) {
69
		if (settings != null) {
70
		long sourceLevel = settings == null
70
			Object assertModeSetting = settings.get(JavaCore.COMPILER_SOURCE);
71
			? ClassFileConstants.JDK1_3
71
			long sourceLevel = ClassFileConstants.JDK1_3;
72
			: CompilerOptions.versionToJdkLevel(settings.get(JavaCore.COMPILER_SOURCE));
72
			if (JavaCore.VERSION_1_4.equals(assertModeSetting)) {
73
		this.localScanner = new Scanner(true, false, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
73
				sourceLevel = ClassFileConstants.JDK1_4;
74
			} else if (JavaCore.VERSION_1_5.equals(assertModeSetting)) {
75
				sourceLevel = ClassFileConstants.JDK1_5;
76
			}		
77
			this.localScanner = new Scanner(true, false, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
78
		} else {
79
			this.localScanner = new Scanner(true, false, false/*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
80
		}
81
		
74
		
82
		this.preferences = preferences;
75
		this.preferences = preferences;
83
		this.scribe = new Scribe2(this, settings, offset, length, unit);
76
		this.scribe = new Scribe2(this, sourceLevel, offset, length, unit);
84
	}
77
	}
85
78
86
	private boolean commentStartsBlock(int start, int end) {
79
	private boolean commentStartsBlock(int start, int end) {
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-16 / +2 lines)
Lines 11-24 Link Here
11
package org.eclipse.jdt.internal.formatter;
11
package org.eclipse.jdt.internal.formatter;
12
12
13
import java.util.Arrays;
13
import java.util.Arrays;
14
import java.util.Map;
15
14
16
import org.eclipse.jdt.core.JavaCore;
17
import org.eclipse.jdt.core.compiler.CharOperation;
15
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.InvalidInputException;
16
import org.eclipse.jdt.core.compiler.InvalidInputException;
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
17
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
import org.eclipse.jdt.internal.compiler.ast.Annotation;
18
import org.eclipse.jdt.internal.compiler.ast.Annotation;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
19
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
23
import org.eclipse.jdt.internal.compiler.parser.Scanner;
20
import org.eclipse.jdt.internal.compiler.parser.Scanner;
24
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
21
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
Lines 80-98 Link Here
80
    /** indent empty lines*/
77
    /** indent empty lines*/
81
    private final boolean indentEmptyLines;
78
    private final boolean indentEmptyLines;
82
    
79
    
83
	Scribe(CodeFormatterVisitor formatter, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
80
	Scribe(CodeFormatterVisitor formatter, long sourceLevel, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
84
		if (settings != null) {
81
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
85
			Object sourceLevelOption = settings.get(JavaCore.COMPILER_SOURCE);
86
			long sourceLevel = ClassFileConstants.JDK1_3;
87
			if (JavaCore.VERSION_1_4.equals(sourceLevelOption)) {
88
				sourceLevel = ClassFileConstants.JDK1_4;
89
			} else if (JavaCore.VERSION_1_5.equals(sourceLevelOption)) {
90
				sourceLevel = ClassFileConstants.JDK1_5;
91
			}
92
			this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
93
		} else {
94
			this.scanner = new Scanner(true, true, false/*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
95
		}
96
		this.formatter = formatter;
82
		this.formatter = formatter;
97
		this.pageWidth = formatter.preferences.page_width;
83
		this.pageWidth = formatter.preferences.page_width;
98
		this.tabLength = formatter.preferences.tab_size;
84
		this.tabLength = formatter.preferences.tab_size;
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-13 / +6 lines)
Lines 103-108 Link Here
103
import org.eclipse.jdt.internal.compiler.ast.WhileStatement;
103
import org.eclipse.jdt.internal.compiler.ast.WhileStatement;
104
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
104
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
105
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
105
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
106
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
106
import org.eclipse.jdt.internal.compiler.impl.Constant;
107
import org.eclipse.jdt.internal.compiler.impl.Constant;
107
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
108
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
108
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
109
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
Lines 173-193 Link Here
173
	public Scribe scribe;
174
	public Scribe scribe;
174
175
175
	public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
176
	public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
176
		if (settings != null) {
177
		long sourceLevel = settings == null
177
			Object assertModeSetting = settings.get(JavaCore.COMPILER_SOURCE);
178
			? ClassFileConstants.JDK1_3
178
			long sourceLevel = ClassFileConstants.JDK1_3;
179
			: CompilerOptions.versionToJdkLevel(settings.get(JavaCore.COMPILER_SOURCE));
179
			if (JavaCore.VERSION_1_4.equals(assertModeSetting)) {
180
		this.localScanner = new Scanner(true, false, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
180
				sourceLevel = ClassFileConstants.JDK1_4;
181
			} else if (JavaCore.VERSION_1_5.equals(assertModeSetting)) {
182
				sourceLevel = ClassFileConstants.JDK1_5;
183
			}		
184
			this.localScanner = new Scanner(true, false, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
185
		} else {
186
			this.localScanner = new Scanner(true, false, false/*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
187
		}
188
		
181
		
189
		this.preferences = preferences;
182
		this.preferences = preferences;
190
		this.scribe = new Scribe(this, settings, offset, length, codeSnippetParsingUtil);
183
		this.scribe = new Scribe(this, sourceLevel, offset, length, codeSnippetParsingUtil);
191
	}
184
	}
192
	
185
	
193
	/**
186
	/**
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe2.java (-16 / +2 lines)
Lines 14-29 Link Here
14
import java.util.Collections;
14
import java.util.Collections;
15
import java.util.Comparator;
15
import java.util.Comparator;
16
import java.util.List;
16
import java.util.List;
17
import java.util.Map;
18
17
19
import org.eclipse.jdt.core.JavaCore;
20
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.core.compiler.InvalidInputException;
19
import org.eclipse.jdt.core.compiler.InvalidInputException;
22
import org.eclipse.jdt.core.dom.ASTVisitor;
20
import org.eclipse.jdt.core.dom.ASTVisitor;
23
import org.eclipse.jdt.core.dom.Annotation;
21
import org.eclipse.jdt.core.dom.Annotation;
24
import org.eclipse.jdt.core.dom.Comment;
22
import org.eclipse.jdt.core.dom.Comment;
25
import org.eclipse.jdt.core.dom.CompilationUnit;
23
import org.eclipse.jdt.core.dom.CompilationUnit;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.compiler.parser.Scanner;
24
import org.eclipse.jdt.internal.compiler.parser.Scanner;
28
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
25
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
29
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
26
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
Lines 83-101 Link Here
83
    /** indent empty lines*/
80
    /** indent empty lines*/
84
    private final boolean indentEmptyLines;
81
    private final boolean indentEmptyLines;
85
    
82
    
86
	Scribe2(CodeFormatterVisitor2 formatter, Map settings, int offset, int length, CompilationUnit unit) {
83
	Scribe2(CodeFormatterVisitor2 formatter, long sourceLevel, int offset, int length, CompilationUnit unit) {
87
		if (settings != null) {
84
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
88
			Object sourceLevelOption = settings.get(JavaCore.COMPILER_SOURCE);
89
			long sourceLevel = ClassFileConstants.JDK1_3;
90
			if (JavaCore.VERSION_1_4.equals(sourceLevelOption)) {
91
				sourceLevel = ClassFileConstants.JDK1_4;
92
			} else if (JavaCore.VERSION_1_5.equals(sourceLevelOption)) {
93
				sourceLevel = ClassFileConstants.JDK1_5;
94
			}
95
			this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
96
		} else {
97
			this.scanner = new Scanner(true, true, false/*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
98
		}
99
		this.formatter = formatter;
85
		this.formatter = formatter;
100
		this.pageWidth = formatter.preferences.page_width;
86
		this.pageWidth = formatter.preferences.page_width;
101
		this.tabLength = formatter.preferences.tab_size;
87
		this.tabLength = formatter.preferences.tab_size;

Return to bug 152725