Fix resource resolution in the graphical layout editor.
Resource with qualifiers take precedence over the ones without even if the qualifiers are not present on the requested configuration. Change-Id: I0d19889064e8031179ea6ee13c93a4198fe971fd
This commit is contained in:
@@ -464,11 +464,11 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the configuration is a match for the given reference config.
|
* Returns whether the configuration is a match for the given reference config.
|
||||||
* <p/>A match means that:
|
* <p/>A match means that, for each qualifier of this config
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>This config does not use any qualifier not used by the reference config</li>
|
* <li>The reference config has no value set
|
||||||
* <li>The qualifier used by this config have the same values as the qualifiers of
|
* <li>or, the qualifier of the reference config is a match. Depending on the qualifier type
|
||||||
* the reference config.</li>
|
* this does not mean the same exact value.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param referenceConfig The reference configuration to test against.
|
* @param referenceConfig The reference configuration to test against.
|
||||||
* @return true if the configuration matches.
|
* @return true if the configuration matches.
|
||||||
@@ -478,14 +478,10 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
|
|||||||
ResourceQualifier testQualifier = mQualifiers[i];
|
ResourceQualifier testQualifier = mQualifiers[i];
|
||||||
ResourceQualifier referenceQualifier = referenceConfig.mQualifiers[i];
|
ResourceQualifier referenceQualifier = referenceConfig.mQualifiers[i];
|
||||||
|
|
||||||
// we only care if testQualifier is non null.
|
// it's only a non match if both qualifiers are non-null, and they don't match.
|
||||||
if (testQualifier != null) {
|
if (testQualifier != null && referenceQualifier != null &&
|
||||||
if (referenceQualifier == null) { // reference config doesn't specify anything
|
testQualifier.isMatchFor(referenceQualifier) == false) {
|
||||||
// for this qualifier so we refuse it.
|
return false;
|
||||||
return false;
|
|
||||||
} else if (testQualifier.isMatchFor(referenceQualifier) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -542,66 +542,69 @@ public class ProjectResources implements IResourceRepository {
|
|||||||
for (int q = 0 ; q < count ; q++) {
|
for (int q = 0 ; q < count ; q++) {
|
||||||
// look to see if one resource has this qualifier.
|
// look to see if one resource has this qualifier.
|
||||||
// At the same time also record the best match value for the qualifier (if applicable).
|
// At the same time also record the best match value for the qualifier (if applicable).
|
||||||
|
|
||||||
|
// The reference value, to find the best match.
|
||||||
|
// Note that this qualifier could be null. In which case any qualifier found in the
|
||||||
|
// possible match, will all be considered best match.
|
||||||
ResourceQualifier referenceQualifier = referenceConfig.getQualifier(q);
|
ResourceQualifier referenceQualifier = referenceConfig.getQualifier(q);
|
||||||
|
|
||||||
if (referenceQualifier != null) { // no need to check if it's null, since the loop
|
boolean found = false;
|
||||||
// above will have removed the resources anyway.
|
ResourceQualifier bestMatch = null; // this is to store the best match.
|
||||||
boolean found = false;
|
for (Resource res : matchingResources) {
|
||||||
ResourceQualifier bestMatch = null;
|
ResourceQualifier qualifier = res.getConfiguration().getQualifier(q);
|
||||||
for (Resource res : matchingResources) {
|
if (qualifier != null) {
|
||||||
ResourceQualifier qualifier = res.getConfiguration().getQualifier(q);
|
// set the flag.
|
||||||
if (qualifier != null) {
|
found = true;
|
||||||
// set the flag.
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
// now check for a best match.
|
// Now check for a best match. If the reference qualifier is null ,
|
||||||
|
// any qualifier is a "best" match (we don't need to record all of them.
|
||||||
|
// Instead the non compatible ones are removed below)
|
||||||
|
if (referenceQualifier != null) {
|
||||||
if (qualifier.isBetterMatchThan(bestMatch, referenceQualifier)) {
|
if (qualifier.isBetterMatchThan(bestMatch, referenceQualifier)) {
|
||||||
bestMatch = qualifier;
|
bestMatch = qualifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if a resources as a qualifier at the current index, remove all the resources that
|
// 4. If a resources has a qualifier at the current index, remove all the resources that
|
||||||
// do not have one.
|
// do not have one, or whose qualifier value does not equal the best match found above
|
||||||
// If there is one, and we have a bestComparable, also check that it's equal to the
|
// unless there's no reference qualifier, in which case they are all considered
|
||||||
// best comparable.
|
// "best" match.
|
||||||
if (found) {
|
if (found) {
|
||||||
for (int i = 0 ; i < matchingResources.size(); ) {
|
for (int i = 0 ; i < matchingResources.size(); ) {
|
||||||
Resource res = matchingResources.get(i);
|
Resource res = matchingResources.get(i);
|
||||||
ResourceQualifier qualifier = res.getConfiguration().getQualifier(q);
|
ResourceQualifier qualifier = res.getConfiguration().getQualifier(q);
|
||||||
|
|
||||||
if (qualifier == null) { // no qualifier? remove the resources
|
if (qualifier == null) {
|
||||||
matchingResources.remove(res);
|
// this resources has no qualifier of this type: rejected.
|
||||||
} else if (bestMatch != null && bestMatch.equals(qualifier) == false) {
|
matchingResources.remove(res);
|
||||||
// if there is a best match, only accept the resource if the qualifier
|
} else if (referenceQualifier != null && bestMatch != null &&
|
||||||
// has the same best value.
|
bestMatch.equals(qualifier) == false) {
|
||||||
matchingResources.remove(res);
|
// there's a reference qualifier and there is a better match for it than
|
||||||
} else {
|
// this resource, so we reject it.
|
||||||
i++;
|
matchingResources.remove(res);
|
||||||
}
|
} else {
|
||||||
|
// looks like we keep this resource, move on to the next one.
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// at this point we may have run out of matching resources before going
|
// at this point we may have run out of matching resources before going
|
||||||
// through all the qualifiers.
|
// through all the qualifiers.
|
||||||
if (matchingResources.size() == 1) {
|
if (matchingResources.size() < 2) {
|
||||||
return matchingResources.get(0);
|
break;
|
||||||
} else if (matchingResources.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// went through all the qualifiers. We should not have more than one
|
// Because we accept resources whose configuration have qualifiers where the reference
|
||||||
switch (matchingResources.size()) {
|
// configuration doesn't, we can end up with more than one match. In this case, we just
|
||||||
case 0:
|
// take the first one.
|
||||||
return null;
|
if (matchingResources.size() == 0) {
|
||||||
case 1:
|
return null;
|
||||||
return matchingResources.get(1);
|
|
||||||
case 2:
|
|
||||||
assert false;
|
|
||||||
}
|
}
|
||||||
return null;
|
return matchingResources.get(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user