KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > complete > CompletionOnQualifiedNameReference


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.complete;
12
13 /*
14  * Completion node build by the parser in any case it was intending to
15  * reduce a qualified name reference containing the completion identifier.
16  * e.g.
17  *
18  * class X {
19  * Y y;
20  * void foo() {
21  * y.fred.ba[cursor]
22  * }
23  * }
24  *
25  * ---> class X {
26  * Y y;
27  * void foo() {
28  * <CompleteOnName:y.fred.ba>
29  * }
30  * }
31  *
32  * The source range of the completion node denotes the source range
33  * which should be replaced by the completion.
34  */

35
36 import org.eclipse.jdt.internal.compiler.ast.*;
37 import org.eclipse.jdt.internal.compiler.lookup.*;
38
39 public class CompletionOnQualifiedNameReference extends QualifiedNameReference {
40     public char[] completionIdentifier;
41     public boolean isInsideAnnotationAttribute;
42 public CompletionOnQualifiedNameReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions, boolean isInsideAnnotationAttribute) {
43     super(previousIdentifiers, positions, (int) (positions[0] >>> 32), (int) positions[positions.length - 1]);
44     this.completionIdentifier = completionIdentifier;
45     this.isInsideAnnotationAttribute = isInsideAnnotationAttribute;
46 }
47 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
48
49     output.append("<CompleteOnName:"); //$NON-NLS-1$
50
for (int i = 0; i < tokens.length; i++) {
51         output.append(tokens[i]);
52         output.append('.');
53     }
54     output.append(completionIdentifier).append('>');
55     return output;
56 }
57 public TypeBinding resolveType(BlockScope scope) {
58     // it can be a package, type, member type, local variable or field
59
binding = scope.getBinding(tokens, this);
60     if (!binding.isValidBinding()) {
61         if (binding instanceof ProblemFieldBinding) {
62             scope.problemReporter().invalidField(this, (FieldBinding) binding);
63         } else if (binding instanceof ProblemReferenceBinding) {
64             scope.problemReporter().invalidType(this, (TypeBinding) binding);
65         } else {
66             scope.problemReporter().unresolvableReference(this, binding);
67         }
68         
69         if (binding.problemId() == ProblemReasons.NotFound) {
70             throw new CompletionNodeFound(this, binding, scope);
71         }
72         
73         throw new CompletionNodeFound();
74     }
75     
76     throw new CompletionNodeFound(this, binding, scope);
77 }
78 }
79
Popular Tags