本文整理汇总了Java中org.eclipse.jdt.core.dom.FieldDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration类的具体用法?Java FieldDeclaration怎么用?Java FieldDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclaration类属于org.eclipse.jdt.core.dom包,在下文中一共展示了FieldDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getField
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
/**
* @param methodname
* @return
*/
public FieldDeclaration getField( ) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
String s = getStaticVariable ( );
if (s==null) return null;
parser.setSource(s.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.accept(new ASTVisitor() {
public boolean visit(FieldDeclaration node) {
field = node;
return true;
}
});
return field;
}
示例2: 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;
}
示例3: rewriteAST
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
final ASTRewrite rewrite = cuRewrite.getASTRewrite();
VariableDeclarationFragment fragment = null;
for (int i = 0; i < fNodes.length; i++) {
final ASTNode node = fNodes[i];
final AST ast = node.getAST();
fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(NAME_FIELD));
final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));
if (!addInitializer(fragment, node)) {
continue;
}
if (fragment.getInitializer() != null) {
final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
if (node instanceof AbstractTypeDeclaration) {
rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
} else if (node instanceof AnonymousClassDeclaration) {
rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
} else if (node instanceof ParameterizedType) {
final ParameterizedType type = (ParameterizedType) node;
final ASTNode parent = type.getParent();
if (parent instanceof ClassInstanceCreation) {
final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
if (anonymous != null) {
rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
}
}
} else {
Assert.isTrue(false);
}
addLinkedPositions(rewrite, fragment, positionGroups);
}
final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
declaration.setJavadoc(doc);
}
}
if (fragment == null) {
return;
}
positionGroups.setEndPosition(rewrite.track(fragment));
}
示例4: 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);
}
示例5: hasFieldInitializers
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
private static boolean hasFieldInitializers(TypeDeclaration typeDecl) {
boolean returnFlag = false;
for (FieldDeclaration fd : typeDecl.getFields()) {
// Skip over primitive types
if (fd.getType().isPrimitiveType() ) {
continue;
}
if (fd.fragments().size() > 0)
if (fd.fragments().get(0) instanceof VariableDeclarationFragment) {
VariableDeclarationFragment vdf = (VariableDeclarationFragment) fd.fragments().get(0);
if (vdf.getInitializer() != null)
returnFlag = true;
}
}
return returnFlag;
}
示例6: createNewFieldDeclaration
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
AST ast = getAST();
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
SimpleName variableName = ast.newSimpleName(fFieldName);
fragment.setName(variableName);
addLinkedName(rewrite, variableName, false);
List<Dimension> extraDimensions =
DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
fragment.extraDimensions().addAll(extraDimensions);
if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
fragment.setInitializer(initializer);
}
FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);
VariableDeclarationStatement vds = getTempDeclarationStatement();
Type type = (Type) rewrite.createCopyTarget(vds.getType());
fieldDeclaration.setType(type);
fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
return fieldDeclaration;
}
示例7: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
@Override
public boolean visit(VariableDeclarationFragment node) {
boolean result = super.visit(node);
if (isFirstSelectedNode(node)) {
if (node.getParent() instanceof FieldDeclaration) {
invalidSelection(
RefactoringCoreMessages
.ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment_from_field,
JavaStatusContext.create(fCUnit, node));
} else {
invalidSelection(
RefactoringCoreMessages
.ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment,
JavaStatusContext.create(fCUnit, node));
}
return false;
}
return result;
}
示例8: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
if (Modifier.isStatic(fieldDeclaration.getModifiers())) {
testCase.setCurrentScope(TestScope.STATICFIELDS);
}
VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
Expression expression = varDeclFrgmnt.getInitializer();
VariableReference varRef;
if (expression == null) {
varRef = retrieveDefaultValueAssignment(retrieveTypeClass(varDeclFrgmnt));
} else {
varRef = retrieveVariableReference(expression, null);
}
varRef.setOriginalCode(fieldDeclaration.toString());
// TODO Use the name here as well?
// String name = varDeclFrgmt.getName().getIdentifier();
// new BoundVariableReferenceImpl(testCase, varType, name);
testCase.addVariable(varDeclFrgmnt.resolveBinding(), varRef);
testCase.setCurrentScope(TestScope.FIELDS);
return true;
}
示例9: visitFragment
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
private void visitFragment(VariableDeclarationFragment fragment, FieldDeclaration field) {
Attribute attribute = importer.ensureAttributeForFragment(fragment, field);
importer.createSourceAnchor(attribute, fragment, (CompilationUnit) field.getRoot());
importer.ensureCommentFromBodyDeclaration(attribute, field);
/* only the last fragment of a field contains the initializer code.
* thus, to create the access to each variable in the fragment we need to ask that last fragment
* we do not have to check the existence of that last fragment, because we already know that the field has at least one fragment */
VariableDeclarationFragment lastFragment = (VariableDeclarationFragment) field.fragments().get(field.fragments().size() - 1);
if (lastFragment.getInitializer() != null) {
Access access = importer.createAccessFromExpression(fragment.getName());
access.setIsWrite(true);
importer.createAccessFromExpression((Expression) lastFragment.getInitializer());
}
attribute.setIsStub(false);
}
示例10: ClassModel
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
List<TypeModel> innerTypes, List<ASTNode> modifiers) {
groovism = provide();
this.className = className;
this.packageDeclaration = packageDeclaration;
this.fields = fieldDeclarations(fields);
this.methods = unmodifiableList(new LinkedList<>(methods));
this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
this.imports = imports;
this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
if (isTestClass(methods)) {
this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
imports.add(0, astNodeFactory.importDeclaration(Specification.class));
} else {
this.superClassType = Optional.ofNullable(superClassType);
}
}
示例11: InterfaceModel
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
List<ASTNode> modifiers) {
groovism = provide();
LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);
this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);
this.typeName = typeName;
this.packageDeclaration = packageDeclaration;
this.fields = unmodifiableList(new LinkedList<>(fields));
this.methods = unmodifiableList(new LinkedList<>(methods));
this.imports = unmodifiableList(importDeclarations);
this.modifiers = unmodifiableList(modifiers);
}
示例12: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
@Override
public boolean visit(FieldDeclaration node) {
List fragments = node.fragments();
for(Object o : fragments) {
VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
String varName = frag.getName().getIdentifier();
int line = cunit.getLineNumber(frag.getStartPosition());
ASTNode parent = node.getParent();
Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
TypeDeclaration dec = (TypeDeclaration) node.getParent();
String qName = dec.getName().getFullyQualifiedName();
PackageDeclaration packageDec = cunit.getPackage();
if(packageDec != null)
qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
String type = !Modifier.isStatic(node.getModifiers()) ? qName : null;
VariableTags tags = new VariableTags(varName, type, line, scope, true);
variables.add(tags);
}
return false;
}
示例13: visit
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
@Override
public boolean visit(TypeDeclaration node) {
System.out.println(node.getParent().getClass());
if(info == null)
info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node));
for(FieldDeclaration f : node.getFields()) {
if(!Modifier.isStatic(f.getModifiers())) {
for(Object o : f.fragments()) {
VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
info.addField(new FieldInfo(frag.getName().toString()));
}
}
}
return true;
}
示例14: getVisibilityModifier
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static String getVisibilityModifier(FieldDeclaration pInstanceVariableNode) {
Iterator<Object> it = pInstanceVariableNode.modifiers().iterator();
// Find the visibility in the modifiers
while (it.hasNext()) {
String modifier = it.next().toString();
switch (modifier) {
case "private":
return "private";
case "protected":
return "protected";
case "public":
return "public";
default:
break;
}
}
// No visibility found
return null;
}
示例15: createFieldInfos
import org.eclipse.jdt.core.dom.FieldDeclaration; //导入依赖的package包/类
private List<FieldInfo> createFieldInfos(FieldDeclaration node, String belongTo) {
List<FieldInfo> fieldInfos = new ArrayList<>();
Type type = node.getType();
Set<String> types = getTypes(type);
String typeString = type.toString();
String visibility = getVisibility(node);
boolean isStatic = isStatic(node);
boolean isFinal = isFinal(node);
String comment = "";
if (node.getJavadoc() != null)
comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
List<VariableDeclarationFragment> fragments = node.fragments();
for (VariableDeclarationFragment fragment : fragments) {
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.belongTo = belongTo;
fieldInfo.name = fragment.getName().getFullyQualifiedName();
fieldInfo.typeString = typeString;
fieldInfo.types = types;
fieldInfo.visibility = visibility;
fieldInfo.isFinal = isFinal;
fieldInfo.isStatic = isStatic;
fieldInfo.comment = comment;
fieldInfos.add(fieldInfo);
}
return fieldInfos;
}