diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-12-20 22:59:22 +0200 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-12-20 22:59:22 +0200 |
commit | 77fb6914b47a93b805baae8a6ff819f686367144 (patch) | |
tree | 6e8c81e2807a07b4cc5d6fbb7631fde2bde9a29b /pf4j | |
parent | b011f59c632a42c9d4b8abb239fd767a115e056d (diff) | |
download | pf4j-77fb6914b47a93b805baae8a6ff819f686367144.tar.gz pf4j-77fb6914b47a93b805baae8a6ff819f686367144.zip |
Improve readability
Diffstat (limited to 'pf4j')
-rw-r--r-- | pf4j/src/main/java/module-info.java | 47 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/processor/ExtensionAnnotationProcessor.java | 56 |
2 files changed, 28 insertions, 75 deletions
diff --git a/pf4j/src/main/java/module-info.java b/pf4j/src/main/java/module-info.java deleted file mode 100644 index 754b9b8..0000000 --- a/pf4j/src/main/java/module-info.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Module descriptor for PF4J. - * - * @author Decebal Suiu - * @author Andreas Rudolph - */ -module org.pf4j { - requires java.base; - - // provides javax.annotation - requires java.compiler; - - // provided by the ASM library - requires org.objectweb.asm; - - // The SLF4J library currently does not provide a module. - // Version 1.8 provides a module called "org.slf4j". But this version is - // currently in beta stage. Therefore I'm not sure, if we already like to - // use it. - requires slf4j.api; - - // The java-semver library currently does not provide a module. - // Maybe we should send them a pull request, that at least they provide an - // automatic module name in their MANIFEST file. - requires java.semver; - - // Maybe we should reconsider the package hierarchy, that only classes are - // exported, which are required by 3rd party developers. - exports org.pf4j; - exports org.pf4j.processor; -} diff --git a/pf4j/src/main/java/org/pf4j/processor/ExtensionAnnotationProcessor.java b/pf4j/src/main/java/org/pf4j/processor/ExtensionAnnotationProcessor.java index 2faf143..797fe04 100644 --- a/pf4j/src/main/java/org/pf4j/processor/ExtensionAnnotationProcessor.java +++ b/pf4j/src/main/java/org/pf4j/processor/ExtensionAnnotationProcessor.java @@ -172,6 +172,34 @@ public class ExtensionAnnotationProcessor extends AbstractProcessor { return storage; } + private void processExtensionElement(Element element) { + // check if @Extension is put on class and not on method or constructor + if (!(element instanceof TypeElement)) { + error(element, "Put annotation only on classes (no methods, no fields)"); + return; + } + + // check if class extends/implements an extension point + if (!ignoreExtensionPoint && !isExtension(element.asType())) { + error(element, "%s is not an extension (it doesn't implement ExtensionPoint)", element); + return; + } + + TypeElement extensionElement = (TypeElement) element; + List<TypeElement> extensionPointElements = findExtensionPoints(extensionElement); + if (extensionPointElements.isEmpty()) { + error(element, "No extension points found for extension %s", extensionElement); + return; + } + + String extension = getBinaryName(extensionElement); + for (TypeElement extensionPointElement : extensionPointElements) { + String extensionPoint = getBinaryName(extensionPointElement); + Set<String> extensionPoints = extensions.computeIfAbsent(extensionPoint, k -> new TreeSet<>()); + extensionPoints.add(extension); + } + } + @SuppressWarnings("unchecked") private List<TypeElement> findExtensionPoints(TypeElement extensionElement) { List<TypeElement> extensionPointElements = new ArrayList<>(); @@ -263,34 +291,6 @@ public class ExtensionAnnotationProcessor extends AbstractProcessor { System.getProperty(IGNORE_EXTENSION_POINT) != null; } - private void processExtensionElement(Element element) { - // check if @Extension is put on class and not on method or constructor - if (!(element instanceof TypeElement)) { - error(element, "Put annotation only on classes (no methods, no fields)"); - return; - } - - // check if class extends/implements an extension point - if (!ignoreExtensionPoint && !isExtension(element.asType())) { - error(element, "%s is not an extension (it doesn't implement ExtensionPoint)", element); - return; - } - - TypeElement extensionElement = (TypeElement) element; - List<TypeElement> extensionPointElements = findExtensionPoints(extensionElement); - if (extensionPointElements.isEmpty()) { - error(element, "No extension points found for extension %s", extensionElement); - return; - } - - String extension = getBinaryName(extensionElement); - for (TypeElement extensionPointElement : extensionPointElements) { - String extensionPoint = getBinaryName(extensionPointElement); - Set<String> extensionPoints = extensions.computeIfAbsent(extensionPoint, k -> new TreeSet<>()); - extensionPoints.add(extension); - } - } - private TypeElement getElement(TypeMirror typeMirror) { return (TypeElement) ((DeclaredType) typeMirror).asElement(); } |