本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.FieldDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration类的具体用法?Java FieldDeclaration怎么用?Java FieldDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclaration类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了FieldDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAnnotations
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
/**
* Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
*
* Only the simple name is checked - the package and any containing class are ignored.
*/
public static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) {
List<Annotation> result = new ArrayList<Annotation>();
if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
for (Annotation annotation : field.annotations) {
TypeReference typeRef = annotation.type;
if (typeRef != null && typeRef.getTypeName() != null) {
char[][] typeName = typeRef.getTypeName();
String suspect = new String(typeName[typeName.length - 1]);
if (namePattern.matcher(suspect).matches()) {
result.add(annotation);
}
}
}
return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
}
示例2: buildTree
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
switch (kind) {
case COMPILATION_UNIT:
return buildCompilationUnit((CompilationUnitDeclaration) node);
case TYPE:
return buildType((TypeDeclaration) node);
case FIELD:
return buildField((FieldDeclaration) node);
case INITIALIZER:
return buildInitializer((Initializer) node);
case METHOD:
return buildMethod((AbstractMethodDeclaration) node);
case ARGUMENT:
return buildLocal((Argument) node, kind);
case LOCAL:
return buildLocal((LocalDeclaration) node, kind);
case STATEMENT:
return buildStatement((Statement) node);
case ANNOTATION:
return buildAnnotation((Annotation) node, false);
default:
throw new AssertionError("Did not expect to arrive here: " + kind);
}
}
示例3: setFieldDefaultsForField
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public void setFieldDefaultsForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level, boolean makeFinal) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
if (level != null && level != AccessLevel.NONE) {
if ((field.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected)) == 0) {
if (!hasAnnotation(PackagePrivate.class, fieldNode)) {
field.modifiers |= EclipseHandlerUtil.toEclipseModifier(level);
}
}
}
if (makeFinal && (field.modifiers & ClassFileConstants.AccFinal) == 0) {
if (!hasAnnotation(NonFinal.class, fieldNode)) {
if ((field.modifiers & ClassFileConstants.AccStatic) == 0 || field.initialization != null) {
field.modifiers |= ClassFileConstants.AccFinal;
}
}
}
fieldNode.rebuild();
}
示例4: fieldExists
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
/**
* Checks if there is a field with the provided name.
*
* @param fieldName the field name to check for.
* @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
*/
public static MemberExistsResult fieldExists(String fieldName, EclipseNode node) {
while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
if (node != null && node.get() instanceof TypeDeclaration) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
if (typeDecl.fields != null) for (FieldDeclaration def : typeDecl.fields) {
char[] fName = def.name;
if (fName == null) continue;
if (fieldName.equals(new String(fName))) {
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
}
return MemberExistsResult.NOT_EXISTS;
}
示例5: createListOfNonExistentFields
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
/**
* Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.
*/
public static List<Integer> createListOfNonExistentFields(List<String> list, EclipseNode type, boolean excludeStandard, boolean excludeTransient) {
boolean[] matched = new boolean[list.size()];
for (EclipseNode child : type.down()) {
if (list.isEmpty()) break;
if (child.getKind() != Kind.FIELD) continue;
if (excludeStandard) {
if ((((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
if (child.getName().startsWith("$")) continue;
}
if (excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0) continue;
int idx = list.indexOf(child.getName());
if (idx > -1) matched[idx] = true;
}
List<Integer> problematic = new ArrayList<Integer>();
for (int i = 0 ; i < list.size() ; i++) {
if (!matched[i]) problematic.add(i);
}
return problematic;
}
示例6: makeSimpleSetterMethodForBuilder
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
TypeDeclaration td = (TypeDeclaration) builderType.get();
AbstractMethodDeclaration[] existing = td.methods;
if (existing == null) existing = EMPTY;
int len = existing.length;
FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
char[] name = fd.name;
for (int i = 0; i < len; i++) {
if (!(existing[i] instanceof MethodDeclaration)) continue;
char[] existingName = existing[i].selector;
if (Arrays.equals(name, existingName)) return;
}
String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
injectMethod(builderType, setter);
}
示例7: generateFields
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
@Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) {
if (useGuavaInstead(builderType)) {
return guavaListSetSingularizer.generateFields(data, builderType);
}
TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs());
FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1);
buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
buildField.modifiers = ClassFileConstants.AccPrivate;
buildField.declarationSourceEnd = -1;
buildField.type = type;
data.setGeneratedByRecursive(buildField);
return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField));
}
示例8: setFieldDefaultsForField
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public void setFieldDefaultsForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level, boolean makeFinal) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
if (level != null && level != AccessLevel.NONE) {
if ((field.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected)) == 0) {
if (!hasAnnotation(PackagePrivate.class, fieldNode)) {
field.modifiers |= EclipseHandlerUtil.toEclipseModifier(level);
}
}
}
if (makeFinal && (field.modifiers & ClassFileConstants.AccFinal) == 0) {
if (!hasAnnotation(NonFinal.class, fieldNode)) {
field.modifiers |= ClassFileConstants.AccFinal;
}
}
fieldNode.rebuild();
}
示例9: makeSimpleSetterMethodForBuilder
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
TypeDeclaration td = (TypeDeclaration) builderType.get();
AbstractMethodDeclaration[] existing = td.methods;
if (existing == null) existing = EMPTY;
int len = existing.length;
FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
char[] name = fd.name;
for (int i = 0; i < len; i++) {
if (!(existing[i] instanceof MethodDeclaration)) continue;
char[] existingName = existing[i].selector;
if (Arrays.equals(name, existingName)) return;
}
String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
injectMethod(builderType, setter);
}
示例10: convert
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
private QualifiedAllocationExpression convert(
IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult)
throws JavaModelException {
TypeDeclaration anonymousLocalTypeDeclaration =
convert((SourceType) localType, compilationResult);
QualifiedAllocationExpression expression =
new QualifiedAllocationExpression(anonymousLocalTypeDeclaration);
expression.type = anonymousLocalTypeDeclaration.superclass;
anonymousLocalTypeDeclaration.superclass = null;
anonymousLocalTypeDeclaration.superInterfaces = null;
anonymousLocalTypeDeclaration.allocation = expression;
if (enumConstant != null) {
anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum;
expression.enumConstant = enumConstant;
expression.type = null;
}
return expression;
}
示例11: getEnclosingDeclaration
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
private ASTNode getEnclosingDeclaration() {
int i = this.parentsPtr;
while (i > -1) {
ASTNode parent = this.parents[i];
if (parent instanceof AbstractMethodDeclaration) {
return parent;
} else if (parent instanceof Initializer) {
return parent;
} else if (parent instanceof FieldDeclaration) {
return parent;
} else if (parent instanceof TypeDeclaration) {
return parent;
}
i--;
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:UnresolvedReferenceNameFinder.java
示例12: add
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public RecoveredElement add(FieldDeclaration newFieldDeclaration, int bracketBalanceValue) {
resetPendingModifiers();
/* local variables inside initializer can only be final and non void */
char[][] fieldTypeName;
if ((newFieldDeclaration.modifiers & ~ClassFileConstants.AccFinal) != 0 /* local var can only be final */
|| (newFieldDeclaration.type == null) // initializer
|| ((fieldTypeName = newFieldDeclaration.type.getTypeName()).length == 1 // non void
&& CharOperation.equals(fieldTypeName[0], TypeBinding.VOID.sourceName()))){
if (this.parent == null) return this; // ignore
this.updateSourceEndIfNecessary(previousAvailableLineEnd(newFieldDeclaration.declarationSourceStart - 1));
return this.parent.add(newFieldDeclaration, bracketBalanceValue);
}
/* default behavior is to delegate recording to parent if any,
do not consider elements passed the known end (if set)
it must be belonging to an enclosing element
*/
if (this.fieldDeclaration.declarationSourceEnd > 0
&& newFieldDeclaration.declarationSourceStart > this.fieldDeclaration.declarationSourceEnd){
if (this.parent == null) return this; // ignore
return this.parent.add(newFieldDeclaration, bracketBalanceValue);
}
// still inside initializer, treat as local variable
return this; // ignore
}
示例13: add
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public RecoveredElement add(FieldDeclaration addedfieldDeclaration, int bracketBalanceValue) {
/* default behavior is to delegate recording to parent if any */
resetPendingModifiers();
if (this.parent == null) return this; // ignore
if (this.fieldDeclaration.declarationSourceStart == addedfieldDeclaration.declarationSourceStart) {
if (this.fieldDeclaration.initialization != null) {
this.updateSourceEndIfNecessary(this.fieldDeclaration.initialization.sourceEnd);
} else {
this.updateSourceEndIfNecessary(this.fieldDeclaration.sourceEnd);
}
} else {
this.updateSourceEndIfNecessary(previousAvailableLineEnd(addedfieldDeclaration.declarationSourceStart - 1));
}
return this.parent.add(addedfieldDeclaration, bracketBalanceValue);
}
示例14: add
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {
resetPendingModifiers();
/* local variables inside method can only be final and non void */
char[][] fieldTypeName;
if ((fieldDeclaration.modifiers & ~ClassFileConstants.AccFinal) != 0 // local var can only be final
|| (fieldDeclaration.type == null) // initializer
|| ((fieldTypeName = fieldDeclaration.type.getTypeName()).length == 1 // non void
&& CharOperation.equals(fieldTypeName[0], TypeBinding.VOID.sourceName()))){
this.updateSourceEndIfNecessary(previousAvailableLineEnd(fieldDeclaration.declarationSourceStart - 1));
return this.parent.add(fieldDeclaration, bracketBalanceValue);
}
/* do not consider a local variable starting passed the block end (if set)
it must be belonging to an enclosing block */
if (this.blockDeclaration.sourceEnd != 0
&& fieldDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){
return this.parent.add(fieldDeclaration, bracketBalanceValue);
}
// ignore the added field, since indicates a local variable behind recovery point
// which thus got parsed as a field reference. This can happen if restarting after
// having reduced an assistNode to get the following context (see 1GEK7SG)
return this;
}
示例15: duplicateModifierForField
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; //导入依赖的package包/类
public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
/* to highlight modifiers use:
this.handle(
new Problem(
DuplicateModifierForField,
new String[] {new String(fieldDecl.name)},
fieldDecl.modifiers.sourceStart,
fieldDecl.modifiers.sourceEnd));
*/
String[] arguments = new String[] {new String(fieldDecl.name)};
this.handle(
IProblem.DuplicateModifierForField,
arguments,
arguments,
fieldDecl.sourceStart,
fieldDecl.sourceEnd);
}