@@ -87,63 +87,58 @@ public LocatorResponse match(Name name, NodeSetWrapper nodeSet, MatchLocator loc
8787 return toResponse (IMPOSSIBLE_MATCH );
8888 }
8989
90- if (this .fieldLocator .matchesName (this .fieldLocator .pattern .name , name .toString ().toCharArray ())) {
91- if (this .fieldLocator .isDeclarationOfAccessedFieldsPattern
92- && this .fieldLocator .pattern instanceof DeclarationOfAccessedFieldsPattern doafp ) {
93- if (doafp .enclosingElement != null ) {
94- // we have an enclosing element to check
95- if (!DOMASTNodeUtils .isWithinRange (name , doafp .enclosingElement )) {
96- return toResponse (PatternLocator .IMPOSSIBLE_MATCH );
90+ if (!this .fieldLocator .matchesName (this .fieldLocator .pattern .name , name .toString ().toCharArray ())) {
91+ return toResponse (PatternLocator .IMPOSSIBLE_MATCH );
92+ }
93+ if (this .fieldLocator .isDeclarationOfAccessedFieldsPattern
94+ && this .fieldLocator .pattern instanceof DeclarationOfAccessedFieldsPattern doafp ) {
95+ if (doafp .enclosingElement != null ) {
96+ // we have an enclosing element to check
97+ if (!DOMASTNodeUtils .isWithinRange (name , doafp .enclosingElement )) {
98+ return toResponse (PatternLocator .IMPOSSIBLE_MATCH );
99+ }
100+ // We need to report the declaration, not the usage
101+ // TODO testDeclarationOfAccessedFields2
102+ IBinding b = name .resolveBinding ();
103+ IJavaElement je = b == null ? null : b .getJavaElement ();
104+ if (je != null && doafp .knownFields .includes (je )) {
105+ doafp .knownFields .remove (je );
106+ ISourceReference sr = je instanceof ISourceReference ? (ISourceReference ) je : null ;
107+ IResource r = null ;
108+ ISourceRange srg = null ;
109+ String elName = je .getElementName ();
110+ try {
111+ srg = sr .getSourceRange ();
112+ IJavaElement ancestor = je .getAncestor (IJavaElement .COMPILATION_UNIT );
113+ r = ancestor == null ? null : ancestor .getCorrespondingResource ();
114+ } catch (JavaModelException jme ) {
115+ // ignore
97116 }
98- // We need to report the declaration, not the usage
99- // TODO testDeclarationOfAccessedFields2
100- IBinding b = name .resolveBinding ();
101- IJavaElement je = b == null ? null : b .getJavaElement ();
102- if (je != null && doafp .knownFields .includes (je )) {
103- doafp .knownFields .remove (je );
104- ISourceReference sr = je instanceof ISourceReference ? (ISourceReference ) je : null ;
105- IResource r = null ;
106- ISourceRange srg = null ;
107- String elName = je .getElementName ();
117+ if (srg != null ) {
118+ int accuracy = this .fieldLocator .pattern .mustResolve ? PatternLocator .POSSIBLE_MATCH
119+ : PatternLocator .ACCURATE_MATCH ;
120+ FieldDeclarationMatch fdMatch = new FieldDeclarationMatch (je , accuracy ,
121+ srg .getOffset () + srg .getLength () - elName .length () - 1 , elName .length (),
122+ locator .getParticipant (), r );
108123 try {
109- srg = sr .getSourceRange ();
110- IJavaElement ancestor = je .getAncestor (IJavaElement .COMPILATION_UNIT );
111- r = ancestor == null ? null : ancestor .getCorrespondingResource ();
112- } catch (JavaModelException jme ) {
124+ locator .report (fdMatch );
125+ } catch (CoreException ce ) {
113126 // ignore
114127 }
115- if (srg != null ) {
116- int accuracy = this .fieldLocator .pattern .mustResolve ? PatternLocator .POSSIBLE_MATCH
117- : PatternLocator .ACCURATE_MATCH ;
118- FieldDeclarationMatch fdMatch = new FieldDeclarationMatch (je , accuracy ,
119- srg .getOffset () + srg .getLength () - elName .length () - 1 , elName .length (),
120- locator .getParticipant (), r );
121- try {
122- locator .report (fdMatch );
123- } catch (CoreException ce ) {
124- // ignore
125- }
126- }
127128 }
128- return toResponse (PatternLocator .IMPOSSIBLE_MATCH );
129129 }
130+ return toResponse (PatternLocator .IMPOSSIBLE_MATCH );
130131 }
132+ }
131133
132- if (!matchesFineGrain (name )) {
133- return toResponse (IMPOSSIBLE_MATCH );
134- }
135-
136- if (!this .fieldLocator .pattern .readAccess && this .fieldLocator .pattern .fineGrain == 0 && DOMLocalVariableLocator .isRead (name )) {
137- return toResponse (IMPOSSIBLE_MATCH );
138- }
139- if (!this .fieldLocator .pattern .writeAccess && DOMLocalVariableLocator .isWrite (name )) {
140- return toResponse (IMPOSSIBLE_MATCH );
141- }
134+ if (this .fieldLocator .pattern .fineGrain != 0 ? matchesFineGrain (name ) :
135+ ((this .fieldLocator .pattern .readAccess && DOMLocalVariableLocator .isRead (name ))
136+ || (this .fieldLocator .pattern .writeAccess && DOMLocalVariableLocator .isWrite (name )))) {
142137 int level = nodeSet .addMatch (name , this .fieldLocator .pattern .mustResolve ? PatternLocator .POSSIBLE_MATCH
143138 : PatternLocator .ACCURATE_MATCH );
144139 return toResponse (level , true );
145140 }
146- return toResponse (PatternLocator . IMPOSSIBLE_MATCH );
141+ return toResponse (IMPOSSIBLE_MATCH );
147142 }
148143
149144 private boolean matchesFineGrain (Name name ) {
0 commit comments