本文整理汇总了Java中org.eclipse.jdt.core.dom.FieldDeclaration.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration.getModifiers方法的具体用法?Java FieldDeclaration.getModifiers怎么用?Java FieldDeclaration.getModifiers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.FieldDeclaration
的用法示例。
在下文中一共展示了FieldDeclaration.getModifiers方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
Type fieldType = fieldDeclaration.getType();
int fieldModifiers = fieldDeclaration.getModifiers();
Visibility visibility = getVisibility(fieldModifiers);
// boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
for (VariableDeclarationFragment fragment : fragments) {
String fieldName = fragment.getName().getIdentifier();
final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
attribute.setStatic(isStatic);
attribute.setVisibility(visibility);
attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));
Expression expression = fragment.getInitializer();
if (expression != null) {
//attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
}
attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
}
return true;
}
示例2: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(FieldDeclaration node) {
int modifiers = node.getModifiers();
if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
List<VariableDeclarationFragment> fragments = node.fragments();
for (VariableDeclarationFragment varDeclFrag : fragments) {
IVariableBinding varBinding = varDeclFrag.resolveBinding();
String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
final TACVariable fieldVar = new TACVariable(varBinding);
if(!enclosingClass.equals(Config.MAINCLASS)){
context.addEncapsulatedVariable(fieldVar);
}
}
}
}
return super.visit(node);
}
示例3: parseFieldDeclaration
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
/**
* Factory Method for ASTField.
*
* @param node
* FiledDeclaration node of Eclipse AST
*/
public void parseFieldDeclaration(FieldDeclaration node) {
for (Object obj : node.fragments()) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) obj;
String fieldName = fragment.getName().toString();
int fieldModifier = node.getModifiers();
String fieldVisibility = getVisibility(fieldModifier);
Blob fieldBlob = new Blob(fieldVisibility + "\n", fieldName);
if (fieldMap.containsKey(fieldName)) {
int numConflicted = 0;
for (Blob field : fieldMap.get(fieldName)) {
conflict(field, fieldName, numConflicted++);
}
conflict(fieldBlob, fieldName, numConflicted);
}
fieldMap.put(fieldName, fieldBlob);
}
}
示例4: getVisibility
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private static String getVisibility(FieldDeclaration decl) {
int modifiers = decl.getModifiers();
if (Modifier.isPrivate(modifiers))
return "private";
if (Modifier.isProtected(modifiers))
return "protected";
if (Modifier.isPublic(modifiers))
return "public";
return "package";
}
示例5: isUiField
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
public static boolean isUiField(FieldDeclaration fieldDecl) {
if ((fieldDecl.getModifiers() & Modifier.STATIC) != 0) {
return false;
}
return (JavaASTUtils.findAnnotation(fieldDecl,
UiBinderConstants.UI_FIELD_ANNOTATION_NAME) != null);
}
示例6: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(FieldDeclaration node)
{
if (nestLevel != 1)
return false;
int modifiers = node.getModifiers();
// Check modifers to spare binding overhead.
if (Modifier.isPublic(modifiers) || !Modifier.isFinal(modifiers))
{
@SuppressWarnings("unchecked")
List<VariableDeclarationFragment> fragments = node.fragments();
for (VariableDeclarationFragment fragment : fragments)
{
String fieldName = fragment.getName().toString();
String qualifiedName = getQualifiedNameFromType(node.getType());
if (qualifiedName != null)
{
if (Modifier.isPublic(modifiers))
readableFields.put(fieldName,
NameUtil.resolveTypeParam(actualTypeParams, typeParams, qualifiedName));
if (!Modifier.isFinal(modifiers))
writableFields.put(fieldName,
NameUtil.resolveTypeParam(actualTypeParams, typeParams, qualifiedName));
}
}
}
return false;
}
示例7: isFinal
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private static boolean isFinal(FieldDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isFinal(modifiers));
}
示例8: isStatic
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private static boolean isStatic(FieldDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isStatic(modifiers));
}
示例9: performFieldRewrite
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private FieldDeclaration performFieldRewrite(IType type, ParameterObjectFactory pof, RefactoringStatus status) throws CoreException {
fBaseCURewrite= new CompilationUnitRewrite(type.getCompilationUnit());
SimpleName name= (SimpleName) NodeFinder.perform(fBaseCURewrite.getRoot(), type.getNameRange());
TypeDeclaration typeNode= (TypeDeclaration) ASTNodes.getParent(name, ASTNode.TYPE_DECLARATION);
ASTRewrite rewrite= fBaseCURewrite.getASTRewrite();
int modifier= Modifier.PRIVATE;
TextEditGroup removeFieldGroup= fBaseCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_remove_field);
FieldDeclaration lastField= null;
initializeDeclaration(typeNode);
for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) {
FieldInfo pi= iter.next();
if (isCreateField(pi)) {
VariableDeclarationFragment vdf= pi.declaration;
FieldDeclaration parent= (FieldDeclaration) vdf.getParent();
if (lastField == null)
lastField= parent;
else if (lastField.getStartPosition() < parent.getStartPosition())
lastField= parent;
ListRewrite listRewrite= rewrite.getListRewrite(parent, FieldDeclaration.FRAGMENTS_PROPERTY);
removeNode(vdf, removeFieldGroup, fBaseCURewrite);
if (listRewrite.getRewrittenList().size() == 0) {
removeNode(parent, removeFieldGroup, fBaseCURewrite);
}
if (fDescriptor.isCreateTopLevel()) {
IVariableBinding binding= vdf.resolveBinding();
ITypeRoot typeRoot= fBaseCURewrite.getCu();
if (binding == null || binding.getType() == null){
status.addFatalError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_fatal_error_cannot_resolve_binding, BasicElementLabels.getJavaElementName(pi.name)), JavaStatusContext.create(typeRoot, vdf));
} else {
ITypeBinding typeBinding= binding.getType();
if (Modifier.isPrivate(typeBinding.getModifiers())){
status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_private_class, BasicElementLabels.getJavaElementName(typeBinding.getName())), JavaStatusContext.create(typeRoot, vdf));
} else if (Modifier.isProtected(typeBinding.getModifiers())){
ITypeBinding declaringClass= typeBinding.getDeclaringClass();
if (declaringClass != null) {
IPackageBinding package1= declaringClass.getPackage();
if (package1 != null && !fDescriptor.getPackage().equals(package1.getName())){
status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_protected_class, new String[] {BasicElementLabels.getJavaElementName(typeBinding.getName()), BasicElementLabels.getJavaElementName(fDescriptor.getPackage())}), JavaStatusContext.create(typeRoot, vdf));
}
}
}
}
}
Expression initializer= vdf.getInitializer();
if (initializer != null)
pi.initializer= initializer;
int modifiers= parent.getModifiers();
if (!MemberVisibilityAdjustor.hasLowerVisibility(modifiers, modifier)){
modifier= modifiers;
}
}
}
FieldDeclaration fieldDeclaration= createParameterObjectField(pof, typeNode, modifier);
ListRewrite bodyDeclList= rewrite.getListRewrite(typeNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
if (lastField != null)
bodyDeclList.insertAfter(fieldDeclaration, lastField, null);
else
bodyDeclList.insertFirst(fieldDeclaration, null);
return fieldDeclaration;
}
示例10: performFieldRewrite
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入方法依赖的package包/类
private FieldDeclaration performFieldRewrite(IType type, ParameterObjectFactory pof, RefactoringStatus status) throws CoreException {
fBaseCURewrite= new CompilationUnitRewrite(type.getCompilationUnit());
SimpleName name= (SimpleName) NodeFinder.perform(fBaseCURewrite.getRoot(), type.getNameRange());
TypeDeclaration typeNode= (TypeDeclaration) ASTNodes.getParent(name, ASTNode.TYPE_DECLARATION);
ASTRewrite rewrite= fBaseCURewrite.getASTRewrite();
int modifier= Modifier.PRIVATE;
TextEditGroup removeFieldGroup= fBaseCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_remove_field);
FieldDeclaration lastField= null;
initializeDeclaration(typeNode);
for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) {
FieldInfo pi= iter.next();
if (isCreateField(pi)) {
VariableDeclarationFragment vdf= pi.declaration;
FieldDeclaration parent= (FieldDeclaration) vdf.getParent();
if (lastField == null)
lastField= parent;
else if (lastField.getStartPosition() < parent.getStartPosition())
lastField= parent;
ListRewrite listRewrite= rewrite.getListRewrite(parent, FieldDeclaration.FRAGMENTS_PROPERTY);
removeNode(vdf, removeFieldGroup, fBaseCURewrite);
if (listRewrite.getRewrittenList().size() == 0) {
removeNode(parent, removeFieldGroup, fBaseCURewrite);
}
if (fDescriptor.isCreateTopLevel()) {
IVariableBinding binding= vdf.resolveBinding();
ITypeRoot typeRoot= fBaseCURewrite.getCu();
if (binding == null || binding.getType() == null){
status.addFatalError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_fatal_error_cannot_resolve_binding, BasicElementLabels.getJavaElementName(pi.name)), JavaStatusContext.create(typeRoot, vdf));
} else {
ITypeBinding typeBinding= binding.getType();
if (Modifier.isPrivate(typeBinding.getDeclaredModifiers())){
status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_private_class, BasicElementLabels.getJavaElementName(typeBinding.getName())), JavaStatusContext.create(typeRoot, vdf));
} else if (Modifier.isProtected(typeBinding.getDeclaredModifiers())){
ITypeBinding declaringClass= typeBinding.getDeclaringClass();
if (declaringClass != null) {
IPackageBinding package1= declaringClass.getPackage();
if (package1 != null && !fDescriptor.getPackage().equals(package1.getName())){
status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_protected_class, new String[] {BasicElementLabels.getJavaElementName(typeBinding.getName()), BasicElementLabels.getJavaElementName(fDescriptor.getPackage())}), JavaStatusContext.create(typeRoot, vdf));
}
}
}
}
}
Expression initializer= vdf.getInitializer();
if (initializer != null)
pi.initializer= initializer;
int modifiers= parent.getModifiers();
if (!MemberVisibilityAdjustor.hasLowerVisibility(modifiers, modifier)){
modifier= modifiers;
}
}
}
FieldDeclaration fieldDeclaration= createParameterObjectField(pof, typeNode, modifier);
ListRewrite bodyDeclList= rewrite.getListRewrite(typeNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
if (lastField != null)
bodyDeclList.insertAfter(fieldDeclaration, lastField, null);
else
bodyDeclList.insertFirst(fieldDeclaration, null);
return fieldDeclaration;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:63,代码来源:ExtractClassRefactoring.java