From c08a3056dbb12f8b2d8798a829dc3f33ad8213ec Mon Sep 17 00:00:00 2001 From: EverettHanke Date: Fri, 8 Nov 2024 00:04:00 -0800 Subject: [PATCH 1/3] Annotating when having Injectable Constructor --- .../pde/ds/internal/annotations/AnnotationVisitor.java | 5 +++++ .../org/eclipse/pde/ds/internal/annotations/Messages.java | 2 ++ .../eclipse/pde/ds/internal/annotations/messages.properties | 1 + 3 files changed, 8 insertions(+) diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java index 68e6fedc11..b5bfe5df0a 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java @@ -258,6 +258,11 @@ public boolean visit(TypeDeclaration type) { if (hasInjectableConstructor) { // TODO we should add an error marker that offers a quickfix to upgrade the spec // version to 1.4 + problemReporter.reportProblem(annotation, null, + NLS.bind( + Messages.AnnotationProcessor_invalidCompImplClass_injectableConstructor, + type.getName().getIdentifier()), + type.getName().getIdentifier()); } problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidCompImplClass_noDefaultConstructor, diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/Messages.java b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/Messages.java index 306a5ce9ce..c38887e4a8 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/Messages.java +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/Messages.java @@ -47,6 +47,8 @@ public class Messages extends NLS { public static String AnnotationProcessor_invalidCompImplClass_noDefaultConstructor; + public static String AnnotationProcessor_invalidCompImplClass_injectableConstructor; + public static String AnnotationProcessor_invalidCompImplClass_notPublic; public static String AnnotationProcessor_invalidCompImplClass_notTopLevel; diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties index 131243e569..c731eb2f5f 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties @@ -25,6 +25,7 @@ AnnotationProcessor_invalidCompImplClass_annotation=Invalid component implementa AnnotationProcessor_invalidCompImplClass_enumeration=Invalid component implementation class ''{0}'': enumeration type. AnnotationProcessor_invalidCompImplClass_interface=Invalid component implementation class ''{0}'': interface type. AnnotationProcessor_invalidCompImplClass_noDefaultConstructor=Invalid component implementation class ''{0}'': no default constructor. +AnnotationProcessor_invalidCompImplClass_injectableConstructor=Invalid component implementation class ''{0}'': injectable constructor. AnnotationProcessor_invalidCompImplClass_compatibleConstructor=Invalid component implementation class ''{0}'': no default or @Activate annotated constructor. AnnotationProcessor_invalidCompImplClass_notPublic=Invalid component implementation class ''{0}'': not a public class. AnnotationProcessor_invalidCompImplClass_notTopLevel=Invalid component implementation class ''{0}'': not a primary class or static class nested in primary type. From 20c9191b62a816f284b97e229ca96fabe5d54da7 Mon Sep 17 00:00:00 2001 From: EverettHanke <156118104+EverettHanke@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:59:34 -0800 Subject: [PATCH 2/3] Update messages.properties for clearer warning. --- .../org/eclipse/pde/ds/internal/annotations/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties index c731eb2f5f..8030d3139a 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties @@ -25,7 +25,7 @@ AnnotationProcessor_invalidCompImplClass_annotation=Invalid component implementa AnnotationProcessor_invalidCompImplClass_enumeration=Invalid component implementation class ''{0}'': enumeration type. AnnotationProcessor_invalidCompImplClass_interface=Invalid component implementation class ''{0}'': interface type. AnnotationProcessor_invalidCompImplClass_noDefaultConstructor=Invalid component implementation class ''{0}'': no default constructor. -AnnotationProcessor_invalidCompImplClass_injectableConstructor=Invalid component implementation class ''{0}'': injectable constructor. +AnnotationProcessor_invalidCompImplClass_injectableConstructor=Invalid component implementation class ''{0}'': has an injectable constructor. Upgrade to spec version 1.4. AnnotationProcessor_invalidCompImplClass_compatibleConstructor=Invalid component implementation class ''{0}'': no default or @Activate annotated constructor. AnnotationProcessor_invalidCompImplClass_notPublic=Invalid component implementation class ''{0}'': not a public class. AnnotationProcessor_invalidCompImplClass_notTopLevel=Invalid component implementation class ''{0}'': not a primary class or static class nested in primary type. From b5cf2ddc80f4d4ab14e51df22c6cc344e6bcad53 Mon Sep 17 00:00:00 2001 From: EverettHanke Date: Mon, 11 Nov 2024 21:48:27 -0800 Subject: [PATCH 3/3] has an injectable constructor that is not public. Please ensure constructor is annotated with @activate. --- .../annotations/AnnotationVisitor.java | 28 +++++++++++++------ .../internal/annotations/messages.properties | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java index b5bfe5df0a..05f72a2599 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java @@ -241,21 +241,29 @@ public boolean visit(TypeDeclaration type) { || (noDefaultConstructor = !(hasDefaultConstructor(type) || (hasInjectableConstructor = hasInjectableConstructor(type, problemReporter))))) { // interfaces, abstract types, non-static/non-public nested types, or types with no default constructor cannot be components - if (!errorLevel.isIgnore()) { - if (isInterface) { + if (!errorLevel.isIgnore()) + { + if (isInterface) + { problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidCompImplClass_interface, type.getName().getIdentifier()), type.getName().getIdentifier()); - } else if (isAbstract) { + } else if (isAbstract) + { problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidCompImplClass_abstract, type.getName().getIdentifier()), type.getName().getIdentifier()); - } else if (isNested) { + } else if (isNested) + { problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidCompImplClass_notTopLevel, type.getName().getIdentifier()), type.getName().getIdentifier()); - } else if (noDefaultConstructor) { - if (specVersion.isEqualOrHigherThan(DSAnnotationVersion.V1_4)) { + } else if (noDefaultConstructor) + { + if (specVersion.isEqualOrHigherThan(DSAnnotationVersion.V1_4)) + { problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidCompImplClass_compatibleConstructor, type.getName().getIdentifier()), type.getName().getIdentifier()); - } else { - if (hasInjectableConstructor) { + } else + { + if (hasInjectableConstructor) + { // TODO we should add an error marker that offers a quickfix to upgrade the spec // version to 1.4 problemReporter.reportProblem(annotation, null, @@ -269,7 +277,9 @@ public boolean visit(TypeDeclaration type) { type.getName().getIdentifier()), type.getName().getIdentifier()); } - } else { + } + else + { problemReporter.reportProblem(annotation, null, NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass, type.getName().getIdentifier()), type.getName().getIdentifier()); } } diff --git a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties index c731eb2f5f..9e2271bc33 100644 --- a/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties +++ b/ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/messages.properties @@ -25,7 +25,7 @@ AnnotationProcessor_invalidCompImplClass_annotation=Invalid component implementa AnnotationProcessor_invalidCompImplClass_enumeration=Invalid component implementation class ''{0}'': enumeration type. AnnotationProcessor_invalidCompImplClass_interface=Invalid component implementation class ''{0}'': interface type. AnnotationProcessor_invalidCompImplClass_noDefaultConstructor=Invalid component implementation class ''{0}'': no default constructor. -AnnotationProcessor_invalidCompImplClass_injectableConstructor=Invalid component implementation class ''{0}'': injectable constructor. +AnnotationProcessor_invalidCompImplClass_injectableConstructor=Invalid component implementation class ''{0}'': has an injectable constructor that is not public. Please ensure constructor is annotated with @activate. AnnotationProcessor_invalidCompImplClass_compatibleConstructor=Invalid component implementation class ''{0}'': no default or @Activate annotated constructor. AnnotationProcessor_invalidCompImplClass_notPublic=Invalid component implementation class ''{0}'': not a public class. AnnotationProcessor_invalidCompImplClass_notTopLevel=Invalid component implementation class ''{0}'': not a primary class or static class nested in primary type.