1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.select;
14 * Selection node build by the parser in any case it was intending to
15 * reduce a type reference containing the selection identifier as a single
19 * class X extends [start]Object[end]
21 * ---> class X extends <SelectOnType:Object>
25 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
26 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
27 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
28 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
29 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
33 public class SelectionOnSingleTypeReference extends SingleTypeReference {
34 public SelectionOnSingleTypeReference(char[] source, long pos) {
37 public void aboutToResolve(Scope scope) {
38 getTypeBinding(scope.parent); // step up from the ClassScope
40 public TypeBinding getTypeBinding(Scope scope) {
41 // it can be a package, type or member type
42 Binding binding = scope.getTypeOrPackage(new char[][] {token});
43 if (!binding.isValidBinding()) {
44 scope.problemReporter().invalidType(this, (TypeBinding) binding);
45 throw new SelectionNodeFound();
48 throw new SelectionNodeFound(binding);
50 public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
51 super.resolveTypeEnclosing(scope, enclosingType);
53 // tolerate some error cases
54 if (binding == null ||
55 !(binding.isValidBinding() ||
56 binding.problemId() == ProblemReasons.NotVisible))
57 throw new SelectionNodeFound();
59 throw new SelectionNodeFound(binding);
61 public String toStringExpression(int tab){
63 return "<SelectOnType:" + new String(token) + ">" ; //$NON-NLS-2$ //$NON-NLS-1$