Skip to content

Commit

Permalink
Cleanup extenion point (#544)
Browse files Browse the repository at this point in the history
* added example for issue #512

* fix removing of field annotations during delombok

* cleanup code

* added to changelog #530

* added support for ImplicitResourceCloser extension point for @cleanup #287

* master is now for: up from 2018.1 IntelliJ builds
  • Loading branch information
mplushnikov committed Oct 24, 2018
1 parent fe359ea commit 28b661a
Show file tree
Hide file tree
Showing 66 changed files with 456 additions and 321 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -17,10 +17,6 @@ env:
- IDEA_VERSION=IC-2018.2 - IDEA_VERSION=IC-2018.2
- IDEA_VERSION=IC-2018.1.6 - IDEA_VERSION=IC-2018.1.6
- IDEA_VERSION=IC-2018.1 - IDEA_VERSION=IC-2018.1
- IDEA_VERSION=IC-2017.3.4
- IDEA_VERSION=IC-2017.3
- IDEA_VERSION=IC-2017.2.6
- IDEA_VERSION=IC-2017.2


before_install: before_install:
- chmod +x gradlew - chmod +x gradlew
Expand Down
4 changes: 0 additions & 4 deletions gradle.properties
Expand Up @@ -2,10 +2,6 @@
# https://www.jetbrains.com/intellij-repository/releases # https://www.jetbrains.com/intellij-repository/releases
# https://www.jetbrains.com/intellij-repository/snapshots # https://www.jetbrains.com/intellij-repository/snapshots
# #
#ideaVersion=2017.2
#ideaVersion=2017.2.7
#ideaVersion=2017.3
#ideaVersion=2017.3.5
#ideaVersion=2018.1 #ideaVersion=2018.1
#ideaVersion=2018.1.6 #ideaVersion=2018.1.6
#ideaVersion=2018.2 #ideaVersion=2018.2
Expand Down
2 changes: 2 additions & 0 deletions parts/pluginChanges.html
Expand Up @@ -5,7 +5,9 @@
<li>Fixed #504: Added Support for Delombok of @EqualsAndHashcode and @ToString Exclude/Include annotations</li> <li>Fixed #504: Added Support for Delombok of @EqualsAndHashcode and @ToString Exclude/Include annotations</li>
<li>Fixed #507: @Value and @FieldDefaults should skip static fields</li> <li>Fixed #507: @Value and @FieldDefaults should skip static fields</li>
<li>Fixed #472: Lombok should not interfer with java 10 'var'</li> <li>Fixed #472: Lombok should not interfer with java 10 'var'</li>
<li>Fixed #530: Remove explicit type argument leads to error</li>
<li>Fixed #531: Inspection for Lombok annotations incorrectly highlights 'var'</li> <li>Fixed #531: Inspection for Lombok annotations incorrectly highlights 'var'</li>
<li>Better Support for @Cleanup: 'AutoCloseableResource'-Inspection can handle @Cleanup correctly in IntelliJ</li>
</ol> </ol>
</li> </li>
<li>0.21 <li>0.21
Expand Down
Expand Up @@ -36,9 +36,7 @@ private boolean isActionAvailable(AnActionEvent e) {
final VirtualFile file = getVirtualFiles(e); final VirtualFile file = getVirtualFiles(e);
if (getEventProject(e) != null && file != null) { if (getEventProject(e) != null && file != null) {
final FileType fileType = file.getFileType(); final FileType fileType = file.getFileType();
if (StdFileTypes.JAVA.equals(fileType)) { return StdFileTypes.JAVA.equals(fileType);
return true;
}
} }
return false; return false;
} }
Expand Down
Expand Up @@ -198,11 +198,9 @@ private static boolean checkCalls(PsiElement scope, PsiMethod method) {
private boolean isThisReference(PsiReference reference) { private boolean isThisReference(PsiReference reference) {
if (reference != null) { if (reference != null) {
final PsiElement referenceElement = reference.getElement(); final PsiElement referenceElement = reference.getElement();
if (referenceElement instanceof PsiJavaCodeReferenceElement && return referenceElement instanceof PsiJavaCodeReferenceElement &&
referenceElement.getParent() instanceof PsiMethodCallExpression && referenceElement.getParent() instanceof PsiMethodCallExpression &&
"this".equals(((PsiJavaCodeReferenceElement) referenceElement).getReferenceName())) { "this".equals(((PsiJavaCodeReferenceElement) referenceElement).getReferenceName());
return true;
}
} }
return false; return false;
} }
Expand Down
Expand Up @@ -22,9 +22,7 @@ public boolean canBeFinal(PsiMember member) {
} }


final PsiClass psiClass = PsiTreeUtil.getParentOfType(member, PsiClass.class); final PsiClass psiClass = PsiTreeUtil.getParentOfType(member, PsiClass.class);
if (null != psiClass && PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Setter.class, Data.class, Value.class)) { return null == psiClass || !PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Setter.class, Data.class, Value.class);
return false;
}
} }
return true; return true;
} }
Expand Down
@@ -0,0 +1,17 @@
package de.plushnikov.intellij.plugin.extension;

import com.intellij.codeInspection.resources.ImplicitResourceCloser;
import com.intellij.psi.PsiVariable;
import de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil;
import lombok.Cleanup;
import org.jetbrains.annotations.NotNull;

/**
* Implement additional way to close AutoCloseables by @lombok.Cleanup for IntelliJ
*/
public class LombokCleanUpImplicitResourceCloser implements ImplicitResourceCloser {
@Override
public boolean isSafelyClosed(@NotNull PsiVariable variable) {
return PsiAnnotationSearchUtil.isAnnotatedWith(variable, Cleanup.class);
}
}
Expand Up @@ -36,11 +36,9 @@ public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile fi
} }


//Handling onX parameters //Handling onX parameters
if (OnXAnnotationHandler.isOnXParameterAnnotation(highlightInfo, file) return !OnXAnnotationHandler.isOnXParameterAnnotation(highlightInfo, file)
|| OnXAnnotationHandler.isOnXParameterValue(highlightInfo, file) && !OnXAnnotationHandler.isOnXParameterValue(highlightInfo, file)
|| LOMBOK_ANYANNOTATIONREQUIRED.matcher(description).matches()) { && !LOMBOK_ANYANNOTATIONREQUIRED.matcher(description).matches();
return false;
}
} }
} }
return true; return true;
Expand Down
Expand Up @@ -31,11 +31,7 @@ public boolean equals(Object o) {
if (configKey != null ? !configKey.equalsIgnoreCase(that.configKey) : that.configKey != null) { if (configKey != null ? !configKey.equalsIgnoreCase(that.configKey) : that.configKey != null) {
return false; return false;
} }
if (directoryName != null ? !directoryName.equals(that.directoryName) : that.directoryName != null) { return directoryName != null ? directoryName.equals(that.directoryName) : that.directoryName == null;
return false;
}

return true;
} }


@Override @Override
Expand Down
@@ -1,5 +1,5 @@
package de.plushnikov.intellij.plugin.processor; package de.plushnikov.intellij.plugin.processor;


public enum LombokPsiElementUsage { public enum LombokPsiElementUsage {
NONE, USAGE, READ, WRITE, READ_WRITE; NONE, USAGE, READ, WRITE, READ_WRITE
} }
Expand Up @@ -76,9 +76,9 @@ public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass p
return result; return result;
} }


protected void addFieldsAnnotation(Collection<PsiAnnotation> result, @NotNull PsiClass psiClass, Class<? extends Annotation>... annotations) { protected void addFieldsAnnotation(Collection<PsiAnnotation> result, @NotNull PsiClass psiClass, String... annotationFQNs) {
for (PsiField psiField : PsiClassUtil.collectClassFieldsIntern(psiClass)) { for (PsiField psiField : PsiClassUtil.collectClassFieldsIntern(psiClass)) {
PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiField, annotations); PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiField, annotationFQNs);
if (null != psiAnnotation) { if (null != psiAnnotation) {
result.add(psiAnnotation); result.add(psiAnnotation);
} }
Expand Down
Expand Up @@ -40,6 +40,8 @@ public class EqualsAndHashCodeProcessor extends AbstractClassProcessor {
private static final String CAN_EQUAL_METHOD_NAME = "canEqual"; private static final String CAN_EQUAL_METHOD_NAME = "canEqual";


private static final String INCLUDE_ANNOTATION_METHOD = "replaces"; private static final String INCLUDE_ANNOTATION_METHOD = "replaces";
private static final String EQUALSANDHASHCODE_INCLUDE = EqualsAndHashCode.Include.class.getName().replace("$", ".");
private static final String EQUALSANDHASHCODE_EXCLUDE = EqualsAndHashCode.Exclude.class.getName().replace("$", ".");


private final EqualsAndHashCodeToStringHandler handler; private final EqualsAndHashCodeToStringHandler handler;


Expand Down Expand Up @@ -342,7 +344,7 @@ private boolean readCallSuperAnnotationOrConfigProperty(@NotNull PsiAnnotation p
@Override @Override
public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) { public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) {
final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass); final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass);
addFieldsAnnotation(result, psiClass, EqualsAndHashCode.Include.class, EqualsAndHashCode.Exclude.class); addFieldsAnnotation(result, psiClass, EQUALSANDHASHCODE_INCLUDE, EQUALSANDHASHCODE_EXCLUDE);
return result; return result;
} }


Expand Down
Expand Up @@ -33,6 +33,8 @@ public class ToStringProcessor extends AbstractClassProcessor {
private static final String INCLUDE_ANNOTATION_METHOD = "name"; private static final String INCLUDE_ANNOTATION_METHOD = "name";
private static final String INCLUDE_ANNOTATION_RANK = "rank"; private static final String INCLUDE_ANNOTATION_RANK = "rank";
private static final String INCLUDE_ANNOTATION_SKIP_NULL = "skipNull"; private static final String INCLUDE_ANNOTATION_SKIP_NULL = "skipNull";
private static final String TOSTRING_INCLUDE = ToString.Include.class.getName().replace("$", ".");
private static final String TOSTRING_EXCLUDE = ToString.Exclude.class.getName().replace("$", ".");


private final EqualsAndHashCodeToStringHandler handler; private final EqualsAndHashCodeToStringHandler handler;


Expand Down Expand Up @@ -180,7 +182,7 @@ private String createParamString(@NotNull PsiClass psiClass, @NotNull Collection
@Override @Override
public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) { public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) {
final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass); final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass);
addFieldsAnnotation(result, psiClass, ToString.Include.class, ToString.Exclude.class); addFieldsAnnotation(result, psiClass, TOSTRING_INCLUDE, TOSTRING_EXCLUDE);
return result; return result;
} }


Expand Down
Expand Up @@ -32,6 +32,9 @@
*/ */
public class BuilderProcessor extends AbstractClassProcessor { public class BuilderProcessor extends AbstractClassProcessor {


private static final String SINGULAR_CLASS = Singular.class.getName();
private static final String BUILDER_DEFAULT_CLASS = Builder.Default.class.getName().replace("$", ".");

private final BuilderHandler builderHandler; private final BuilderHandler builderHandler;
private final AllArgsConstructorProcessor allArgsConstructorProcessor; private final AllArgsConstructorProcessor allArgsConstructorProcessor;


Expand All @@ -51,7 +54,7 @@ public boolean isEnabled(@NotNull PropertiesComponent propertiesComponent) {
@Override @Override
public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) { public Collection<PsiAnnotation> collectProcessedAnnotations(@NotNull PsiClass psiClass) {
final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass); final Collection<PsiAnnotation> result = super.collectProcessedAnnotations(psiClass);
addFieldsAnnotation(result, psiClass, Singular.class, Builder.Default.class); addFieldsAnnotation(result, psiClass, SINGULAR_CLASS, BUILDER_DEFAULT_CLASS);
return result; return result;
} }


Expand Down
Expand Up @@ -33,7 +33,7 @@ protected boolean validate(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiCla
result = super.validate(psiAnnotation, psiClass, builder); result = super.validate(psiAnnotation, psiClass, builder);


final String staticConstructorName = getStaticConstructorName(psiAnnotation); final String staticConstructorName = getStaticConstructorName(psiAnnotation);
result &= validateIsConstructorNotDefined(psiClass, staticConstructorName, Collections.<PsiField>emptyList(), builder); result &= validateIsConstructorNotDefined(psiClass, staticConstructorName, Collections.emptyList(), builder);


return result; return result;
} }
Expand Down
Expand Up @@ -74,7 +74,7 @@ public static AccessorsInfo build(@Nullable PsiClass psiClass) {
containingClass = containingClass.getContainingClass(); containingClass = containingClass.getContainingClass();
} }


return buildAccessorsInfo(psiClass, null, null, Collections.<String>emptySet()); return buildAccessorsInfo(psiClass, null, null, Collections.emptySet());
} }


@NotNull @NotNull
Expand Down
Expand Up @@ -80,14 +80,14 @@ private <K, V> void putProcessor(final Map<K, Collection<V>> map, final K key, f
@NotNull @NotNull
public Collection<Processor> getLombokProcessors(@NotNull Class supportedClass) { public Collection<Processor> getLombokProcessors(@NotNull Class supportedClass) {
final Collection<Processor> result = lombokTypeProcessors.get(supportedClass); final Collection<Processor> result = lombokTypeProcessors.get(supportedClass);
return result == null ? Collections.<Processor>emptySet() : result; return result == null ? Collections.emptySet() : result;
} }


@NotNull @NotNull
public Collection<Processor> getProcessors(@NotNull PsiAnnotation psiAnnotation) { public Collection<Processor> getProcessors(@NotNull PsiAnnotation psiAnnotation) {
final String qualifiedName = psiAnnotation.getQualifiedName(); final String qualifiedName = psiAnnotation.getQualifiedName();
final Collection<Processor> result = qualifiedName == null ? null : lombokProcessors.get(qualifiedName); final Collection<Processor> result = qualifiedName == null ? null : lombokProcessors.get(qualifiedName);
return result == null ? Collections.<Processor>emptySet() : result; return result == null ? Collections.emptySet() : result;
} }


private boolean verifyLombokAnnotationPresent(@NotNull PsiClass psiClass) { private boolean verifyLombokAnnotationPresent(@NotNull PsiClass psiClass) {
Expand Down
Expand Up @@ -113,11 +113,7 @@ public boolean equals(Object o) {


LombokLightModifierList that = (LombokLightModifierList) o; LombokLightModifierList that = (LombokLightModifierList) o;


if (!myAnnotations.equals(that.myAnnotations)) { return myAnnotations.equals(that.myAnnotations);
return false;
}

return true;
} }


@Override @Override
Expand Down
Expand Up @@ -72,7 +72,7 @@ private void applyFixInner(final Project project) {
final Editor editor = CodeInsightUtil.positionCursor(project, file, myAnnotation); final Editor editor = CodeInsightUtil.positionCursor(project, file, myAnnotation);
if (editor != null) { if (editor != null) {
new WriteCommandAction(project, file) { new WriteCommandAction(project, file) {
protected void run(@NotNull Result result) throws Throwable { protected void run(@NotNull Result result) {
final PsiNameValuePair valuePair = selectAnnotationAttribute(); final PsiNameValuePair valuePair = selectAnnotationAttribute();


if (null != valuePair) { if (null != valuePair) {
Expand Down
Expand Up @@ -77,7 +77,7 @@ private void applyFixInner(final Project project) {
final Editor editor = CodeInsightUtil.positionCursor(project, psiFile, myClass.getLBrace()); final Editor editor = CodeInsightUtil.positionCursor(project, psiFile, myClass.getLBrace());
if (editor != null) { if (editor != null) {
new WriteCommandAction(project, psiFile) { new WriteCommandAction(project, psiFile) {
protected void run(@NotNull Result result) throws Throwable { protected void run(@NotNull Result result) {


final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(myClass.getProject()); final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(myClass.getProject());
final PsiField psiField = psiElementFactory.createField(myName, myType); final PsiField psiField = psiElementFactory.createField(myName, myType);
Expand Down
Expand Up @@ -105,7 +105,7 @@ public boolean isModified() {
} }


@Override @Override
public void apply() throws ConfigurationException { public void apply() {
ProjectSettings.setEnabled(myPropertiesComponent, ProjectSettings.LOMBOK_ENABLED_IN_PROJECT, myEnableLombokInProject.isSelected()); ProjectSettings.setEnabled(myPropertiesComponent, ProjectSettings.LOMBOK_ENABLED_IN_PROJECT, myEnableLombokInProject.isSelected());


ProjectSettings.setEnabled(myPropertiesComponent, ProjectSettings.IS_VAL_ENABLED, myEnableValSupport.isSelected()); ProjectSettings.setEnabled(myPropertiesComponent, ProjectSettings.IS_VAL_ENABLED, myEnableValSupport.isSelected());
Expand Down
Expand Up @@ -24,6 +24,11 @@ public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner psiModi
return findAnnotationQuick(psiModifierListOwner.getModifierList(), annotationFQN); return findAnnotationQuick(psiModifierListOwner.getModifierList(), annotationFQN);
} }


@Nullable
public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull String... annotationFQNs) {
return findAnnotationQuick(psiModifierListOwner.getModifierList(), annotationFQNs);
}

@Nullable @Nullable
public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull final Class<? extends Annotation> annotationType) { public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull final Class<? extends Annotation> annotationType) {
return findAnnotationQuick(psiModifierListOwner.getModifierList(), annotationType.getName()); return findAnnotationQuick(psiModifierListOwner.getModifierList(), annotationType.getName());
Expand Down
Expand Up @@ -76,7 +76,7 @@ public static boolean methodMatches(
return true; return true;
} }


public static boolean typesAreEquivalent( private static boolean typesAreEquivalent(
@Nullable PsiType type1, @Nullable PsiType type2) { @Nullable PsiType type1, @Nullable PsiType type2) {
if (type1 == null) { if (type1 == null) {
return type2 == null; return type2 == null;
Expand Down
Expand Up @@ -25,20 +25,4 @@ public static <T, R> void setFinalFieldPerReflection(Class<T> clazz, T instance,
LOG.error(x); LOG.error(x);
} }
} }

public static <T, R> R getFieldPerReflection(Class<T> clazz, T instance, Class<R> fieldClass, String fieldName) {
R result = null;
try {
final Field declaredField = clazz.getDeclaredField(fieldName);
declaredField.setAccessible(true);
result = (R) declaredField.get(instance);
} catch (IllegalArgumentException x) {
LOG.error(x);
} catch (IllegalAccessException x) {
LOG.error(x);
} catch (NoSuchFieldException e) {
LOG.error(e);
}
return result;
}
} }
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Expand Up @@ -59,6 +59,8 @@
<fileBasedIndex implementation="de.plushnikov.intellij.plugin.lombokconfig.LombokConfigIndex"/> <fileBasedIndex implementation="de.plushnikov.intellij.plugin.lombokconfig.LombokConfigIndex"/>


<custom.exception.handler implementation="de.plushnikov.intellij.plugin.handler.SneakyThrowsExceptionHandler"/> <custom.exception.handler implementation="de.plushnikov.intellij.plugin.handler.SneakyThrowsExceptionHandler"/>
<implicit.resource.closer
implementation="de.plushnikov.intellij.plugin.extension.LombokCleanUpImplicitResourceCloser"/>


<!--<referencesSearch implementation="de.plushnikov.intellij.plugin.extension.LombokReferenceSearcher"/>--> <!--<referencesSearch implementation="de.plushnikov.intellij.plugin.extension.LombokReferenceSearcher"/>-->
<findUsagesHandlerFactory implementation="de.plushnikov.intellij.plugin.extension.LombokFieldFindUsagesHandlerFactory"/> <findUsagesHandlerFactory implementation="de.plushnikov.intellij.plugin.extension.LombokFieldFindUsagesHandlerFactory"/>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/lombokBundle.properties
Expand Up @@ -26,7 +26,9 @@ Fixes:<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/504">#504</a>): Added Support for Delombok of @EqualsAndHashcode. and @ToString.Exclude/Include annotations<br>\ - Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/504">#504</a>): Added Support for Delombok of @EqualsAndHashcode. and @ToString.Exclude/Include annotations<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/507">#507</a>): @Value and @FieldDefaults should skip static fields<br>\ - Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/507">#507</a>): @Value and @FieldDefaults should skip static fields<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/472">#472</a>): Lombok should not interfer with java 10 'var'<br>\ - Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/472">#472</a>): Lombok should not interfer with java 10 'var'<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/530">#530</a>): Remove explicit type argument leads to error<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/531">#531</a>): Inspection for Lombok annotations incorrectly highlights 'var'<br>\ - Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/531">#531</a>): Inspection for Lombok annotations incorrectly highlights 'var'<br>\
- Better Support for @Cleanup: 'AutoCloseableResource'-Inspection can handle @Cleanup correctly in IntelliJ<br>\
<br>\ <br>\
If you find my plugin helpful, donate me using <br><b>\ If you find my plugin helpful, donate me using <br><b>\
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\\&hosted_button_id=3F9HXD7A2SMCN">PayPal</a>\ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\\&hosted_button_id=3F9HXD7A2SMCN">PayPal</a>\
Expand Down
Expand Up @@ -15,61 +15,61 @@ public class LombokPluginProjectValidatorComponentTest {
private OrderEntry orderEntry; private OrderEntry orderEntry;


@Before @Before
public void setUp() throws Exception { public void setUp() {
component = new LombokPluginProjectValidatorComponent(null); component = new LombokPluginProjectValidatorComponent(null);
orderEntry = mock(OrderEntry.class); orderEntry = mock(OrderEntry.class);
} }


@Test @Test
public void parseLombokVersionFromGradle() throws Exception { public void parseLombokVersionFromGradle() {
when(orderEntry.getPresentableName()).thenReturn("Gradle: org.projectlombok:lombok:1.16.8"); when(orderEntry.getPresentableName()).thenReturn("Gradle: org.projectlombok:lombok:1.16.8");
assertEquals("1.16.8", component.parseLombokVersion(orderEntry)); assertEquals("1.16.8", component.parseLombokVersion(orderEntry));
} }


@Test @Test
public void parseLombokVersionFromMaven() throws Exception { public void parseLombokVersionFromMaven() {
when(orderEntry.getPresentableName()).thenReturn("Maven: org.projectlombok:lombok:1.16.6"); when(orderEntry.getPresentableName()).thenReturn("Maven: org.projectlombok:lombok:1.16.6");
assertEquals("1.16.6", component.parseLombokVersion(orderEntry)); assertEquals("1.16.6", component.parseLombokVersion(orderEntry));
} }


@Test @Test
public void parseLombokVersionFromUnknown() throws Exception { public void parseLombokVersionFromUnknown() {
when(orderEntry.getPresentableName()).thenReturn("lombok"); when(orderEntry.getPresentableName()).thenReturn("lombok");
assertNull(component.parseLombokVersion(orderEntry)); assertNull(component.parseLombokVersion(orderEntry));
} }


@Test @Test
public void compareVersionString1_2() throws Exception { public void compareVersionString1_2() {
assertEquals(-1, component.compareVersionString("1", "2")); assertEquals(-1, component.compareVersionString("1", "2"));
} }


@Test @Test
public void compareVersionString__2() throws Exception { public void compareVersionString__2() {
assertEquals(-1, component.compareVersionString("", "2")); assertEquals(-1, component.compareVersionString("", "2"));
} }


@Test @Test
public void compareVersionString123_121() throws Exception { public void compareVersionString123_121() {
assertEquals(1, component.compareVersionString("1.2.3", "1.2.1")); assertEquals(1, component.compareVersionString("1.2.3", "1.2.1"));
} }


@Test @Test
public void compareVersionString1166_1168() throws Exception { public void compareVersionString1166_1168() {
assertEquals(-1, component.compareVersionString("1.16.6", "1.16.8")); assertEquals(-1, component.compareVersionString("1.16.6", "1.16.8"));
} }


@Test @Test
public void compareVersionString1168_1168() throws Exception { public void compareVersionString1168_1168() {
assertEquals(0, component.compareVersionString("1.16.8", "1.16.8")); assertEquals(0, component.compareVersionString("1.16.8", "1.16.8"));
} }


@Test @Test
public void compareVersionString0102_1168() throws Exception { public void compareVersionString0102_1168() {
assertEquals(-1, component.compareVersionString("0.10.2", "1.16.8")); assertEquals(-1, component.compareVersionString("0.10.2", "1.16.8"));
} }


@Test @Test
public void compareVersionString1169_1168() throws Exception { public void compareVersionString1169_1168() {
assertEquals(1, component.compareVersionString("1.16.9", "1.16.8")); assertEquals(1, component.compareVersionString("1.16.9", "1.16.8"));
} }
} }

0 comments on commit 28b661a

Please sign in to comment.