01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.codeassist.select;
11:
12: /*
13: * Selection node build by the parser in any case it was intending to
14: * reduce a type reference containing the completion identifier as part
15: * of a qualified name.
16: * e.g.
17: *
18: * class X extends java.lang.[start]Object[end]
19: *
20: * ---> class X extends <SelectOnType:java.lang.Object>
21: *
22: */
23:
24: import org.eclipse.jdt.core.compiler.CharOperation;
25: import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
26: import org.eclipse.jdt.internal.compiler.lookup.Binding;
27: import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28: import org.eclipse.jdt.internal.compiler.lookup.Scope;
29: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
30:
31: public class SelectionOnQualifiedTypeReference extends
32: QualifiedTypeReference {
33: public SelectionOnQualifiedTypeReference(
34: char[][] previousIdentifiers, char[] selectionIdentifier,
35: long[] positions) {
36: super (CharOperation.arrayConcat(previousIdentifiers,
37: selectionIdentifier), positions);
38: }
39:
40: public void aboutToResolve(Scope scope) {
41: getTypeBinding(scope.parent); // step up from the ClassScope
42: }
43:
44: protected TypeBinding getTypeBinding(Scope scope) {
45: // it can be a package, type or member type
46: Binding binding = scope.getTypeOrPackage(tokens);
47: if (!binding.isValidBinding()) {
48: // tolerate some error cases
49: if (binding.problemId() == ProblemReasons.NotVisible) {
50: throw new SelectionNodeFound(binding);
51: }
52: scope.problemReporter().invalidType(this ,
53: (TypeBinding) binding);
54: throw new SelectionNodeFound();
55: }
56:
57: throw new SelectionNodeFound(binding);
58: }
59:
60: public StringBuffer printExpression(int indent, StringBuffer output) {
61:
62: output.append("<SelectOnType:"); //$NON-NLS-1$
63: for (int i = 0, length = tokens.length; i < length; i++) {
64: if (i > 0)
65: output.append('.');
66: output.append(tokens[i]);
67: }
68: return output.append('>');
69: }
70: }
|