mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
DfaMemoryStateImpl: tryMergeClassByQualifier extracted and documented (IDEA-CR-21388)
This commit is contained in:
@@ -317,29 +317,42 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
addToMap(dfaValue.getID(), resultIndex);
|
||||
|
||||
if (dfaValue instanceof DfaVariableValue) {
|
||||
DfaVariableValue variableValue = (DfaVariableValue)dfaValue;
|
||||
DfaVariableValue qualifier = variableValue.getQualifier();
|
||||
PsiModifierListOwner variable = variableValue.getPsiVariable();
|
||||
if (qualifier != null) {
|
||||
Integer index = getOrCreateEqClassIndex(qualifier);
|
||||
if (index != null) {
|
||||
for (DfaValue eqQualifier : myEqClasses.get(index).getMemberValues()) {
|
||||
if (eqQualifier != qualifier && eqQualifier instanceof DfaVariableValue) {
|
||||
DfaVariableValue eqValue = getFactory().getVarFactory()
|
||||
.createVariableValue(variable, variableValue.getVariableType(), variableValue.isNegated(), (DfaVariableValue)eqQualifier);
|
||||
i = getEqClassIndex(eqValue);
|
||||
if (i != -1) {
|
||||
uniteClasses(i, resultIndex);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tryMergeClassByQualifier(resultIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a class index which contains single value, tries to find equivalent class
|
||||
* based on qualifier equivalence. E.g. if {@code classIndex} is {@code [length|s1]}
|
||||
* and there are another classes {@code [s1, s2]} and {@code [length|s2]}, then
|
||||
* {@code [length|s1, length|s2]} created and returned (if strings s1 and s2 are the same,
|
||||
* then their lengths are also the same).
|
||||
*
|
||||
* @param classIndex index of a class to merge (should contain single element)
|
||||
* @return an index of a merged class or original classIndex if merging is impossible.
|
||||
*/
|
||||
private int tryMergeClassByQualifier(int classIndex) {
|
||||
List<DfaValue> values = myEqClasses.get(classIndex).getMemberValues();
|
||||
if (values.size() != 1) return classIndex;
|
||||
DfaValue dfaValue = values.get(0);
|
||||
if (!(dfaValue instanceof DfaVariableValue)) return classIndex;
|
||||
DfaVariableValue variableValue = (DfaVariableValue)dfaValue;
|
||||
DfaVariableValue qualifier = variableValue.getQualifier();
|
||||
PsiModifierListOwner variable = variableValue.getPsiVariable();
|
||||
if (qualifier == null) return classIndex;
|
||||
Integer index = getOrCreateEqClassIndex(qualifier);
|
||||
if (index == null) return classIndex;
|
||||
for (DfaValue eqQualifier : myEqClasses.get(index).getMemberValues()) {
|
||||
if (eqQualifier != qualifier && eqQualifier instanceof DfaVariableValue) {
|
||||
DfaVariableValue eqValue = getFactory().getVarFactory()
|
||||
.createVariableValue(variable, variableValue.getVariableType(), variableValue.isNegated(), (DfaVariableValue)eqQualifier);
|
||||
int i = getEqClassIndex(eqValue);
|
||||
if (i != -1) {
|
||||
uniteClasses(i, classIndex);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultIndex;
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
private void addToMap(int id, int index) {
|
||||
|
||||
Reference in New Issue
Block a user