Java Code Examples for org.eclipse.jdt.core.dom.BodyDeclaration#modifiers()

The following examples show how to use org.eclipse.jdt.core.dom.BodyDeclaration#modifiers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public static void checkModifiers(ProblemCollector collector, BodyDeclaration elem,
		Predicate<Modifier> allowSpecific) {
	for (Object obj : elem.modifiers()) {
		if (!(obj instanceof Modifier)) {
			continue;
		}
		Modifier modifier = (Modifier) obj;
		boolean valid;
		if (allowSpecific.test(modifier)) {
			valid = true;
		} else {
			valid = modifier.isPrivate() || modifier.isPublic() || modifier.isProtected() || modifier.isFinal();
		}
		if (!valid) {
			collector.report(INVALID_MODIFIER.create(collector.getSourceInfo(), modifier));
		}
	}
}
 
Example 2
Source File: UtilTools.java    From apidiff with MIT License 5 votes vote down vote up
public static Boolean containsModifier(BodyDeclaration node, String modifier){
	for (Object m : node.modifiers()) {
		if(m.toString().equals(modifier)){
			return true;
		}
	}
	return false;
}
 
Example 3
Source File: UtilTools.java    From apidiff with MIT License 5 votes vote down vote up
public static String getVisibility(BodyDeclaration node){
	for (Object modifier : node.modifiers()) {
		if(modifier.toString().equals("public") || modifier.toString().equals("private")
				|| modifier.toString().equals("protected")){
			return modifier.toString();
		}
	}
	
	return "default";
}
 
Example 4
Source File: GwtIncompatibleNodeCollector.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private static boolean hasGwtIncompatibleAnnotation(BodyDeclaration declaration) {
  for (Object modifier : declaration.modifiers()) {
    if (modifier instanceof Annotation) {
      Name name = ((Annotation) modifier).getTypeName();
      // Get the name of the class without package, since the {@code GwtIncompatible} annotation
      // can be defined anywhere.
      String simpleName =
          name.isSimpleName() ? name.toString() : ((QualifiedName) name).getName().toString();
      if (simpleName.equals("GwtIncompatible")) {
        return true;
      }
    }
  }
  return false;
}
 
Example 5
Source File: JavaASTUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Modifier findPrivateModifier(BodyDeclaration decl) {
  List<IExtendedModifier> modifiers = decl.modifiers();
  for (IExtendedModifier m : modifiers) {
    if (m.isModifier()) {
      Modifier modifier = (Modifier) m;
      if (modifier.isPrivate()) {
        return modifier;
      }
    }
  }
  return null;
}
 
Example 6
Source File: SharedUtils.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the annotation node if it is present on the declaration or null
 */
public static Annotation obtainAnnotation(BodyDeclaration declaration, Class<?> annotationClass) {
	for (Object mod : declaration.modifiers()) {
		IExtendedModifier modifier = (IExtendedModifier) mod;
		if (modifier.isAnnotation()) {
			Annotation annotation = (Annotation) modifier;
			if (identicalAnnotations(annotation, annotationClass)) {
				return annotation;
			}
		}
	}
	return null;
}
 
Example 7
Source File: SharedUtils.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
public static IAnnotationBinding obtainAnnotationBinding(BodyDeclaration declaration, Class<?> annotationClass) {
	for (Object mod : declaration.modifiers()) {
		IExtendedModifier modifier = (IExtendedModifier) mod;
		if (modifier.isAnnotation()) {
			Annotation annotation = (Annotation) modifier;
			if (identicalAnnotations(annotation, annotationClass)) {
				return annotation.resolveAnnotationBinding();
			}
		}
	}
	return null;
}