package bluej.stride.framedjava.errors;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import bluej.compiler.Diagnostic.DiagnosticOrigin;
import bluej.stride.framedjava.ast.StringSlotFragment;
import bluej.stride.framedjava.errors.Correction.SimpleCorrectionInfo;
import bluej.stride.framedjava.slots.ExpressionSlot;
import threadchecker.OnThread;
import threadchecker.Tag;

public class UndeclaredVariableInExpressionError
extends DirectSlotError{    
   private final String varName;
   
   private final int startPosInSlot;
   
   private final int endPosInSlot;
   
   private List<FixSuggestion> corrections = new ArrayList<>();

   
   
| Creates an error about an undeclared variable being used in an expression. The quick fixes | will be to switch the variable name to another similarly spelt variable. | | @param slotFragment The fragment with the error. | @param varName The name of the variable which is used, but not declared | @param startPosInSlot The start position in the slot of the variable name (inclusive) | @param endPosInSlot The end position in the slot of the variable name (exclusive) | @param slot The slot with the error (which will contain slotFragment). | @param possibleCorrections The possible other variable names (unfiltered: all variable names which are in scope) | @OnThread(Tag.FXPlatform) public UndeclaredVariableInExpressionError(StringSlotFragment slotFragment, String varName, int startPosInSlot, int endPosInSlot, ExpressionSlot slot, Set<String> possibleCorrections) { super(slotFragment, DiagnosticOrigin.STRIDE_LATE); this.varName = varName; this.startPosInSlot = startPosInSlot; this.endPosInSlot = endPosInSlot; corrections.addAll(Correction.winnowAndCreateCorrections(varName, possibleCorrections.stream().map(SimpleCorrectionInfo::new), s -> slot.replace(startPosInSlot, endPosInSlot, isJavaPos(), s))); } @Override public int getStartPosition() { return startPosInSlot; } @Override public int getEndPosition() { return endPosInSlot; } @Override @OnThread(Tag.Any) public String getMessage() { return "Undeclared variable: " + varName; } @Override public List getFixSuggestions() { return corrections; } @Override public boolean isJavaPos() { return true; } }
top, use, map, class UndeclaredVariableInExpressionError

.   UndeclaredVariableInExpressionError
.   getStartPosition
.   getEndPosition
.   getMessage
.   getFixSuggestions
.   isJavaPos




76 neLoCode + 8 LoComm