Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: handle some rare limit cases to avoid nasty NPEs #1331

Merged
merged 1 commit into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,12 @@ public <T> void visitCtConstructor(CtConstructor<T> constructor) {
if (constructor.getFormalCtTypeParameters().size() > 0) {
printer.write(' ');
}
if (constructor.getDeclaringType().isLocalType()) {
printer.write(constructor.getDeclaringType().getSimpleName().replaceAll("^[0-9]*", ""));
} else {
printer.write(constructor.getDeclaringType().getSimpleName());
if (constructor.getDeclaringType() != null) {
if (constructor.getDeclaringType().isLocalType()) {
printer.write(constructor.getDeclaringType().getSimpleName().replaceAll("^[0-9]*", ""));
} else {
printer.write(constructor.getDeclaringType().getSimpleName());
}
}
elementPrinterHelper.writeExecutableParameters(constructor);
elementPrinterHelper.writeThrowsClause(constructor);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/reflect/visitor/ImportScannerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected boolean addClassImport(CtTypeReference<?> ref) {
} catch (ParentNotInitializedException e) {
}
CtPackageReference pack = targetType.getPackage();
if (ref.getPackage() != null && !ref.getPackage().isUnnamedPackage()) {
if (pack != null && ref.getPackage() != null && !ref.getPackage().isUnnamedPackage()) {
// ignore java.lang package
if (!ref.getPackage().getSimpleName().equals("java.lang")) {
// ignore type in same package
Expand All @@ -372,7 +372,7 @@ protected boolean isImportedInClassImports(CtTypeReference<?> ref) {

// we consider that if a class belongs to java.lang or the same package than the actual class
// then it is imported by default
if (ref.getPackage() != null && !ref.getPackage().isUnnamedPackage()) {
if (pack != null && ref.getPackage() != null && !ref.getPackage().isUnnamedPackage()) {
// ignore java.lang package
if (!ref.getPackage().getSimpleName().equals("java.lang")) {
// ignore type in same package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ protected void generateProcessedSourceFilesUsingCUs() {
List<File> printedFiles = new ArrayList<>();
for (spoon.reflect.cu.CompilationUnit cu : factory.CompilationUnit().getMap().values()) {

factory.getEnvironment().debugMessage("Generating source for compilation unit: " + cu.getFile());
if (cu.getDeclaredTypes().size() == 0) { // case of package-info
continue;
}

CtType<?> element = cu.getMainType();

Expand Down