List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration fragments
public List fragments()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(FieldDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from w ww. ja v a2 s.c om if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); } node.getType().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ for (Iterator<VariableDeclarationFragment> it = node.fragments().iterator(); it.hasNext();) { VariableDeclarationFragment f = it.next(); f.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(";");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(FieldDeclaration node) { List<boa.types.Ast.Variable> list = fields.peek(); for (Object o : node.fragments()) { VariableDeclarationFragment f = (VariableDeclarationFragment) o; Variable.Builder b = Variable.newBuilder(); // b.setPosition(pos.build()); // FIXME b.setName(f.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else//from w ww . j a v a 2 s . c o m ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = typeName(node.getType()); for (int i = 0; i < f.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setVariableType(tb.build()); if (f.getInitializer() != null) { f.getInitializer().accept(this); b.setInitializer(expressions.pop()); } list.add(b.build()); } return false; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(FieldDeclaration node) { List<VariableDeclarationFragment> fragments = node.fragments(); for (VariableDeclarationFragment fragment : fragments) { int beginLine = cu.getLineNumber(fragment.getStartPosition()); int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength()); int beginColumn = beginColunm(node); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); SimpleName name = fragment.getName(); if (name != null) { endLine = cu.getLineNumber(name.getStartPosition() + name.getLength()); endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength()); }/* w w w.j a v a2 s .co m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, fragment.getName().getIdentifier())); } return true; }
From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java
@Override public boolean visit(FieldDeclaration node) { Location location;//from ww w .j a va2 s . c om List<VariableDeclarationFragment> fragments = node.fragments(); for (VariableDeclarationFragment fragment : fragments) { int elementLineBegin = cu.getLineNumber(fragment.getStartPosition()); int elementLineEnd = cu.getLineNumber(fragment.getStartPosition() + node.getLength()); int elementColumnBegin = cu.getColumnNumber(fragment.getStartPosition()); int elementColumnEnd = cu.getColumnNumber(fragment.getStartPosition() + node.getLength()); location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd); MyAttributeDeclaration myAttribute = new MyAttributeDeclaration(fragment, location); if (!classLanguageConstructsList.isEmpty()) { classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getAttributes() .add(myAttribute); } } return true; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final FieldDeclaration pNode) { @SuppressWarnings("rawtypes") final List fragments = pNode.fragments(); IElement lField;//from w w w. ja va 2 s . com this.aCurrMethodReminder.push(this.aCurrMethod); if (Modifier.isStatic(pNode.getModifiers())) { this.aCurrMethod = (MethodElement) FlyweightElementFactory.getElement(Category.METHOD, this.aCurrType.getId() + "." + ASTCrawler.aCLINIT_METHOD_NAME); if (!this.aDB.contains(this.aCurrMethod)) // This <clinit>() method will be in any class that has a static // field with initialization // But the DECLARES relation will be linked only if this method // has at least one sub relations // The linkage is done at the end of traversing each // compilations unit while end visiting type Declaration this.aDB.addElement(this.aCurrMethod, pNode.getModifiers()); } else this.aCurrMethod = this.aTempMethod; // Consider multiple declaration in one statment for (@SuppressWarnings("rawtypes") final Iterator itr = fragments.iterator(); itr.hasNext();) { final VariableDeclarationFragment fragment = (VariableDeclarationFragment) itr.next(); final String lSimpleName = fragment.getName().getIdentifier(); final Expression lInit = fragment.getInitializer(); if (lSimpleName != null) { lField = FlyweightElementFactory.getElement(Category.FIELD, this.aCurrType.getId() + "." + lSimpleName); this.aDB.addElement(lField, pNode.getModifiers()); this.aDB.addRelation(this.aCurrType, Relation.DECLARES_FIELD, lField); // If there is any initialization to this field then we write // them as an access by <init> or <clinit> if (lInit != null) { this.aDB.addRelationAndTranspose(this.aCurrMethod, Relation.ACCESSES, lField); this.aDB.addRelationAndTranspose(this.aCurrMethod, Relation.SETS, lField); // Want to go into the right side of assignment operator lInit.accept(this); } } } // Because we have covered everything we need about field declaration, // we dont' have to go deeper into this node. // return false; return true; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final MarkerAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }/*from w w w . ja v a 2s . c o m*/ case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: { AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) annotatedNode; IMethodBinding methodBinding = atmd.resolveBinding(); return this.addAnnotationRelation(annoteElem, methodBinding); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final NormalAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }/* w ww . jav a 2 s. c om*/ case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final SingleMemberAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }/*from w w w. j a v a 2 s. co m*/ case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { VariableDeclarationStatement vds = (VariableDeclarationStatement) annotatedNode; return processVariableDeclarationStatement(annoteElem, vds); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:cc.kave.eclipse.commons.analysis.transformer.DeclarationVisitor.java
License:Apache License
@Override public boolean visit(FieldDeclaration node) { if (node != null) { List<VariableDeclarationFragment> fragments = node.fragments(); for (VariableDeclarationFragment fragment : fragments) { FieldName name = (FieldName) NodeFactory.createNodeName(fragment); // if (isNestedDeclaration(name, context)) { // return super.visit(node); // }//from w w w .j a v a2s . c o m cc.kave.commons.model.ssts.impl.declarations.FieldDeclaration fieldDeclaration = new cc.kave.commons.model.ssts.impl.declarations.FieldDeclaration(); fieldDeclaration.setName(name); context.getFields().add(fieldDeclaration); } } return super.visit(node); }
From source file:cc.kave.eclipse.namefactory.NodeFactory.java
License:Apache License
private static Name createVariableName(ASTNode node) { StringBuilder sb = new StringBuilder(); switch (node.getNodeType()) { case ASTNode.FIELD_DECLARATION: FieldDeclaration fieldNode = (FieldDeclaration) node; Object field = fieldNode.fragments().get(0); if (field instanceof VariableDeclarationFragment) { sb.append(modifierHelper(((VariableDeclarationFragment) field).resolveBinding())); sb.append("["); sb.append(BindingFactory// www .ja va 2s .co m .getBindingName(((VariableDeclarationFragment) field).resolveBinding().getType())); sb.append("] ["); sb.append(getDeclaringType(fieldNode)); sb.append("]."); sb.append(((VariableDeclarationFragment) field).getName().getIdentifier()); return CsFieldName.newFieldName(sb.toString()); } break; case ASTNode.VARIABLE_DECLARATION_STATEMENT: VariableDeclarationStatement variableStatementNode = (VariableDeclarationStatement) node; Object variableStatement = variableStatementNode.fragments().get(0); if (variableStatement instanceof VariableDeclarationFragment) { sb.append("["); sb.append(BindingFactory.getBindingName( ((VariableDeclarationFragment) variableStatement).resolveBinding().getType())); sb.append("] "); sb.append(((VariableDeclarationFragment) variableStatement).getName().getIdentifier()); return CsLocalVariableName.newLocalVariableName(sb.toString()); } break; case ASTNode.VARIABLE_DECLARATION_EXPRESSION: VariableDeclarationExpression variableExpressionNode = (VariableDeclarationExpression) node; Object variableExpression = variableExpressionNode.fragments().get(0); if (variableExpression instanceof VariableDeclarationFragment) { sb.append("["); sb.append(BindingFactory.getBindingName( ((VariableDeclarationFragment) variableExpression).resolveBinding().getType())); sb.append("] "); sb.append(((VariableDeclarationFragment) variableExpression).getName().getIdentifier()); return CsLocalVariableName.newLocalVariableName(sb.toString()); } break; } throw new RuntimeException("should not happen"); }