KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 import org.eclipse.jdt.internal.compiler.ast.Expression;
14 import org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference;
15 import org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
18 import org.eclipse.jdt.internal.compiler.lookup.Scope;
19 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
20
21 public class CompletionOnJavadocFieldReference extends JavadocFieldReference implements CompletionOnJavadoc {
22 // public boolean completionInText;
23
public int completionFlags = JAVADOC;
24     public int separatorPosition;
25
26     public CompletionOnJavadocFieldReference(Expression receiver, int tag, int position, int separatorPos, char[] name) {
27         super(null, (((long)position)<<32)+position-1);
28         this.receiver = receiver;
29         this.tagSourceStart = position;
30         this.tagSourceEnd = position;
31         this.tagValue = tag;
32         this.separatorPosition = separatorPos;
33     }
34
35     public CompletionOnJavadocFieldReference(JavadocFieldReference fieldRef, int position, char[] name) {
36         super(fieldRef.token, fieldRef.nameSourcePosition);
37         this.receiver = fieldRef.receiver;
38         this.separatorPosition = position;
39         this.tagSourceStart = fieldRef.tagSourceStart;
40         this.tagSourceEnd = fieldRef.tagSourceEnd;
41         this.tagValue = fieldRef.tagValue;
42     }
43
44     public CompletionOnJavadocFieldReference(JavadocMessageSend msgSend, int position) {
45         super(msgSend.selector, ((msgSend.nameSourcePosition>>32)<<32)+msgSend.sourceEnd);
46         this.receiver = msgSend.receiver;
47         this.separatorPosition = position;
48         this.tagSourceStart = msgSend.tagSourceStart;
49         this.tagSourceEnd = msgSend.tagSourceEnd;
50         this.tagValue = msgSend.tagValue;
51     }
52
53     /**
54      * @param flags The completionFlags to set.
55      */

56     public void addCompletionFlags(int flags) {
57         this.completionFlags |= flags;
58     }
59
60     public boolean completeAnException() {
61         return (this.completionFlags & EXCEPTION) != 0;
62     }
63
64     public boolean completeInText() {
65         return (this.completionFlags & TEXT) != 0;
66     }
67
68     public boolean completeBaseTypes() {
69         return (this.completionFlags & BASE_TYPES) != 0;
70     }
71
72     public boolean completeFormalReference() {
73         return (this.completionFlags & FORMAL_REFERENCE) != 0;
74     }
75
76     /**
77      * Get completion node flags.
78      *
79      * @return int Flags of the javadoc completion node.
80      */

81     public int getCompletionFlags() {
82         return this.completionFlags;
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference#internalResolveType(org.eclipse.jdt.internal.compiler.lookup.Scope)
87      */

88     protected TypeBinding internalResolveType(Scope scope) {
89
90         if (this.token != null) {
91             return super.internalResolveType(scope);
92         }
93         
94         // Resolve only receiver
95
if (this.receiver == null) {
96             this.receiverType = scope.enclosingSourceType();
97         } else if (scope.kind == Scope.CLASS_SCOPE) {
98             this.receiverType = this.receiver.resolveType((ClassScope) scope);
99         } else {
100             this.receiverType = this.receiver.resolveType((BlockScope)scope);
101         }
102         return null;
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference#printExpression(int, java.lang.StringBuffer)
107      */

108     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
109         output.append("<CompleteOnJavadocFieldReference:"); //$NON-NLS-1$
110
super.printExpression(indent, output);
111         indent++;
112         if (this.completionFlags > 0) {
113             output.append('\n');
114             for (int i=0; i<indent; i++) output.append('\t');
115             output.append("infos:"); //$NON-NLS-1$
116
char separator = 0;
117             if (completeAnException()) {
118                 output.append("exception"); //$NON-NLS-1$
119
separator = ',';
120             }
121             if (completeInText()) {
122                 if (separator != 0) output.append(separator);
123                 output.append("text"); //$NON-NLS-1$
124
separator = ',';
125             }
126             if (completeBaseTypes()) {
127                 if (separator != 0) output.append(separator);
128                 output.append("base types"); //$NON-NLS-1$
129
separator = ',';
130             }
131             if (completeFormalReference()) {
132                 if (separator != 0) output.append(separator);
133                 output.append("formal reference"); //$NON-NLS-1$
134
separator = ',';
135             }
136             output.append('\n');
137         }
138         indent--;
139         for (int i=0; i<indent; i++) output.append('\t');
140         return output.append('>');
141     }
142 }
143
Popular Tags