View | Details | Raw Unified | Return to bug 110188
Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-1 / +45 lines)
Lines 3133-3139 Link Here
3133
public TypeReference createParameterizedSingleAssistTypeReference(TypeReference[] typeArguments, char[] assistName, long position) {
3133
public TypeReference createParameterizedSingleAssistTypeReference(TypeReference[] typeArguments, char[] assistName, long position) {
3134
	return this.createSingleAssistTypeReference(assistName, position);
3134
	return this.createSingleAssistTypeReference(assistName, position);
3135
}
3135
}
3136
3136
protected StringLiteral createStringLiteral(char[] token, int start, int end) {
3137
	if (start <= this.cursorLocation && this.cursorLocation <= end){
3138
		char[] source = this.scanner.source;
3139
		
3140
		int stringStart = start;
3141
		int stringEnd = end;
3142
		
3143
		// " could be as unicode \u0022
3144
		int pos = stringStart;
3145
		if(source[pos] == '\"') {
3146
			stringStart = pos + 1;
3147
		} else if(source[pos] == '\\' && source[pos+1] == 'u') {
3148
			pos += 2;
3149
			while (source[pos] == 'u') {
3150
				pos++;
3151
			}
3152
			stringStart = pos + 4;
3153
		}
3154
		pos = stringEnd;
3155
		if(source[pos] == '\"') {
3156
			stringEnd = pos - 1;
3157
		} else if(source.length > 5 && source[pos-4] == 'u') {
3158
			pos -= 5;
3159
			while (pos > -1 && source[pos] == 'u') {
3160
				pos--;
3161
			}
3162
			if(pos > -1 && source[pos] == '\\') {
3163
				stringEnd = pos - 1;
3164
			} 
3165
			
3166
		}
3167
		
3168
		CompletionOnStringLiteral stringLiteral = new CompletionOnStringLiteral(
3169
				token, 
3170
				stringStart, 
3171
				stringEnd);
3172
		
3173
		this.assistNode = stringLiteral;
3174
		this.restartRecovery = true;
3175
		this.lastCheckPoint = end;
3176
		
3177
		return stringLiteral;
3178
	}
3179
	return super.createStringLiteral(token, start, end);
3180
}
3137
public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int cursorLoc) {
3181
public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int cursorLoc) {
3138
3182
3139
	this.cursorLocation = cursorLoc;
3183
	this.cursorLocation = cursorLoc;
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java (-5 / +22 lines)
Lines 21-27 Link Here
21
 *  n  means completion behind the n-th character
21
 *  n  means completion behind the n-th character
22
 */
22
 */
23
import org.eclipse.jdt.core.compiler.*;
23
import org.eclipse.jdt.core.compiler.*;
24
import org.eclipse.jdt.core.compiler.InvalidInputException;
25
import org.eclipse.jdt.internal.compiler.parser.Scanner;
24
import org.eclipse.jdt.internal.compiler.parser.Scanner;
26
25
27
public class CompletionScanner extends Scanner {
26
public class CompletionScanner extends Scanner {
Lines 82-87 Link Here
82
	return super.getCurrentIdentifierSource();
81
	return super.getCurrentIdentifierSource();
83
}
82
}
84
83
84
public char[] getCurrentTokenSourceString() {
85
	if (this.completionIdentifier == null){
86
		if (this.cursorLocation+1 >= this.startPosition && this.cursorLocation < this.currentPosition){
87
			// remember actual identifier positions
88
			this.completedIdentifierStart = this.startPosition;
89
			this.completedIdentifierEnd = this.currentPosition - 1;
90
			if (this.withoutUnicodePtr != 0){			// check unicode scenario
91
				int length = this.cursorLocation - this.startPosition - this.unicodeCharSize;
92
				System.arraycopy(this.withoutUnicodeBuffer, 2, this.completionIdentifier = new char[length], 0, length);
93
			} else {
94
				// no char[] sharing around completionIdentifier, we want it to be unique so as to use identity checks	
95
				int length = this.cursorLocation - this.startPosition;
96
				System.arraycopy(this.source, this.startPosition + 1, (this.completionIdentifier = new char[length]), 0, length);
97
			}
98
			return this.completionIdentifier;
99
		}
100
	}
101
	return super.getCurrentTokenSourceString();
102
}
85
public int getNextToken() throws InvalidInputException {
103
public int getNextToken() throws InvalidInputException {
86
104
87
	this.wasAcr = false;
105
	this.wasAcr = false;
Lines 490-498 Link Here
490
						}
508
						}
491
						throw e; // rethrow
509
						throw e; // rethrow
492
					}
510
					}
493
					if (this.startPosition <= this.cursorLocation && this.cursorLocation <= this.currentPosition-1){
494
						throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_STRING);
495
					}
496
					return TokenNameStringLiteral;
511
					return TokenNameStringLiteral;
497
				case '/' :
512
				case '/' :
498
					{
513
					{
Lines 760-766 Link Here
760
public final void getNextUnicodeChar() throws InvalidInputException {
775
public final void getNextUnicodeChar() throws InvalidInputException {
761
	int temp = this.currentPosition; // the \ is already read
776
	int temp = this.currentPosition; // the \ is already read
762
	super.getNextUnicodeChar();
777
	super.getNextUnicodeChar();
763
	this.unicodeCharSize += (this.currentPosition - temp);
778
	if(this.cursorLocation > temp) {
779
		this.unicodeCharSize += (this.currentPosition - temp);
780
	}
764
	if (temp < this.cursorLocation && this.cursorLocation < this.currentPosition-1){
781
	if (temp < this.cursorLocation && this.cursorLocation < this.currentPosition-1){
765
		throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_UNICODE);
782
		throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_UNICODE);
766
	}
783
	}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionNodeDetector.java (+3 lines)
Lines 263-268 Link Here
263
	public boolean visit(SingleTypeReference singleTypeReference, ClassScope scope) {
263
	public boolean visit(SingleTypeReference singleTypeReference, ClassScope scope) {
264
		return this.visit(singleTypeReference);
264
		return this.visit(singleTypeReference);
265
	}
265
	}
266
	public boolean visit(StringLiteral stringLiteral, BlockScope scope) {
267
		return this.visit(stringLiteral);
268
	}
266
	public boolean visit(SuperReference superReference, BlockScope scope) {
269
	public boolean visit(SuperReference superReference, BlockScope scope) {
267
		return this.visit(superReference);
270
		return this.visit(superReference);
268
	}
271
	}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-3 / +6 lines)
Lines 6847-6857 Link Here
6847
					this.scanner.currentPosition - 1)); 
6847
					this.scanner.currentPosition - 1)); 
6848
			break;
6848
			break;
6849
		case TokenNameStringLiteral :
6849
		case TokenNameStringLiteral :
6850
			StringLiteral stringLiteral = new StringLiteral(
6850
			pushOnExpressionStack(
6851
				this.createStringLiteral(
6851
					this.scanner.getCurrentTokenSourceString(), 
6852
					this.scanner.getCurrentTokenSourceString(), 
6852
					this.scanner.startPosition, 
6853
					this.scanner.startPosition, 
6853
					this.scanner.currentPosition - 1); 
6854
					this.scanner.currentPosition - 1)); 
6854
			pushOnExpressionStack(stringLiteral); 
6855
			break;
6855
			break;
6856
		case TokenNamefalse :
6856
		case TokenNamefalse :
6857
			pushOnExpressionStack(
6857
			pushOnExpressionStack(
Lines 7383-7388 Link Here
7383
protected LocalDeclaration createLocalDeclaration(char[] localDeclarationName, int sourceStart, int sourceEnd) {
7383
protected LocalDeclaration createLocalDeclaration(char[] localDeclarationName, int sourceStart, int sourceEnd) {
7384
	return new LocalDeclaration(localDeclarationName, sourceStart, sourceEnd);
7384
	return new LocalDeclaration(localDeclarationName, sourceStart, sourceEnd);
7385
}
7385
}
7386
protected StringLiteral createStringLiteral(char[] token, int start, int end) {
7387
	return new StringLiteral(token, start, end);
7388
}
7386
protected RecoveredType currentRecoveryType() {
7389
protected RecoveredType currentRecoveryType() {
7387
	if(this.currentElement != null) {
7390
	if(this.currentElement != null) {
7388
		if(this.currentElement instanceof RecoveredType) {
7391
		if(this.currentElement instanceof RecoveredType) {
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-1 / +1 lines)
Lines 488-494 Link Here
488
		this.startPosition, 
488
		this.startPosition, 
489
		this.currentPosition - this.startPosition); 
489
		this.currentPosition - this.startPosition); 
490
}
490
}
491
public final char[] getCurrentTokenSourceString() {
491
public char[] getCurrentTokenSourceString() {
492
	//return the token REAL source (aka unicodes are precomputed).
492
	//return the token REAL source (aka unicodes are precomputed).
493
	//REMOVE the two " that are at the beginning and the end.
493
	//REMOVE the two " that are at the beginning and the end.
494
494
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnStringLiteral.java (+29 lines)
Added Link Here
1
package org.eclipse.jdt.internal.codeassist.complete;
2
3
import org.eclipse.jdt.internal.compiler.ast.StringLiteral;
4
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
5
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
6
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
7
8
public class CompletionOnStringLiteral extends StringLiteral {
9
10
	public CompletionOnStringLiteral(char[] token, int s, int e) {
11
		super(token, s, e);
12
	}
13
14
	public CompletionOnStringLiteral(int s, int e) {
15
		super(s,e);
16
	}
17
	public TypeBinding resolveType(ClassScope scope) {
18
		throw new CompletionNodeFound(this, null, scope);
19
	}
20
	public TypeBinding resolveType(BlockScope scope) {
21
		throw new CompletionNodeFound(this, null, scope);
22
	}
23
	
24
	public StringBuffer printExpression(int indent, StringBuffer output) {
25
		output.append("<CompletionOnString:"); //$NON-NLS-1$
26
		output = super.printExpression(indent, output);
27
		return output.append('>');
28
	}
29
}

Return to bug 110188