本文整理汇总了Java中com.sun.mirror.declaration.Modifier类的典型用法代码示例。如果您正苦于以下问题:Java Modifier类的具体用法?Java Modifier怎么用?Java Modifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Modifier类属于com.sun.mirror.declaration包,在下文中一共展示了Modifier类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClassModifiers
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
private boolean testClassModifiers(ClassDeclaration classDeclaration) {
Collection<Modifier> modifiers = classDeclaration.getModifiers();
boolean isPublic = false;
for (Modifier modifier : modifiers) {
if (modifier.equals(Modifier.FINAL)) {
reportError(classDeclaration, ErrorMessages.IS_FINAL_ERROR_MESSAGE);
return false;
}
if (modifier.equals(Modifier.PUBLIC)) {
isPublic = true;
}
}
if (!isPublic) {
reportError(classDeclaration, ErrorMessages.IS_NOT_PUBLIC_ERROR_MESSAGE);
return false;
}
return true;
}
示例2: testFieldModifiers
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
private boolean testFieldModifiers(FieldDeclaration fieldDeclaration) {
Collection<Modifier> modifiers = fieldDeclaration.getModifiers();
// must not worry for private/protected. cannot be accessed from outside.
if (modifiers.contains(Modifier.PROTECTED) || modifiers.contains(Modifier.PRIVATE))
return true;
// no public/package access without getters/setters for non final fields
if (!fieldDeclaration.getModifiers().contains(Modifier.FINAL) &&
!checkGettersSetters(fieldDeclaration.getSimpleName())) {
reportWarning(fieldDeclaration, "The class declares the " +
(modifiers.contains(Modifier.PUBLIC) ? "public" : "package") + " field " +
fieldDeclaration.getSimpleName() + ".\n" + ErrorMessages.NO_GETTERS_SETTERS_ERROR_MESSAGE);
return false;
}
return true;
}
示例3: verifyConstructors
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
private ConstructorCheckResult verifyConstructors(ClassDeclaration classDeclaration) {
ConstructorCheckResult ccr = new ConstructorCheckResult();
Collection<ConstructorDeclaration> constructors = classDeclaration.getConstructors();
if (constructors.isEmpty()) {
// has no constructors at all! son of a butch!
ccr.hasNoArgConstructor = true;
return ccr;
}
// one of the constructors must have no args
for (ConstructorDeclaration constructorDeclaration : constructors) {
if (constructorDeclaration.getParameters().isEmpty()) {
ccr.hasNoArgConstructor = true;
if (constructorDeclaration.getModifiers().contains(Modifier.PRIVATE))
ccr.isFinalNoArgConstructor = true;
}
}
return ccr;
}
示例4: validateField
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
private static void validateField(FieldDeclaration field) {
// Check if field is "public static final"
Collection<Modifier> modifiers = field.getModifiers();
if ( modifiers.size() != 3
|| !modifiers.contains(Modifier.PUBLIC)
|| !modifiers.contains(Modifier.STATIC)
|| !modifiers.contains(Modifier.FINAL) ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
}
// Check suported types (int, long, float, String)
TypeMirror field_type = field.getType();
if ( field_type instanceof PrimitiveType ) {
PrimitiveType field_type_prim = (PrimitiveType)field_type;
PrimitiveType.Kind field_kind = field_type_prim.getKind();
if ( field_kind != PrimitiveType.Kind.INT
&& field_kind != PrimitiveType.Kind.LONG
&& field_kind != PrimitiveType.Kind.FLOAT
&& field_kind != PrimitiveType.Kind.BYTE ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long' or 'float'");
}
} else if ( "java.lang.String".equals(field_type.toString()) ) {
} else {
throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
}
Object field_value = field.getConstantValue();
if ( field_value == null ) {
throw new RuntimeException("Field " + field.getSimpleName() + " has no initial value");
}
}
示例5: getFilter
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
/**
* Returns a filter that selects declarations containing all of a
* collection of modifiers.
*
* @param mods the modifiers to match (non-null)
* @return a filter that matches declarations containing <tt>mods</tt>
*/
public static DeclarationFilter getFilter(
final Collection<Modifier> mods) {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return d.getModifiers().containsAll(mods);
}
};
}
示例6: matches
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
public boolean matches(Declaration d) {
Collection<Modifier> mods = d.getModifiers();
if (mod1 == null) { // looking for package private
return !(mods.contains(PUBLIC) ||
mods.contains(PROTECTED) ||
mods.contains(PRIVATE));
}
return mods.contains(mod1) &&
(mod2 == null || mods.contains(mod2));
}
示例7: visitClassDeclaration
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
public void visitClassDeclaration (ClassDeclaration classDeclaration)
{
CookCCOption option = classDeclaration.getAnnotation (CookCCOption.class);
if (option == null)
return;
m_option = option;
m_doc.setMain (false);
String inputClass = classDeclaration.getQualifiedName ();
m_doc.setProperty (PROP_INPUT, inputClass);
ClassType superClassType = classDeclaration.getSuperclass ();
ClassDeclaration superClass = superClassType.getDeclaration ();
m_doc.setProperty (PROP_OUTPUT, computeOutputClass (superClassType));
if (superClass.getModifiers ().contains (Modifier.PUBLIC))
m_doc.setProperty (PROP_PUBLIC, Boolean.TRUE);
m_doc.setUnicode (option.unicode ());
m_start = option.start ();
String tokenClass = option.tokenClass ();
if (tokenClass != null && (tokenClass = tokenClass.trim ()).length () != 0)
m_doc.setProperty (PROP_TOKEN, tokenClass);
// try to get the file header
try
{
m_doc.addCode ("fileheader", generateFileHeader (FileHeaderScanner.getFileHeader (superClass.getPosition ().file ())));
}
catch (Exception ex)
{
}
// try to get the class header
m_doc.addCode ("classheader", generateClassHeader (superClass.getDocComment ()));
m_parent.addDocument (classDeclaration.getQualifiedName (), m_doc);
}
示例8: getFilter
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
/**
* Returns a filter that selects declarations containing all of a
* collection of modifiers.
*
* @param mods the modifiers to match (non-null)
* @return a filter that matches declarations containing <tt>mods</tt>
*/
public static DeclarationFilter getFilter(
final Collection<Modifier> mods) {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return d.getModifiers().containsAll(mods);
}
};
}
示例9: matches
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
public boolean matches(Declaration d) {
Collection<Modifier> mods = d.getModifiers();
if (mod1 == null) { // looking for package private
return !(mods.contains(PUBLIC) ||
mods.contains(PROTECTED) ||
mods.contains(PRIVATE));
}
return mods.contains(mod1) &&
(mod2 == null || mods.contains(mod2));
}
示例10: testMethodModifiers
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
private boolean testMethodModifiers(MethodDeclaration methodDeclaration) {
Collection<Modifier> modifiers = methodDeclaration.getModifiers();
if (modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.PRIVATE)) {
reportError(methodDeclaration, " The class declares the final method " +
methodDeclaration.getSimpleName() + ".\n" + ErrorMessages.HAS_FINAL_METHOD_ERROR_MESSAGE);
return false;
}
return true;
}
示例11: AccessFilter
import com.sun.mirror.declaration.Modifier; //导入依赖的package包/类
AccessFilter(Modifier m) {
mod1 = m;
}