public boolean visit(FieldDeclaration node) { if (node.getParent().getNodeType() == ASTNode.TYPE_DECLARATION) { TypeDeclaration parentType = (TypeDeclaration) node.getParent(); int lastFieldIdx = parentType.getFields().length - 1; FieldDeclaration lastFieldInParent = parentType.getFields()[lastFieldIdx]; boolean isLastFieldDecl = lastFieldInParent.equals(node); // ... } return super.visit(node); }
private String[] getNamesOfFieldsInDeclaringType() { final AbstractTypeDeclaration type= getEnclosingType(); if (type instanceof TypeDeclaration) { FieldDeclaration[] fields= ((TypeDeclaration) type).getFields(); List<String> result= new ArrayList<>(fields.length); for (int i= 0; i < fields.length; i++) { for (Iterator<VariableDeclarationFragment> iter= fields[i].fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment field= iter.next(); result.add(field.getName().getIdentifier()); } } return result.toArray(new String[result.size()]); } return new String[] {}; }
private String[] getNamesOfFieldsInDeclaringType() { final AbstractTypeDeclaration type= getEnclosingType(); if (type instanceof TypeDeclaration) { FieldDeclaration[] fields= ((TypeDeclaration) type).getFields(); List<String> result= new ArrayList<>(fields.length); for (int i= 0; i < fields.length; i++) { for (Iterator<VariableDeclarationFragment> iter= fields[i].fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment field= iter.next(); result.add(field.getName().getIdentifier()); } } return result.toArray(new String[result.size()]); } return new String[] {}; }
private String[] getNamesOfFieldsInDeclaringType() { final AbstractTypeDeclaration type= getEnclosingType(); if (type instanceof TypeDeclaration) { FieldDeclaration[] fields= ((TypeDeclaration) type).getFields(); List result= new ArrayList(fields.length); for (int i= 0; i < fields.length; i++) { for (Iterator iter= fields[i].fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment field= (VariableDeclarationFragment) iter.next(); result.add(field.getName().getIdentifier()); } } return (String[]) result.toArray(new String[result.size()]); } return new String[] {}; }
public static FieldDeclaration findFieldByName(String name, TypeDeclaration type) { for (FieldDeclaration field : type.getFields()) { for (Object frag : field.fragments()) { if (((VariableDeclarationFragment) frag) .getName().getIdentifier().equals(name)) { return field; } } } return null; }
private void initializeDeclaration(TypeDeclaration node) { FieldDeclaration[] fields= node.getFields(); for (int i= 0; i < fields.length; i++) { FieldDeclaration fieldDeclaration= fields[i]; List<VariableDeclarationFragment> fragments= fieldDeclaration.fragments(); for (Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) { VariableDeclarationFragment vdf= iterator.next(); FieldInfo fieldInfo= getFieldInfo(vdf.getName().getIdentifier()); if (fieldInfo != null) { Assert.isNotNull(vdf); fieldInfo.declaration= vdf; fieldInfo.pi.setOldBinding(vdf.resolveBinding()); } } } }
private void initializeDeclaration(TypeDeclaration node) { FieldDeclaration[] fields= node.getFields(); for (int i= 0; i < fields.length; i++) { FieldDeclaration fieldDeclaration= fields[i]; List<VariableDeclarationFragment> fragments= fieldDeclaration.fragments(); for (Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) { VariableDeclarationFragment vdf= iterator.next(); FieldInfo fieldInfo= getFieldInfo(vdf.getName().getIdentifier()); if (fieldInfo != null) { Assert.isNotNull(vdf); fieldInfo.declaration= vdf; fieldInfo.pi.setOldBinding(vdf.resolveBinding()); } } } }
private ASTNode getPreviousSibling(ASTNode node) { boolean isPrevious = true; if (node != null && node.getParent() instanceof TypeDeclaration) { final TypeDeclaration typeDecl = (TypeDeclaration) node.getParent(); final TreeMap<Integer, ASTNode> nodes = new TreeMap<Integer, ASTNode>(); addAll(nodes, typeDecl.getFields()); addAll(nodes, typeDecl.getMethods()); addAll(nodes, typeDecl.getTypes()); if (isPrevious) { SortedMap<Integer, ASTNode> entries = nodes.headMap(node.getStartPosition()); if (!entries.isEmpty()) { return entries.get(entries.lastKey()); } } else { SortedMap<Integer, ASTNode> entries = nodes.tailMap(node.getStartPosition()); if (!entries.isEmpty()) { return entries.get(entries.firstKey()); } } } return null; }
@Override public FieldDeclaration bodyDeclaration(CompilationUnit astRoot) { String fieldName = this.getName(); for (FieldDeclaration fieldDeclaration : this.declaringTypeDeclaration(astRoot).getFields()) { // handle multiple fields declared in a single statement: // private int foo, bar; for (VariableDeclarationFragment fragment : this.fragments(fieldDeclaration)) { if (fragment.getName().getFullyQualifiedName().equals(fieldName)) { return fieldDeclaration; } } } return null; }
public static void addFields(final ASTNode node, final Set<String> features) { checkArgument(node.getRoot() instanceof CompilationUnit); final CompilationUnit cu = (CompilationUnit) node.getRoot(); for (final Object type : cu.types()) { if (type instanceof TypeDeclaration) { final TypeDeclaration td = (TypeDeclaration) type; for (final FieldDeclaration fd : td.getFields()) { for (final Object decl : fd.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) decl; final List<String> nameParts = getNameParts(vdf .getName().getIdentifier()); nameParts.forEach(np -> features.add("inScope:" + np)); } } } } }
/** * Builds a CFG for the provided node. * * @param node the node for which to build a CFG. * @return the list of basic blocks representing CFGs for each method in this type declaration */ public List<CFGBasicBlock> buildCFG(TypeDeclaration node) { if (!node.isInterface()) { List<CFGBasicBlock> results = new LinkedList<CFGBasicBlock>(); for (FieldDeclaration fieldDecl : node.getFields()) { buildCFG(fieldDecl); } for (MethodDeclaration methodDecl : node.getMethods()) { results.add(buildCFG(methodDecl)); } for (TypeDeclaration typeDeclaration : node.getTypes()) { buildCFG(typeDeclaration); } // for (BodyDeclaration bodyDeclaration : (List<BodyDeclaration>) // node.bodyDeclarations()) { // buildCFG(bodyDeclaration); // } return results; } return Collections.emptyList(); }
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration) */ public boolean visit(TypeDeclaration node) { if (containsPosition(node)) { // visit the field declarations FieldDeclaration[] fields = node.getFields(); for (int i = 0, length = fields.length; i < length && !fFound; i++) { fields[i].accept(this); } if (!fFound) { // visit inner types TypeDeclaration[] types = node.getTypes(); for (int i = 0, length = types.length; i < length && !fFound; i++) { types[i].accept(this); } } } return false; }
/** * @param td * @param currentTypeName * @param features */ private void addFieldVocabulary(final TypeDeclaration td, final String currentTypeName, final Set<String> features) { for (final FieldDeclaration fd : td.getFields()) { for (final Object vdf : fd.fragments()) { final VariableDeclarationFragment frag = (VariableDeclarationFragment) vdf; for (final String namePart : JavaFeatureExtractor .getNameParts(frag.getName().toString())) { features.add("fieldVoc:" + namePart); } } if (!currentTypeName.equals(fd.getType().toString())) { features.add("fieldType:" + fd.getType().toString()); for (final String namePart : JavaFeatureExtractor .getNameParts(fd.getType().toString())) { features.add("fieldVoc:" + namePart); } } } }
private static List<Type> findDeclTypeInClass(SimpleName sn, TypeDeclaration typeclass) { FieldDeclaration[] fields = typeclass.getFields(); String superQname = null; if (typeclass.getSuperclassType() != null) {
FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields(); if (fieldDecls.length > 0) { return fieldDecls[0].getModifiers();
FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields(); if (fieldDecls.length > 0) { return fieldDecls[0].getModifiers();
FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields(); if (fieldDecls.length > 0) { return fieldDecls[0].getModifiers();
FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields(); if (fieldDecls.length > 0) { return fieldDecls[0].getModifiers();
@SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.getName().toString()); visitListAsNode(EntityType.MODIFIERS, node.modifiers()); visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters()); if (node.getSuperclassType() != null) { node.getSuperclassType().accept(this); } visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes()); // @Inria // Change Distiller does not check the changes at Class Field declaration for (FieldDeclaration fd : node.getFields()) { fd.accept(this); } // @Inria // Visit Declaration and Body (inside MD visiting) for (MethodDeclaration md : node.getMethods()) { md.accept(this); } return false; }
@SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.getName().toString()); visitListAsNode(EntityType.MODIFIERS, node.modifiers()); visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters()); if (node.getSuperclassType() != null) { node.getSuperclassType().accept(this); } visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes()); // @Inria // Change Distiller does not check the changes at Class Field declaration for (FieldDeclaration fd : node.getFields()) { fd.accept(this); } // @Inria // Visit Declaration and Body (inside MD visiting) for (MethodDeclaration md : node.getMethods()) { md.accept(this); } return false; }