Skip to content

Commit

Permalink
Merge pull request #4433 from jlerbsc/master
Browse files Browse the repository at this point in the history
Fixes an error in jbehave tests when they are run in a Windows os
  • Loading branch information
jlerbsc committed May 25, 2024
2 parents 6998087 + 4fb1298 commit f22c723
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@

package com.github.javaparser.steps;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.visitor.ModifierVisitor;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import static com.github.javaparser.StaticJavaParser.*;
import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock;
import static com.github.javaparser.utils.Utils.readerToString;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import static com.github.javaparser.StaticJavaParser.*;
import static com.github.javaparser.utils.Utils.readerToString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.visitor.ModifierVisitor;
import com.github.javaparser.utils.LineSeparator;

public class PrettyPrintingSteps {

Expand Down Expand Up @@ -107,6 +110,9 @@ public void whenTheClassIsVisitedByAnEmptyModifierVisitorAdapter() {

@Then("it is printed as:$src")
public void isPrintedAs(String src) {
assertEquals(src.trim(), resultNode.toString().trim());
assertEquals(
normalizeEolInTextBlock(src.trim(), LineSeparator.ARBITRARY),
normalizeEolInTextBlock(resultNode.toString().trim(), LineSeparator.ARBITRARY)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ public Optional<S> getDeclaration() {
* The corresponding declaration. If not solve this throws UnsupportedOperationException.
*/
public S getCorrespondingDeclaration() {

Optional<S> declaration = getDeclaration();
if (declaration.isPresent()) {
return declaration.get();
}

throw new UnsolvedSymbolException("Corresponding declaration not available for unsolved symbol.");
return getDeclaration().orElseThrow(() -> new UnsolvedSymbolException("Corresponding declaration not available for unsolved symbol."));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
package com.github.javaparser.symbolsolver.javaparsermodel.contexts;


import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
import com.github.javaparser.ast.Node;
Expand All @@ -43,10 +47,6 @@
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
import com.github.javaparser.symbolsolver.resolution.SymbolSolver;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Federico Tomassetti
*/
Expand Down Expand Up @@ -129,11 +129,11 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name, List<Reso
if (type instanceof ClassOrInterfaceDeclaration) {
return SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration((ClassOrInterfaceDeclaration) type));
}

if (type instanceof AnnotationDeclaration) {
return SymbolReference.solved(new JavaParserAnnotationDeclaration((AnnotationDeclaration) type, typeSolver));
}

if (type instanceof EnumDeclaration) {
return SymbolReference.solved(new JavaParserEnumDeclaration((EnumDeclaration) type, typeSolver));
}
Expand All @@ -146,7 +146,7 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name, List<Reso
// class or interface called "B". Since the type that we're looking for can be nested arbitrarily deeply
// ("A.B.C.D"), we look for the outermost type ("A" in the previous example) first, then recursively invoke
// this method for the remaining part of the given name.
if (name.indexOf('.') > -1) {
if (isQualifiedName(name)) {
SymbolReference<ResolvedTypeDeclaration> ref = null;
SymbolReference<ResolvedTypeDeclaration> outerMostRef =
solveType(name.substring(0, name.indexOf(".")));
Expand All @@ -167,10 +167,7 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name, List<Reso

// Inspect imports for matches, prior to inspecting other classes within the package (per issue #1526)
int dotPos = name.indexOf('.');
String prefix = null;
if (dotPos > -1) {
prefix = name.substring(0, dotPos);
}
String prefix = isQualifiedName(name) ? name.substring(0, dotPos) : null;
// look into single type imports
for (ImportDeclaration importDecl : wrappedNode.getImports()) {
if (!importDecl.isAsterisk()) {
Expand Down

0 comments on commit f22c723

Please sign in to comment.