1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Fixed an NPE.

This commit is contained in:
Sergey Prigogin 2009-05-15 08:12:56 +00:00
parent 61f6529667
commit cff7d18b90

View file

@ -299,9 +299,11 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
if (!isSource(getPath(file)) || index.findIncludedBy(file, 0).length > 0) { if (!isSource(getPath(file)) || index.findIncludedBy(file, 0).length > 0) {
IIndexFile representativeFile = getRepresentativeFile(file, index); IIndexFile representativeFile = getRepresentativeFile(file, index);
IRequiredInclude include = getRequiredInclude(representativeFile, index); IRequiredInclude include = getRequiredInclude(representativeFile, index);
IncludeCandidate candidate = new IncludeCandidate(binding, include); if (include != null) {
if (!candidates.containsKey(candidate.toString())) { IncludeCandidate candidate = new IncludeCandidate(binding, include);
candidates.put(candidate.toString(), candidate); if (!candidates.containsKey(candidate.toString())) {
candidates.put(candidate.toString(), candidate);
}
} }
} }
} }
@ -519,21 +521,25 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
// has to be resolvable in the context of the current translation unit. // has to be resolvable in the context of the current translation unit.
int systemIncludeVotes = 0; int systemIncludeVotes = 0;
String[] ballotBox = new String[includes.length]; String[] ballotBox = new String[includes.length];
int k = 0;
for (int i = 0; i < includes.length; i++) { for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i]; IIndexInclude include = includes[i];
if (isResolvable(include)) { if (isResolvable(include)) {
ballotBox[i] = include.getFullName(); ballotBox[k++] = include.getFullName();
if (include.isSystemInclude()) { if (include.isSystemInclude()) {
systemIncludeVotes++; systemIncludeVotes++;
} }
} }
} }
Arrays.sort(ballotBox); if (k == 0) {
return null;
}
Arrays.sort(ballotBox, 0, k);
String contender = ballotBox[0]; String contender = ballotBox[0];
int votes = 1; int votes = 1;
String winner = contender; String winner = contender;
int winnerVotes = votes; int winnerVotes = votes;
for (int i = 1; i < ballotBox.length; i++) { for (int i = 1; i < k; i++) {
if (!ballotBox[i].equals(contender)) { if (!ballotBox[i].equals(contender)) {
contender = ballotBox[i]; contender = ballotBox[i];
votes = 1; votes = 1;
@ -544,7 +550,7 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
winnerVotes = votes; winnerVotes = votes;
} }
} }
return new RequiredInclude(winner, systemIncludeVotes * 2 >= includes.length); return new RequiredInclude(winner, systemIncludeVotes * 2 >= k);
} }
// The file has never been included before. // The file has never been included before.