/
CompletionOnReferenceExpressionName.java
81 lines (73 loc) · 3.07 KB
/
CompletionOnReferenceExpressionName.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
* Copyright (c) 2014, 2017 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.codeassist.complete;
import org.eclipse.jdt.internal.compiler.ast.ReferenceExpression;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
public class CompletionOnReferenceExpressionName extends ReferenceExpression {
public CompletionOnReferenceExpressionName(Scanner scanner) {
super(scanner);
}
@Override
public TypeBinding resolveType(BlockScope scope) {
final CompilerOptions compilerOptions = scope.compilerOptions();
TypeBinding lhsType;
boolean typeArgumentsHaveErrors;
this.constant = Constant.NotAConstant;
lhsType = this.lhs.resolveType(scope);
if (this.typeArguments != null) {
int length = this.typeArguments.length;
typeArgumentsHaveErrors = compilerOptions.sourceLevel < ClassFileConstants.JDK1_5;
this.resolvedTypeArguments = new TypeBinding[length];
for (int i = 0; i < length; i++) {
TypeReference typeReference = this.typeArguments[i];
if ((this.resolvedTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) {
typeArgumentsHaveErrors = true;
}
if (typeArgumentsHaveErrors && typeReference instanceof Wildcard) { // resolveType on wildcard always return null above, resolveTypeArgument is the real workhorse.
scope.problemReporter().illegalUsageOfWildcard(typeReference);
}
}
if (typeArgumentsHaveErrors || lhsType == null)
throw new CompletionNodeFound();
}
if (lhsType != null && lhsType.isValidBinding())
throw new CompletionNodeFound(this, lhsType, scope);
throw new CompletionNodeFound();
}
@Override
public StringBuffer printExpression(int tab, StringBuffer output) {
output.append("<CompletionOnReferenceExpressionName:"); //$NON-NLS-1$
this.lhs.print(0, output);
output.append("::"); //$NON-NLS-1$
if (this.typeArguments != null) {
output.append('<');
int max = this.typeArguments.length - 1;
for (int j = 0; j < max; j++) {
this.typeArguments[j].print(0, output);
output.append(", ");//$NON-NLS-1$
}
this.typeArguments[max].print(0, output);
output.append('>');
}
output.append(this.selector);
return output.append('>');
}
}