Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.NewArrayTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import java.util.Collections;
Expand All @@ -35,6 +34,7 @@
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeMaker;
import org.netbeans.api.java.source.TypeMirrorHandle;
import org.netbeans.api.java.source.WorkingCopy;
import org.netbeans.modules.java.hints.spi.ErrorRule;
import org.netbeans.spi.editor.hints.Fix;
Expand Down Expand Up @@ -134,11 +134,11 @@ public void cancel() {

private static final class FixImpl extends JavaFix {

private TypeMirror arrayTypeMirror;
private final TypeMirrorHandle arrayTypeMirror;

public FixImpl(CompilationInfo info, TreePath tp, TypeMirror arrayType) {
super(info, tp);
this.arrayTypeMirror = arrayType;
this.arrayTypeMirror = TypeMirrorHandle.create(arrayType);
}

@Override
Expand All @@ -157,12 +157,18 @@ protected void performRewrite(TransformationContext tc) throws Exception {
if (statementPath.getLeaf().getKind() == Tree.Kind.VARIABLE) {
oldVariableTree = (VariableTree) statementPath.getLeaf();

arrayTypeMirror = Utilities.resolveCapturedType(wc, arrayTypeMirror);
TypeMirror arrayType = arrayTypeMirror.resolve(wc);

if (arrayType == null) {
return ; //cannot resolve
}

arrayType = Utilities.resolveCapturedType(wc, arrayType);

VariableTree newVariableTree = make.Variable(
oldVariableTree.getModifiers(),
oldVariableTree.getName(),
make.ArrayType(make.Type(arrayTypeMirror)),
make.ArrayType(make.Type(arrayType)),
oldVariableTree.getInitializer()
);
tc.getWorkingCopy().rewrite(oldVariableTree, newVariableTree);
Expand Down
Loading