2020
2121import com .sun .source .tree .ExpressionTree ;
2222import com .sun .source .tree .NewArrayTree ;
23- import com .sun .source .tree .NewClassTree ;
2423import com .sun .source .tree .Tree ;
2524import com .sun .source .util .TreePath ;
2625import java .util .Collections ;
3534import org .netbeans .api .java .source .CompilationInfo ;
3635import org .netbeans .api .java .source .JavaSource ;
3736import org .netbeans .api .java .source .TreeMaker ;
37+ import org .netbeans .api .java .source .TypeMirrorHandle ;
3838import org .netbeans .api .java .source .WorkingCopy ;
3939import org .netbeans .modules .java .hints .spi .ErrorRule ;
4040import org .netbeans .spi .editor .hints .Fix ;
@@ -134,11 +134,11 @@ public void cancel() {
134134
135135 private static final class FixImpl extends JavaFix {
136136
137- private TypeMirror arrayTypeMirror ;
137+ private final TypeMirrorHandle arrayTypeMirror ;
138138
139139 public FixImpl (CompilationInfo info , TreePath tp , TypeMirror arrayType ) {
140140 super (info , tp );
141- this .arrayTypeMirror = arrayType ;
141+ this .arrayTypeMirror = TypeMirrorHandle . create ( arrayType ) ;
142142 }
143143
144144 @ Override
@@ -157,12 +157,18 @@ protected void performRewrite(TransformationContext tc) throws Exception {
157157 if (statementPath .getLeaf ().getKind () == Tree .Kind .VARIABLE ) {
158158 oldVariableTree = (VariableTree ) statementPath .getLeaf ();
159159
160- arrayTypeMirror = Utilities .resolveCapturedType (wc , arrayTypeMirror );
160+ TypeMirror arrayType = arrayTypeMirror .resolve (wc );
161+
162+ if (arrayType == null ) {
163+ return ; //cannot resolve
164+ }
165+
166+ arrayType = Utilities .resolveCapturedType (wc , arrayType );
161167
162168 VariableTree newVariableTree = make .Variable (
163169 oldVariableTree .getModifiers (),
164170 oldVariableTree .getName (),
165- make .ArrayType (make .Type (arrayTypeMirror )),
171+ make .ArrayType (make .Type (arrayType )),
166172 oldVariableTree .getInitializer ()
167173 );
168174 tc .getWorkingCopy ().rewrite (oldVariableTree , newVariableTree );
0 commit comments