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