下面列出了java.nio.file.InvalidPathException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @param targetClass
* @param targetMethod
* @return list of resolved classes and interfaces which are ancestors of the
* given classes (not including java.lang.Object or external
* dependencies) and contain the given target method
* @throws BotRefactoringException
*/
private static Set<ResolvedReferenceTypeDeclaration> findAllAncestors(ClassOrInterfaceDeclaration targetClass,
MethodDeclaration targetMethod) throws BotRefactoringException {
List<ResolvedReferenceType> ancestors = new ArrayList<>();
Set<ResolvedReferenceTypeDeclaration> result = new HashSet<>();
try {
ancestors = targetClass.resolve().getAllAncestors();
} catch (UnsolvedSymbolException u) {
ancestors = RefactoringHelper.getAllResolvableAncestors(targetClass.resolve());
logger.warn("Refactored classes might extend/implement classes or interfaces from external dependency! "
+ "Please validate the correctness of the refactoring.");
// TODO propagate warning
} catch (InvalidPathException i) {
throw new BotRefactoringException("Javaparser could not parse file: " + i.getMessage());
} catch (Exception e) {
throw new BotRefactoringException("Error while resolving superclasses occured!");
}
for (ResolvedReferenceType ancestor : ancestors) {
if (!ancestor.getQualifiedName().equals("java.lang.Object")) {
for (ResolvedMethodDeclaration method : ancestor.getAllMethods()) {
if (method.getSignature().equals(targetMethod.resolve().getSignature())) {
result.add(ancestor.getTypeDeclaration());
}
}
}
}
return result;
}
@Override
public Path parse(String text) throws ParseException {
try {
return Paths.get(text);
} catch(InvalidPathException e) {
throw new FormatException(e.getMessage());
}
}
/** @return a valid path from given pathString.
* @throws CommonException if a valid path could not be created.
* Given errorMessagePrefix will be used as a prefix in {@link CommonException}'s message. */
public static Path createPath(String pathString, String errorMessagePrefix) throws CommonException {
try {
return Paths.get(pathString);
} catch (InvalidPathException ipe) {
String pathMessage = ipe.getMessage();
if(pathMessage == null) {
pathMessage = ipe.toString();
}
throw new CommonException(errorMessagePrefix + pathMessage);
}
}