Skip to content

Commit

Permalink
Fix testCoreException and others
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Oct 31, 2024
1 parent 6db7bf5 commit 9303eda
Showing 1 changed file with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1376,27 +1376,34 @@ protected void locateMatchesWithASTParser(JavaProject javaProject, PossibleMatch
map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING);
this.options = new CompilerOptions(map);

List<org.eclipse.jdt.core.ICompilationUnit> unitCollector = new ArrayList<>();
Map<PossibleMatch, org.eclipse.jdt.core.ICompilationUnit> matchToCU = new HashMap<>();
// Original implementation used Map throughout, however,
// PossibleMatch was determined to be a bad / non-unique key where the
// hashCode and equals methods would let two different matches overlap.
// So we have to use Arrays and Lists, like a bunch of barbarians.
org.eclipse.jdt.core.ICompilationUnit[] unitArray = new org.eclipse.jdt.core.ICompilationUnit[possibleMatches.length];

Map<org.eclipse.jdt.core.ICompilationUnit, PossibleMatch> cuToMatch = new HashMap<>();
for( int i = 0; i < possibleMatches.length; i++ ) {
if( !skipMatch(javaProject, possibleMatches[i])) {
org.eclipse.jdt.core.ICompilationUnit u = findUnitForPossibleMatch(javaProject, possibleMatches[i]);
unitCollector.add(u);
matchToCU.put(possibleMatches[i], u);
unitArray[i] = u;
cuToMatch.put(u, possibleMatches[i]);
}
}
org.eclipse.jdt.core.ICompilationUnit[] units = unitCollector.toArray(new org.eclipse.jdt.core.ICompilationUnit[unitCollector.size()]);
org.eclipse.jdt.core.ICompilationUnit[] nonNullUnits =
Arrays.asList(unitArray).stream().filter(x -> x != null).toArray(org.eclipse.jdt.core.ICompilationUnit[]::new);
// debugMethodOne(javaProject, possibleMatches[0], new org.eclipse.jdt.core.ICompilationUnit[] {units[0]});
// debugMethodTwo(javaProject, possibleMatches[0], new org.eclipse.jdt.core.ICompilationUnit[] {units[0]});
// debugMethodThree(javaProject, possibleMatches[0], units);

if (units.length == 0) {
if (nonNullUnits.length == 0) {
return;
}

Set<WorkingCopyOwner> ownerSet = new HashSet<>();
for( int i = 0; i < units.length; i++ ) {
if( units[i].getOwner() != null ) {
ownerSet.add(units[i].getOwner());
for( int i = 0; i < nonNullUnits.length; i++ ) {
if( nonNullUnits[i].getOwner() != null ) {
ownerSet.add(nonNullUnits[i].getOwner());
}
}
WorkingCopyOwner owner = null;
Expand All @@ -1412,36 +1419,45 @@ protected void locateMatchesWithASTParser(JavaProject javaProject, PossibleMatch
if( owner != null )
astParser.setWorkingCopyOwner(owner);

Map<PossibleMatch, org.eclipse.jdt.core.dom.CompilationUnit> asts = new HashMap<>();
astParser.createASTs(units, new String[0], new ASTRequestor() {
org.eclipse.jdt.core.dom.CompilationUnit[] domUnits = new org.eclipse.jdt.core.dom.CompilationUnit[possibleMatches.length];
List<Integer> nonNullDomIndexes = new ArrayList<>();
astParser.createASTs(nonNullUnits, new String[0], new ASTRequestor() {
@Override
public void acceptAST(org.eclipse.jdt.core.ICompilationUnit source, org.eclipse.jdt.core.dom.CompilationUnit ast) {
PossibleMatch pm = cuToMatch.get(source);
if( pm != null ) {
asts.put(pm, ast);
for( int i = 0; i < possibleMatches.length; i++ ) {
if( possibleMatches[i] == pm ) {
domUnits[i] = ast;
nonNullDomIndexes.add(i);
return;
}
}
}

// Arrays.stream(possibleMatches, start, start + length) .filter(match -> match.openable.equals(source))
// .findAny() .ifPresent(match -> asts.put(match, ast));
}
}, this.progressMonitor); // todo, use a subprogressmonitor or slice it
asts.forEach((possibleMatch, ast) -> {
// todo, use a subprogressmonitor or slice it
}, this.progressMonitor);


nonNullDomIndexes.forEach(x -> {
PossibleMatch possibleMatch = possibleMatches[x];
org.eclipse.jdt.core.dom.CompilationUnit ast = domUnits[x];
ast.accept(new PatternLocatorVisitor(this.patternLocator, possibleMatch.nodeSet, this));
});
asts.keySet().forEach(possibleMatch -> {

for( int x : nonNullDomIndexes ) {
PossibleMatch possibleMatch = possibleMatches[x];
this.currentPossibleMatch = possibleMatch;
possibleMatch.nodeSet.trustedASTNodeLevels.forEach((node, level) -> {
for( org.eclipse.jdt.core.dom.ASTNode node : possibleMatch.nodeSet.trustedASTNodeLevels.keySet()) {
int level = possibleMatch.nodeSet.trustedASTNodeLevels.get(node);
SearchMatch match = toMatch(node, level, possibleMatch);
if( match != null && match.getElement() != null ) {
try {
this.report(match);
} catch (CoreException ex) {
ILog.get().error(ex.getMessage(), ex);
}
this.report(match);
}
});
});
}
}
}

private SearchMatch toMatch(org.eclipse.jdt.core.dom.ASTNode node, int accuracy, PossibleMatch possibleMatch) {
IResource resource = possibleMatch.resource;
if (node instanceof MethodDeclaration || node instanceof AbstractTypeDeclaration || node instanceof VariableDeclaration) {
Expand Down

0 comments on commit 9303eda

Please sign in to comment.