3333import org .eclipse .jdt .core .dom .ArrayInitializer ;
3434import org .eclipse .jdt .core .dom .CompilationUnit ;
3535import org .eclipse .jdt .core .dom .Expression ;
36+ import org .eclipse .jdt .core .dom .IAnnotationBinding ;
37+ import org .eclipse .jdt .core .dom .IMemberValuePairBinding ;
38+ import org .eclipse .jdt .core .dom .IMethodBinding ;
39+ import org .eclipse .jdt .core .dom .ITypeBinding ;
3640import org .eclipse .jdt .core .dom .MemberValuePair ;
3741import org .eclipse .jdt .core .dom .MethodDeclaration ;
3842import org .eclipse .jdt .core .dom .NormalAnnotation ;
3943import org .eclipse .jdt .core .dom .SimpleName ;
4044import org .eclipse .jdt .core .dom .SingleMemberAnnotation ;
45+ import org .eclipse .jdt .core .dom .StringLiteral ;
4146import org .eclipse .jdt .ui .JavaUI ;
4247import org .eclipse .jface .text .IRegion ;
4348import org .eclipse .jface .text .ITextViewer ;
4954import org .eclipse .wst .xml .core .internal .provisional .document .IDOMNode ;
5055
5156import net .harawata .mybatipse .Activator ;
57+ import net .harawata .mybatipse .MybatipseConstants ;
5258import net .harawata .mybatipse .mybatis .JavaMapperUtil .HasSelectAnnotation ;
5359import net .harawata .mybatipse .mybatis .JavaMapperUtil .ResultsAnnotationWithId ;
5460import net .harawata .mybatipse .mybatis .MapperNamespaceCache ;
@@ -211,7 +217,6 @@ public boolean visit(NormalAnnotation anno)
211217 return false ;
212218 }
213219
214- @ SuppressWarnings ("unchecked" )
215220 private void parseAnnotation (Annotation anno )
216221 {
217222 String name = anno .getTypeName ().getFullyQualifiedName ();
@@ -222,49 +227,84 @@ private void parseAnnotation(Annotation anno)
222227 }
223228 else if ("Results" .equals (name ))
224229 {
225- Expression expr = annotationValueAt (anno , "value" , offset );
226- if (expr == null )
227- return ;
228- List <Expression > resultAnnos ;
229- if (expr .getNodeType () == Expression .ARRAY_INITIALIZER )
230- {
231- resultAnnos = ((ArrayInitializer )expr ).expressions ();
232- }
233- else
230+ parseResults (anno );
231+ }
232+ else if (MybatipseConstants .PROVIDER_ANNOTATION_NAMES .contains (name ))
233+ {
234+ parseProvider (anno );
235+ }
236+ }
237+
238+ private void parseProvider (Annotation anno )
239+ {
240+ Expression expr = annotationValueAt (anno , "method" , offset );
241+ if (expr == null )
242+ return ;
243+ IAnnotationBinding annoBinding = anno .resolveAnnotationBinding ();
244+ for (IMemberValuePairBinding valuePair : annoBinding .getAllMemberValuePairs ())
245+ {
246+ String pairName = valuePair .getName ();
247+ if ("type" .equals (pairName ) || "value" .equals (pairName ))
234248 {
235- resultAnnos = Arrays .asList ((Expression )expr );
249+ String methodName = ((StringLiteral )expr ).getLiteralValue ();
250+ ITypeBinding providerClass = (ITypeBinding )valuePair .getValue ();
251+ for (IMethodBinding method : providerClass .getDeclaredMethods ())
252+ {
253+ if (methodName .equals (method .getName ()))
254+ {
255+ linkRegion = new Region (expr .getStartPosition (), expr .getLength ());
256+ hyperlink = new ToJavaHyperlink (method .getJavaElement (), linkRegion ,
257+ javaLinkLabel ("method" ));
258+ return ;
259+ }
260+ }
236261 }
237- for (Expression resultAnno : resultAnnos )
262+ }
263+ }
264+
265+ @ SuppressWarnings ("unchecked" )
266+ private void parseResults (Annotation anno )
267+ {
268+ Expression expr = annotationValueAt (anno , "value" , offset );
269+ if (expr == null )
270+ return ;
271+ List <Expression > resultAnnos ;
272+ if (expr .getNodeType () == Expression .ARRAY_INITIALIZER )
273+ {
274+ resultAnnos = ((ArrayInitializer )expr ).expressions ();
275+ }
276+ else
277+ {
278+ resultAnnos = Arrays .asList ((Expression )expr );
279+ }
280+ for (Expression resultAnno : resultAnnos )
281+ {
282+ if (isInRange (resultAnno , offset ))
238283 {
239- if (isInRange (resultAnno , offset ))
284+ createHyperlink ("select" ,
285+ expressionAt (annotationValueAt ((Annotation )annotationValueAt ((Annotation )resultAnno ,
286+ Arrays .asList ("one" , "many" ), offset ), "select" , offset ), offset ));
287+ if (hyperlink == null )
240288 {
241- createHyperlink ("select" ,
242- expressionAt (
243- annotationValueAt ((Annotation )annotationValueAt ((Annotation )resultAnno ,
244- Arrays .asList ("one" , "many" ), offset ), "select" , offset ),
245- offset ));
246- if (hyperlink == null )
289+ Expression propertyName = annotationValueAt ((Annotation )resultAnno , "property" ,
290+ offset );
291+ if (propertyName == null )
292+ return ;
293+ String returnType = method .resolveBinding ().getReturnType ().getQualifiedName ();
294+ if (returnType == null || "void" .equals (returnType ))
295+ return ;
296+ try
247297 {
248- Expression propertyName = annotationValueAt ((Annotation )resultAnno , "property" ,
249- offset );
250- if (propertyName == null )
251- return ;
252- String returnType = method .resolveBinding ().getReturnType ().getQualifiedName ();
253- if (returnType == null || "void" .equals (returnType ))
254- return ;
255- try
256- {
257- hyperlink = linkToJavaProperty (project , returnType ,
258- (String )propertyName .resolveConstantExpressionValue (),
259- new Region (propertyName .getStartPosition (), propertyName .getLength ()));
260- }
261- catch (JavaModelException e )
262- {
263- Activator .log (Status .ERROR , e .getMessage (), e );
264- }
298+ hyperlink = linkToJavaProperty (project , returnType ,
299+ (String )propertyName .resolveConstantExpressionValue (),
300+ new Region (propertyName .getStartPosition (), propertyName .getLength ()));
301+ }
302+ catch (JavaModelException e )
303+ {
304+ Activator .log (Status .ERROR , e .getMessage (), e );
265305 }
266- break ;
267306 }
307+ break ;
268308 }
269309 }
270310 }
0 commit comments