5d49dfb5f4717ca1b5c7787c77c70b16d67dab92
[phpeclipse.git] /
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.select;
12
13 /*
14  * Selection node build by the parser in any case it was intending to
15  * reduce a type reference containing the completion identifier as part
16  * of a qualified name.
17  * e.g.
18  *
19  *      class X extends java.lang.[start]Object[end]
20  *
21  *      ---> class X extends <SelectOnType:java.lang.Object>
22  *
23  */
24  
25 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedTypeReference;
26 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
28 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
29 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
30 import net.sourceforge.phpdt.internal.compiler.util.CharOperation;
31
32 public class SelectionOnQualifiedTypeReference extends QualifiedTypeReference {
33 public SelectionOnQualifiedTypeReference(char[][] previousIdentifiers, char[] selectionIdentifier, long[] positions) {
34         super(
35                 CharOperation.arrayConcat(previousIdentifiers, selectionIdentifier),
36                 positions);
37 }
38 public void aboutToResolve(Scope scope) {
39         getTypeBinding(scope.parent); // step up from the ClassScope
40 }
41 public TypeBinding getTypeBinding(Scope scope) {
42         // it can be a package, type or member type
43         Binding binding = scope.getTypeOrPackage(tokens);
44         if (!binding.isValidBinding()) {
45                         // tolerate some error cases
46                         if (binding.problemId() == ProblemReasons.NotVisible){
47                                 throw new SelectionNodeFound(binding);
48                         }
49                 scope.problemReporter().invalidType(this, (TypeBinding) binding);
50                 throw new SelectionNodeFound();
51         }
52
53         throw new SelectionNodeFound(binding);
54 }
55 public String toStringExpression(int tab) {
56
57         StringBuffer buffer = new StringBuffer();
58         buffer.append("<SelectOnType:"); //$NON-NLS-1$
59         for (int i = 0, length = tokens.length; i < length; i++) {
60                 buffer.append(tokens[i]);
61                 if (i != length - 1)
62                         buffer.append("."); //$NON-NLS-1$
63         }
64         buffer.append(">"); //$NON-NLS-1$
65         return buffer.toString();
66 }
67 }