KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > select > SelectionOnQualifiedTypeReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.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 org.eclipse.jdt.core.compiler.CharOperation;
26 import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
27 import org.eclipse.jdt.internal.compiler.lookup.Binding;
28 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
29 import org.eclipse.jdt.internal.compiler.lookup.Scope;
30 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
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 protected 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 StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
56
57     output.append("<SelectOnType:"); //$NON-NLS-1$
58
for (int i = 0, length = tokens.length; i < length; i++) {
59         if (i > 0) output.append('.');
60         output.append(tokens[i]);
61     }
62     return output.append('>');
63 }
64 }
65
Popular Tags