KickJava   Java API By Example, From Geeks To Geeks.

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


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 qualified name reference containing the assist identifier.
16  * e.g.
17  *
18  * class X {
19  * Y y;
20  * void foo() {
21  * y.fred.[start]ba[end]
22  * }
23  * }
24  *
25  * ---> class X {
26  * Y y;
27  * void foo() {
28  * <SelectOnName:y.fred.ba>
29  * }
30  * }
31  *
32  */

33
34 import org.eclipse.jdt.core.compiler.CharOperation;
35 import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
36 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
37 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
38 import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding;
39 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
40 import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
41 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
42
43 public class SelectionOnQualifiedNameReference extends QualifiedNameReference {
44
45 public SelectionOnQualifiedNameReference(char[][] previousIdentifiers, char[] selectionIdentifier, long[] positions) {
46     super(
47         CharOperation.arrayConcat(previousIdentifiers, selectionIdentifier),
48         positions,
49         (int) (positions[0] >>> 32),
50         (int) positions[positions.length - 1]);
51 }
52 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
53
54     output.append("<SelectOnName:"); //$NON-NLS-1$
55
for (int i = 0, length = tokens.length; i < length; i++) {
56         if (i > 0) output.append('.');
57         output.append(tokens[i]);
58     }
59     return output.append('>');
60 }
61 public TypeBinding resolveType(BlockScope scope) {
62     // it can be a package, type, member type, local variable or field
63
binding = scope.getBinding(tokens, this);
64     if (!binding.isValidBinding()) {
65         if (binding instanceof ProblemFieldBinding) {
66             // tolerate some error cases
67
if (binding.problemId() == ProblemReasons.NotVisible
68                     || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName
69                     || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation
70                     || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
71                 throw new SelectionNodeFound(binding);
72             }
73             scope.problemReporter().invalidField(this, (FieldBinding) binding);
74         } else if (binding instanceof ProblemReferenceBinding) {
75             // tolerate some error cases
76
if (binding.problemId() == ProblemReasons.NotVisible){
77                 throw new SelectionNodeFound(binding);
78             }
79             scope.problemReporter().invalidType(this, (TypeBinding) binding);
80         } else {
81             scope.problemReporter().unresolvableReference(this, binding);
82         }
83         throw new SelectionNodeFound();
84     }
85     throw new SelectionNodeFound(binding);
86 }
87 }
88
Popular Tags