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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+35 lines)
Lines 923-928 Link Here
923
			requestor.getResults());
923
			requestor.getResults());
924
}
924
}
925
925
926
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141518
927
public void testEvaluationContextCompletion5() throws JavaModelException {
928
	this.workingCopies = new ICompilationUnit[1];
929
	this.workingCopies[0] = getWorkingCopy(
930
		"/Completion/src/test/TestEvaluationContextCompletion5.java",
931
		"package test;"+
932
		"public class TestEvaluationContextCompletion5 {\n"+
933
		"}");
934
	
935
	String start = "someVariable.to";
936
	IJavaProject javaProject = getJavaProject("Completion");
937
	IEvaluationContext context = javaProject.newEvaluationContext();
938
	
939
	context.newVariable( "Object", "someVariable", null );
940
	
941
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, false);
942
	context.codeComplete(start, start.length(), requestor, this.wcOwner);
943
	
944
	int startOffset = start.length() - 2;
945
	int endOffset = startOffset + 2 ;
946
	
947
	assertResults(
948
			"completion offset="+endOffset+"\n"+
949
			"completion range=["+startOffset+", "+(endOffset-1)+"]\n"+
950
			"completion token=\"to\"\n"+
951
			"completion token kind=TOKEN_KIND_NAME\n"+
952
			"expectedTypesSignatures=null\n"+
953
			"expectedTypesKeys=null",
954
            requestor.getContext());
955
    
956
	assertResults(
957
			"toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED)+"}",
958
			requestor.getResults());
959
}
960
926
/**
961
/**
927
 * Ensures that completion is not case sensitive
962
 * Ensures that completion is not case sensitive
928
 */
963
 */
(-)eval/org/eclipse/jdt/internal/eval/EvaluationContext.java (+39 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.eval;
11
package org.eclipse.jdt.internal.eval;
12
12
13
import java.util.Locale;
13
import java.util.Map;
14
import java.util.Map;
14
15
15
import org.eclipse.jdt.core.CompletionRequestor;
16
import org.eclipse.jdt.core.CompletionRequestor;
Lines 20-28 Link Here
20
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
21
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
21
import org.eclipse.jdt.internal.compiler.ClassFile;
22
import org.eclipse.jdt.internal.compiler.ClassFile;
22
import org.eclipse.jdt.internal.compiler.IProblemFactory;
23
import org.eclipse.jdt.internal.compiler.IProblemFactory;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
23
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
26
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
24
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
27
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
25
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
28
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
29
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
26
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
30
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
27
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
31
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
28
import org.eclipse.jdt.internal.core.SearchableEnvironment;
32
import org.eclipse.jdt.internal.core.SearchableEnvironment;
Lines 98-103 Link Here
98
 *		set of options used to configure the code assist engine.
102
 *		set of options used to configure the code assist engine.
99
 */
103
 */
100
public void complete(char[] codeSnippet, int completionPosition, SearchableEnvironment environment, CompletionRequestor requestor, Map options, IJavaProject project) {
104
public void complete(char[] codeSnippet, int completionPosition, SearchableEnvironment environment, CompletionRequestor requestor, Map options, IJavaProject project) {
105
	try {
106
		IRequestor variableRequestor = new IRequestor() {
107
			public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
108
				// Do nothing
109
				return true;
110
			}
111
			public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) {
112
				// Do nothing
113
			}
114
		};
115
		this.evaluateVariables(environment, options, variableRequestor, new DefaultProblemFactory(Locale.getDefault()));
116
	} catch (InstallException e) {
117
		// Do nothing
118
	}
101
	final char[] className = "CodeSnippetCompletion".toCharArray(); //$NON-NLS-1$
119
	final char[] className = "CodeSnippetCompletion".toCharArray(); //$NON-NLS-1$
102
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
120
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
103
		codeSnippet, 
121
		codeSnippet, 
Lines 125-131 Link Here
125
			return null;
143
			return null;
126
		}
144
		}
127
	};
145
	};
146
	
128
	CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project);
147
	CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project);
148
	
149
	if (this.installedVars != null) {
150
		IBinaryType binaryType = this.getRootCodeSnippetBinary();
151
		if (binaryType != null) {
152
			engine.lookupEnvironment.cacheBinaryType(binaryType, null /*no access restriction*/);
153
		}
154
		
155
		ClassFile[] classFiles = installedVars.classFiles;
156
		for (int i = 0; i < classFiles.length; i++) {
157
			ClassFile classFile = classFiles[i];
158
			IBinaryType binary = null;
159
			try {
160
				binary = new ClassFileReader(classFile.getBytes(), null);
161
			} catch (ClassFormatException e) {
162
				e.printStackTrace(); // Should never happen since we compiled this type
163
			}
164
			engine.lookupEnvironment.cacheBinaryType(binary, null /*no access restriction*/);
165
		}
166
	}
167
	
129
	engine.complete(sourceUnit, mapper.startPosOffset + completionPosition, mapper.startPosOffset);
168
	engine.complete(sourceUnit, mapper.startPosOffset + completionPosition, mapper.startPosOffset);
130
}
169
}
131
/**
170
/**

Return to bug 141518