use of javax.lang.model.element.Modifier in project j2objc by google.
the class ElementUtil method toModifierSet.
public static Set<Modifier> toModifierSet(int modifiers) {
Set<Modifier> set = modifierSets.get(modifiers);
if (set == null) {
set = EnumSet.noneOf(Modifier.class);
if ((modifiers & java.lang.reflect.Modifier.PUBLIC) > 0) {
set.add(Modifier.PUBLIC);
}
if ((modifiers & java.lang.reflect.Modifier.PRIVATE) > 0) {
set.add(Modifier.PRIVATE);
}
if ((modifiers & java.lang.reflect.Modifier.PROTECTED) > 0) {
set.add(Modifier.PROTECTED);
}
if ((modifiers & java.lang.reflect.Modifier.STATIC) > 0) {
set.add(Modifier.STATIC);
}
if ((modifiers & java.lang.reflect.Modifier.FINAL) > 0) {
set.add(Modifier.FINAL);
}
if ((modifiers & java.lang.reflect.Modifier.SYNCHRONIZED) > 0) {
set.add(Modifier.SYNCHRONIZED);
}
if ((modifiers & java.lang.reflect.Modifier.VOLATILE) > 0) {
set.add(Modifier.VOLATILE);
}
if ((modifiers & java.lang.reflect.Modifier.TRANSIENT) > 0) {
set.add(Modifier.TRANSIENT);
}
if ((modifiers & java.lang.reflect.Modifier.NATIVE) > 0) {
set.add(Modifier.NATIVE);
}
if ((modifiers & java.lang.reflect.Modifier.ABSTRACT) > 0) {
set.add(Modifier.ABSTRACT);
}
if ((modifiers & java.lang.reflect.Modifier.STRICT) > 0) {
set.add(Modifier.STRICTFP);
}
// added in Java 8.
if ((modifiers & org.eclipse.jdt.core.dom.Modifier.DEFAULT) > 0) {
try {
Modifier m = Modifier.valueOf("DEFAULT");
set.add(m);
} catch (IllegalArgumentException e) {
// Can only add DEFAULT modifier in Java 8.
}
}
modifierSets.put(modifiers, set);
}
return set;
}
use of javax.lang.model.element.Modifier in project error-prone by google.
the class UseBinds method matchMethod.
@Override
public Description matchMethod(MethodTree method, VisitorState state) {
if (!CAN_BE_A_BINDS_METHOD.matches(method, state)) {
return NO_MATCH;
}
JCClassDecl enclosingClass = ASTHelpers.findEnclosingNode(state.getPath(), JCClassDecl.class);
// Dagger 1 modules don't support @Binds.
if (!IS_DAGGER_2_MODULE.matches(enclosingClass, state)) {
return NO_MATCH;
}
if (enclosingClass.getExtendsClause() != null) {
return fixByDelegating();
}
for (Tree member : enclosingClass.getMembers()) {
if (member.getKind().equals(Tree.Kind.METHOD) && !getSymbol(member).isConstructor()) {
MethodTree siblingMethod = (MethodTree) member;
Set<Modifier> siblingFlags = siblingMethod.getModifiers().getFlags();
if (!(siblingFlags.contains(Modifier.STATIC) || siblingFlags.contains(Modifier.ABSTRACT)) && !CAN_BE_A_BINDS_METHOD.matches(siblingMethod, state)) {
return fixByDelegating();
}
}
}
return fixByModifyingMethod(state, enclosingClass, method);
}
use of javax.lang.model.element.Modifier in project squidb by yahoo.
the class ModelMethodPlugin method checkExecutableElement.
private void checkExecutableElement(ExecutableElement e, List<ExecutableElement> modelMethods, List<ExecutableElement> staticModelMethods, DeclaredTypeName modelClass) {
Set<Modifier> modifiers = e.getModifiers();
if (e.getKind() == ElementKind.CONSTRUCTOR) {
// Don't copy constructors
return;
}
if (!modifiers.contains(Modifier.STATIC)) {
utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Model spec objects should never be instantiated, so non-static methods are meaningless. " + "Did you mean to make this a static method?", e);
return;
}
ModelMethod methodAnnotation = e.getAnnotation(ModelMethod.class);
// Don't assume error if method is private
if (methodAnnotation == null) {
if (modifiers.contains(Modifier.PUBLIC)) {
staticModelMethods.add(e);
} else if (!modifiers.contains(Modifier.PRIVATE)) {
utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "This method will not be added to the model definition. " + "Did you mean to annotate this method with @ModelMethod?", e);
}
} else {
List<? extends VariableElement> params = e.getParameters();
if (params.size() == 0) {
modelSpec.logError("@ModelMethod methods must have an abstract model as their first argument", e);
} else {
VariableElement firstParam = params.get(0);
TypeMirror paramType = firstParam.asType();
if (!checkFirstArgType(paramType, modelClass)) {
modelSpec.logError("@ModelMethod methods must have an abstract model as their first argument", e);
} else {
modelMethods.add(e);
}
}
}
}
use of javax.lang.model.element.Modifier in project butterknife by JakeWharton.
the class ButterKnifeProcessor method isInaccessibleViaGeneratedCode.
private boolean isInaccessibleViaGeneratedCode(Class<? extends Annotation> annotationClass, String targetThing, Element element) {
boolean hasError = false;
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Verify method modifiers.
Set<Modifier> modifiers = element.getModifiers();
if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
error(element, "@%s %s must not be private or static. (%s.%s)", annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(), element.getSimpleName());
hasError = true;
}
// Verify containing type.
if (enclosingElement.getKind() != CLASS) {
error(enclosingElement, "@%s %s may only be contained in classes. (%s.%s)", annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(), element.getSimpleName());
hasError = true;
}
// Verify containing class visibility is not private.
if (enclosingElement.getModifiers().contains(PRIVATE)) {
error(enclosingElement, "@%s %s may not be contained in private classes. (%s.%s)", annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(), element.getSimpleName());
hasError = true;
}
return hasError;
}
use of javax.lang.model.element.Modifier in project LoganSquare by bluelinelabs.
the class JsonObjectProcessor method addAllNonPrivateAccessors.
private void addAllNonPrivateAccessors(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
List<? extends Element> enclosedElements = element.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
ElementKind enclosedElementKind = enclosedElement.getKind();
if (enclosedElementKind == ElementKind.FIELD) {
Set<Modifier> modifiers = enclosedElement.getModifiers();
if (modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.TRANSIENT) && !modifiers.contains(Modifier.STATIC)) {
String getter = JsonFieldHolder.getGetter(enclosedElement, elements);
String setter = JsonFieldHolder.getSetter(enclosedElement, elements);
if (!TextUtils.isEmpty(getter) && !TextUtils.isEmpty(setter)) {
createOrUpdateFieldHolder(enclosedElement, elements, types, objectHolder);
}
}
}
}
}
Aggregations