KickJava   Java API By Example, From Geeks To Geeks.

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


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.select;
12
13 import org.eclipse.jdt.internal.compiler.ast.*;
14 import org.eclipse.jdt.internal.compiler.lookup.*;
15
16 /**
17  * Node representing a Javadoc comment including code selection.
18  */

19 public class SelectionJavadoc extends Javadoc {
20
21     Expression selectedNode;
22
23     public SelectionJavadoc(int sourceStart, int sourceEnd) {
24         super(sourceStart, sourceEnd);
25     }
26
27     /* (non-Javadoc)
28      * @see org.eclipse.jdt.internal.compiler.ast.Javadoc#print(int, java.lang.StringBuffer)
29      */

30     public StringBuffer JavaDoc print(int indent, StringBuffer JavaDoc output) {
31         super.print(indent, output);
32         if (this.selectedNode != null) {
33             String JavaDoc selectedString = null;
34             if (this.selectedNode instanceof JavadocFieldReference) {
35                 JavadocFieldReference fieldRef = (JavadocFieldReference) this.selectedNode;
36                 if (fieldRef.methodBinding != null) {
37                     selectedString = "<SelectOnMethod:"; //$NON-NLS-1$
38
} else {
39                     selectedString = "<SelectOnField:"; //$NON-NLS-1$
40
}
41             } else if (this.selectedNode instanceof JavadocMessageSend) {
42                 selectedString = "<SelectOnMethod:"; //$NON-NLS-1$
43
} else if (this.selectedNode instanceof JavadocAllocationExpression) {
44                 selectedString = "<SelectOnConstructor:"; //$NON-NLS-1$
45
} else if (this.selectedNode instanceof JavadocSingleNameReference) {
46                 selectedString = "<SelectOnLocalVariable:"; //$NON-NLS-1$
47
} else if (this.selectedNode instanceof JavadocSingleTypeReference) {
48                 JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) this.selectedNode;
49                 if (typeRef.packageBinding == null) {
50                     selectedString = "<SelectOnType:"; //$NON-NLS-1$
51
}
52             } else if (this.selectedNode instanceof JavadocQualifiedTypeReference) {
53                 JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) this.selectedNode;
54                 if (typeRef.packageBinding == null) {
55                     selectedString = "<SelectOnType:"; //$NON-NLS-1$
56
}
57             } else {
58                 selectedString = "<SelectOnType:"; //$NON-NLS-1$
59
}
60             int pos = output.length()-3;
61             output.replace(pos-2,pos, selectedString+selectedNode+'>');
62         }
63         return output;
64     }
65
66     /**
67      * Resolve selected node if not null and throw exception to let clients know
68      * that it has been found.
69      *
70      * @throws SelectionNodeFound
71      */

72     private void internalResolve(Scope scope) {
73         if (this.selectedNode != null) {
74             switch (scope.kind) {
75                 case Scope.CLASS_SCOPE:
76                     this.selectedNode.resolveType((ClassScope)scope);
77                     break;
78                 case Scope.METHOD_SCOPE:
79                     this.selectedNode.resolveType((MethodScope)scope);
80                     break;
81             }
82             Binding binding = null;
83             if (this.selectedNode instanceof JavadocFieldReference) {
84                 JavadocFieldReference fieldRef = (JavadocFieldReference) this.selectedNode;
85                 binding = fieldRef.binding;
86                 if (binding == null && fieldRef.methodBinding != null) {
87                     binding = fieldRef.methodBinding;
88                 }
89             } else if (this.selectedNode instanceof JavadocMessageSend) {
90                 binding = ((JavadocMessageSend) this.selectedNode).binding;
91             } else if (this.selectedNode instanceof JavadocAllocationExpression) {
92                 binding = ((JavadocAllocationExpression) this.selectedNode).binding;
93             } else if (this.selectedNode instanceof JavadocSingleNameReference) {
94                 binding = ((JavadocSingleNameReference) this.selectedNode).binding;
95             } else if (this.selectedNode instanceof JavadocSingleTypeReference) {
96                 JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) this.selectedNode;
97                 if (typeRef.packageBinding == null) {
98                     binding = typeRef.resolvedType;
99                 }
100             } else if (this.selectedNode instanceof JavadocQualifiedTypeReference) {
101                 JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) this.selectedNode;
102                 if (typeRef.packageBinding == null) {
103                     binding = typeRef.resolvedType;
104                 }
105             } else {
106                 binding = this.selectedNode.resolvedType;
107             }
108             throw new SelectionNodeFound(binding);
109         }
110     }
111
112     /**
113      * Resolve selected node if not null and throw exception to let clients know
114      * that it has been found.
115      *
116      * @throws SelectionNodeFound
117      */

118     public void resolve(ClassScope scope) {
119         internalResolve(scope);
120     }
121
122     /**
123      * Resolve selected node if not null and throw exception to let clients know
124      * that it has been found.
125      *
126      * @throws SelectionNodeFound
127      */

128     public void resolve(MethodScope scope) {
129         internalResolve(scope);
130     }
131
132 }
133
Popular Tags