Skip to content

Commit

Permalink
[#18] Added javadocs and did some polishing for 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Feb 23, 2018
1 parent 973e3c0 commit 904caf2
Show file tree
Hide file tree
Showing 69 changed files with 1,410 additions and 1,346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.Map;

/**
* Created by tobiasstamann on 24.08.17.
* Abstract base class for writers of java code and resources.
*
*/
public class AbstractSimpleWriter<T extends FileObject> {

Expand All @@ -21,16 +23,32 @@ public AbstractSimpleWriter(T fileObject) throws IOException {
this.foWriter = fileObject.openWriter();
}

/**
* Appends string content to the writer.
* @param content the content to append
* @throws IOException is thrown if content can't be written
*/
public void append(String content) throws IOException {
foWriter.append(content);
foWriter.flush();
}

/**
* Write char array content to the writer.
* @param buffer the buffer to append
* @throws IOException is thrown if buffer can't be written
*/
public void write(char[] buffer) throws IOException {
foWriter.write(buffer);
foWriter.flush();
}

/**
* Write a template based content.
* @param templateFileName the template resource file to use
* @param values the values to be used with template
* @throws IOException is thrown if content can't be written
*/
public void writeTemplate( String templateFileName, Map<String, Object> values) throws IOException {
String processedTemplate = TemplateProcessor.processTemplateResourceFile(templateFileName, values);

Expand All @@ -40,11 +58,20 @@ public void writeTemplate( String templateFileName, Map<String, Object> values)

}

/**
* Write string based content to the writer.
* @param content the content to write
* @throws IOException is thrown if content can't be written
*/
public void write(String content) throws IOException {
foWriter.write(content);
foWriter.flush();
}

/**
* Closes encapsulated writer.
* @throws IOException is thrown if writer can't be closed
*/
public void close() throws IOException {
foWriter.flush();
foWriter.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,24 @@ public SimpleResourceWriter createResource(String fileName) throws IOException {
}


/**
* Creates a class file writer.
* @param fileName the filename to use
* @param originatingElements the element which originates the creation of the class file
* @return a SimpleJavaWriter that can be used to write java classes
* @throws IOException is thrown if writer can't be created
*/
public SimpleJavaWriter createClassFile(String fileName, Element... originatingElements) throws IOException {
return new SimpleJavaWriter(ToolingProvider.getTooling().getFiler().createClassFile(fileName, originatingElements));
}

/**
* Creates a source file writer.
* @param fileName the filename to use
* @param originatingElements the element which originates the creation of the source file
* @return a SimpleJavaWriter that can be used to write java source code
* @throws IOException is thrown if writer can't be created
*/
public SimpleJavaWriter createSourceFile(String fileName, Element... originatingElements) throws IOException {
return new SimpleJavaWriter(ToolingProvider.getTooling().getFiler().createSourceFile(fileName, originatingElements));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.io.IOException;


/**
* A Simple java writer.
*/
public class SimpleJavaWriter extends AbstractSimpleWriter<JavaFileObject> {


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This package contains utility classes to create resource and java code files.
*/
package io.toolisticon.annotationprocessortoolkit.generators;
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.toolisticon.annotationprocessortoolkit.tools;

import io.toolisticon.annotationprocessortoolkit.internal.Utilities;
import io.toolisticon.annotationprocessortoolkit.tools.filter.Filters;
import io.toolisticon.annotationprocessortoolkit.tools.validator.Validators;
import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -485,7 +483,7 @@ public static boolean hasStrictfpModifier(Element e) {
* @return true if passed element has modifier, otherwise false
*/
private static boolean hasModifier(Element e, Modifier modifier) {
return Validators.MODIFIER_VALIDATOR.hasAllOf(e, modifier);
return CoreMatchers.BY_MODIFIER.getValidator().hasAllOf(e, modifier);
}

}
Expand Down Expand Up @@ -657,7 +655,7 @@ public static List<? extends Element> getEnclosedElementsByName(Element element,
return new ArrayList<Element>();
}

return Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), name);
return CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), name);

}

Expand Down Expand Up @@ -712,7 +710,7 @@ public static List<? extends Element> getEnclosedElementsOfKind(Element element,
return new ArrayList<Element>();
}

return Filters.ELEMENT_KIND_FILTER.filterByOneOf(element.getEnclosedElements(), kind);
return CoreMatchers.BY_ELEMENT_KIND.getFilter().filterByOneOf(element.getEnclosedElements(), kind);

}

Expand All @@ -730,7 +728,7 @@ public static List<? extends Element> getEnclosedElementsWithAllAnnotationsOf(El
return new ArrayList<Element>();
}

return Filters.ANNOTATION_FILTER.filterByAllOf(element.getEnclosedElements(), annotations);
return CoreMatchers.BY_ANNOTATION.getFilter().filterByAllOf(element.getEnclosedElements(), annotations);

}

Expand All @@ -747,7 +745,7 @@ public static List<? extends Element> getEnclosedElementsWithAtLeastOneAnnotatio
return new ArrayList<Element>();
}

return Filters.ANNOTATION_FILTER.filterByAtLeastOneOf(element.getEnclosedElements(), annotations);
return CoreMatchers.BY_ANNOTATION.getFilter().filterByAtLeastOneOf(element.getEnclosedElements(), annotations);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.toolisticon.annotationprocessortoolkit.internal;
package io.toolisticon.annotationprocessortoolkit.tools;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private CoreMatchers() {
/**
* Matcher to check if an Element has a specific name.
*/
public final static ExclusiveCharacteristicElementBasedCoreMatcher<String> BY_NAME = new ExclusiveCharacteristicElementBasedCoreMatcher<String>(new ByNameMatcher(), CoreMatcherValidationMessages.BY_NAME);
public final static ExclusiveCriteriaElementBasedCoreMatcher<String> BY_NAME = new ExclusiveCriteriaElementBasedCoreMatcher<String>(new ByNameMatcher(), CoreMatcherValidationMessages.BY_NAME);

/**
* Matcher to check if an Element name matches a specific regular expression.
Expand All @@ -70,7 +70,7 @@ private CoreMatchers() {
/**
* Matcher to check if an Element is of a specific ElementKind.
*/
public final static ExclusiveCharacteristicElementBasedCoreMatcher<ElementKind> BY_ELEMENT_KIND = new ExclusiveCharacteristicElementBasedCoreMatcher<ElementKind>(new ByElementKindMatcher(), CoreMatcherValidationMessages.BY_ELEMENT_KIND);
public final static ExclusiveCriteriaElementBasedCoreMatcher<ElementKind> BY_ELEMENT_KIND = new ExclusiveCriteriaElementBasedCoreMatcher<ElementKind>(new ByElementKindMatcher(), CoreMatcherValidationMessages.BY_ELEMENT_KIND);

/**
* Matcher to check if an Element has a specific Modifier.
Expand All @@ -81,28 +81,28 @@ private CoreMatchers() {
/**
* Matcher to check if an TypeElement matches a specific generic type.
*/
public final static ExclusiveCharacteristicElementBasedCoreMatcher<GenericType> BY_GENERIC_TYPE = new ExclusiveCharacteristicElementBasedCoreMatcher<GenericType>(new ByGenericTypeMatcher(), CoreMatcherValidationMessages.BY_GENERIC_TYPE);
public final static ExclusiveCriteriaElementBasedCoreMatcher<GenericType> BY_GENERIC_TYPE = new ExclusiveCriteriaElementBasedCoreMatcher<GenericType>(new ByGenericTypeMatcher(), CoreMatcherValidationMessages.BY_GENERIC_TYPE);

/**
* Matcher to check if an TypeElement matches a specific generic type.
*/
public final static ExclusiveCharacteristicCoreMatcher<TypeElement, Class> BY_RAW_TYPE = new ExclusiveCharacteristicCoreMatcher<TypeElement, Class>(new ByRawTypeMatcher(), CoreMatcherValidationMessages.BY_RAW_TYPE);
public final static ExclusiveCriteriaCoreMatcher<TypeElement, Class> BY_RAW_TYPE = new ExclusiveCriteriaCoreMatcher<TypeElement, Class>(new ByRawTypeMatcher(), CoreMatcherValidationMessages.BY_RAW_TYPE);


/**
* Matcher to check if an ExecutableElement has specific parameter types
*/
public final static ExclusiveCharacteristicCoreMatcher<ExecutableElement, String[]> BY_PARAMETER_TYPE_FQN = new ExclusiveCharacteristicCoreMatcher<ExecutableElement, String[]>(new ByParameterTypeFqnMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE_FQN);
public final static ExclusiveCriteriaCoreMatcher<ExecutableElement, String[]> BY_PARAMETER_TYPE_FQN = new ExclusiveCriteriaCoreMatcher<ExecutableElement, String[]>(new ByParameterTypeFqnMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE_FQN);

/**
* Matcher to check if an ExecutableElement has specific parameter types
*/
public final static ExclusiveCharacteristicCoreMatcher<ExecutableElement, Class[]> BY_PARAMETER_TYPE = new ExclusiveCharacteristicCoreMatcher<ExecutableElement, Class[]>(new ByParameterTypeMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE);
public final static ExclusiveCriteriaCoreMatcher<ExecutableElement, Class[]> BY_PARAMETER_TYPE = new ExclusiveCriteriaCoreMatcher<ExecutableElement, Class[]>(new ByParameterTypeMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE);

/**
* Matcher to check if an Element is assignable to a specific type
*/
public final static ExclusiveCharacteristicElementBasedCoreMatcher<Class> IS_ASSIGNABLE_TO = new ExclusiveCharacteristicElementBasedCoreMatcher<Class>(new IsAssignableToMatcher(), CoreMatcherValidationMessages.IS_ASSIGNABLE_TO);
public final static ExclusiveCriteriaElementBasedCoreMatcher<Class> IS_ASSIGNABLE_TO = new ExclusiveCriteriaElementBasedCoreMatcher<Class>(new IsAssignableToMatcher(), CoreMatcherValidationMessages.IS_ASSIGNABLE_TO);


// ---------------------------------------------------------------------------------
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.toolisticon.annotationprocessortoolkit.tools.corematcher;

import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCriteriaElementFilter;
import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher;
import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator;

import javax.lang.model.element.Element;


/**
* Convenience class to use just one class which can be used in Fluent validators and filters.
*/
public class ExclusiveCriteriaCoreMatcher<
ELEMENT extends Element,
CHARACTERISTIC
> extends AbstractBaseCoreMatcher{

/**
* The wrapped criteria matcher.
*/
private final CriteriaMatcher<ELEMENT, CHARACTERISTIC> matcher;

/**
* The constructor.
* @param matcher the criteria matcher to use
* @param defaultValidatorMessage the default message to use with validator
*/
public ExclusiveCriteriaCoreMatcher(CriteriaMatcher<ELEMENT, CHARACTERISTIC> matcher, CoreMatcherValidationMessages defaultValidatorMessage) {
super(defaultValidatorMessage);
this.matcher = matcher;
}

/**
* Gets the wrapped criteria matcher.
* @return the wrapped criteria matcher
*/
public CriteriaMatcher<ELEMENT, CHARACTERISTIC> getMatcher() {
return matcher;
}

/**
* Gets the validator for the wrapped criteria matcher.
* @return the criteria validator instance
*/
public ExclusiveCriteriaElementValidator<ELEMENT, CHARACTERISTIC, CriteriaMatcher<ELEMENT, CHARACTERISTIC>> getValidator() {
return new ExclusiveCriteriaElementValidator<ELEMENT, CHARACTERISTIC, CriteriaMatcher<ELEMENT, CHARACTERISTIC>>(matcher, getDefaultValidatorMessage());
}

/**
* Gets the filter for the wrapped criteria matcher.
* @return the criteria filter instance
*/
public ExclusiveCriteriaElementFilter<ELEMENT, CHARACTERISTIC, ExclusiveCriteriaElementValidator<ELEMENT, CHARACTERISTIC, CriteriaMatcher<ELEMENT, CHARACTERISTIC>>> getFilter() {
return new ExclusiveCriteriaElementFilter<ELEMENT, CHARACTERISTIC, ExclusiveCriteriaElementValidator<ELEMENT, CHARACTERISTIC, CriteriaMatcher<ELEMENT, CHARACTERISTIC>>>(getValidator());
}


}
Loading

0 comments on commit 904caf2

Please sign in to comment.