mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Fixed an NPE.
This commit is contained in:
parent
61f6529667
commit
cff7d18b90
1 changed files with 13 additions and 7 deletions
|
@ -299,12 +299,14 @@ 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);
|
||||||
|
if (include != null) {
|
||||||
IncludeCandidate candidate = new IncludeCandidate(binding, include);
|
IncludeCandidate candidate = new IncludeCandidate(binding, include);
|
||||||
if (!candidates.containsKey(candidate.toString())) {
|
if (!candidates.containsKey(candidate.toString())) {
|
||||||
candidates.put(candidate.toString(), candidate);
|
candidates.put(candidate.toString(), candidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String deduceUsingDeclaration(IBinding source, IBinding target, IASTTranslationUnit ast) {
|
private String deduceUsingDeclaration(IBinding source, IBinding target, IASTTranslationUnit ast) {
|
||||||
if (source.equals(target)) {
|
if (source.equals(target)) {
|
||||||
|
@ -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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue