*/
private boolean isImmutableAndWellDefinedVariable(Var v,
ReferenceCollection refInfo) {
List<Reference> refSet = refInfo.references;
int startingReadRef = 1;
Reference refDecl = refSet.get(0);
if (!isValidDeclaration(refDecl)) {
return false;
}
boolean isNeverAssigned = refInfo.isNeverAssigned();
// For values that are never assigned, only the references need to be
// checked.
if (!isNeverAssigned) {
Reference refInit = refInfo.getInitializingReference();
if (!isValidInitialization(refInit)) {
return false;
}
if (refDecl != refInit) {
Preconditions.checkState(refInit == refSet.get(1));
startingReadRef = 2;
}
if (!refInfo.isWellDefined()) {
return false;
}
Node value = refInit.getAssignedValue();
Preconditions.checkNotNull(value);
boolean isImmutableValueWorthInlining =
NodeUtil.isImmutableValue(value) &&
(value.getType() != Token.STRING ||
isStringWorthInlining(v, refInfo.references));
boolean isInlinableThisAlias =
value.getType() == Token.THIS &&
!refInfo.isEscaped();
if (!isImmutableValueWorthInlining && !isInlinableThisAlias) {
return false;
}
}
for (int i = startingReadRef; i < refSet.size(); i++) {
Reference ref = refSet.get(i);
if (!isValidReference(ref)) {
return false;
}
}