Example usage for org.eclipse.jdt.core.dom FieldDeclaration toString

List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration toString

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom FieldDeclaration toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this node suitable for debugging purposes only.

Usage

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w ww.j  a  v  a2  s  .c  om*/
public boolean visit(FieldDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }

    // @Inria
    pushNode(node, node.toString());
    //
    visitListAsNode(EntityType.MODIFIERS, node.modifiers());
    node.getType().accept(this);
    visitListAsNode(EntityType.FRAGMENTS, node.fragments());

    return false;
}

From source file:fr.labri.harmony.rta.junit.jdt.JDTVisitorRTA.java

License:Open Source License

public boolean visit(FieldDeclaration fd) {

    VariableDeclarationFragment f = (VariableDeclarationFragment) fd.fragments().get(0);
    IVariableBinding b = f.resolveBinding();
    if (b != null && fd != null && currentClass != null) {
        if (b.getDeclaringClass().isAnonymous())
            return false;
        String id = getVariableBindingId(b);
        hashes.put(id, MD5Generator.md5(fd.toString()));
        //Put the field in the database
        currentJavaMethod = getJavaMethod(id);
        currentJavaMethod//from   w  w w  .  ja v  a  2 s  .  co m
                .setClassName(getJavaClass(b.getDeclaringClass().getTypeDeclaration().getQualifiedName()));
        //Si la variable de classe est instancie
        if (f.getInitializer() instanceof ClassInstanceCreation) {
            ClassInstanceCreation cc = (ClassInstanceCreation) f.getInitializer();
            IMethodBinding mb = cc.resolveConstructorBinding();
            if (mb != null) {
                String isIntern = "false";
                if (Modifier.isPrivate(b.getModifiers()))
                    isIntern = "true";
                fieldClassCreated.add(mb.getDeclaringClass().getQualifiedName() + "::" + isIntern);
            }
        }

    }

    return true;
}

From source file:org.cruxframework.cruxdevtools.loginstrumentation.LogInstrumentation.java

License:Apache License

private static void parse(String str) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(str.toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final CompilationUnit cu = (CompilationUnit) parser.createAST(null);

    cu.accept(new ASTVisitor() {

        private boolean logInserted = false;
        private String fileName;

        @Override//w w w  .j  a va 2  s . c  o m
        public boolean visit(FieldDeclaration node) {
            if (!logInserted) {
                logInserted = true;
                int lineNumber = cu.getLineNumber(node.getStartPosition());
                int charNumber = node.getStartPosition();
                mapVariableLocation.put(fileName, new VariableLocation(lineNumber - 1, charNumber,
                        node.toString(), fileName.substring(0, fileName.length() - ".java".length())));
            }

            return super.visit(node);
        }

        @Override
        public boolean visit(TypeDeclaration node) {
            fileName = node.getName().getFullyQualifiedName() + ".java";
            return super.visit(node);
        }

        @Override
        public boolean visit(MethodDeclaration node) {
            List<MethodLocation> methodLocations = mapMethodLocation.get(fileName);
            if (methodLocations == null) {
                methodLocations = new ArrayList<LogInstrumentation.MethodLocation>();
            }

            if (node != null && node.getBody() != null) {
                int indexOfSuper = node.getBody().toString().indexOf("super(");
                if (indexOfSuper < 0 || indexOfSuper > 5) {
                    int lineNumber = cu.getLineNumber(node.getBody().getStartPosition());
                    int charNumber = node.getStartPosition();
                    methodLocations.add(
                            new MethodLocation(lineNumber, charNumber, node.getName().getFullyQualifiedName()));
                    mapMethodLocation.put(fileName, methodLocations);
                }

            }

            return super.visit(node);
        }
    });
}

From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.FullTextIndexer.java

License:Open Source License

@Override
public void indexField(final Document document, final FieldDeclaration field) {
    CodeIndexer.addFieldToDocument(document, Fields.FULL_TEXT, field.toString().trim());
}

From source file:org.eclipse.swordfish.tooling.test.util.project.SFASTMatcher.java

License:Open Source License

/**
 * Returns whether the given node and the other object match.
 * <p>/*from  w  w w  . j a v a 2s .  c  om*/
 * The default implementation provided by this class tests whether the
 * other object is a node of the same type with structurally isomorphic
 * child subtrees. Subclasses may override this method as needed.
 * </p>
 *
 * @param node the node
 * @param other the other object, or <code>null</code>
 * @return <code>true</code> if the subtree matches, or
 *   <code>false</code> if they do not match or the other object has a
 *   different node type or is <code>null</code>
 */
public boolean match(FieldDeclaration node, Object other) {
    if (!(other instanceof FieldDeclaration)) {
        return false;
    }
    FieldDeclaration o = (FieldDeclaration) other;
    if (node.toString().indexOf(EXCLUDE_SERIAL) >= 0 && o.toString().indexOf(EXCLUDE_SERIAL) >= 0)
        return true;
    return super.match(node, other);
}

From source file:org.evosuite.junit.TestExtractingVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override/*w  ww.  ja  va  2 s .c  o m*/
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;
}

From source file:sourcecodefilter.ExitCode.java

License:Open Source License

@SuppressWarnings("unchecked")
private static void removeNonSerializedFieldsAndUnusedMethodsIn(ConverterRelevantCatroidSource source) {
    final List<AbstractTypeDeclaration> types = source.getSourceAst().types();
    assert types.size() > 0;
    // TODO: add abstraction for field and method iteration
    for (AbstractTypeDeclaration abstractTypeDecl : types) {
        Set<FieldDeclaration> nonTransientFields = new HashSet<FieldDeclaration>();
        // using AbstractTypeDeclaration to cover regular Types and Enums
        for (BodyDeclaration bodyDecl : new ArrayList<BodyDeclaration>(abstractTypeDecl.bodyDeclarations())) {
            if (bodyDecl.getNodeType() == ASTNode.FIELD_DECLARATION) {
                FieldDeclaration fieldDecl = (FieldDeclaration) bodyDecl;
                assert fieldDecl.fragments().size() == 1 : String
                        .format("Unsupported multi field declaration: '%s'", fieldDecl.toString());
                String fieldName = ((VariableDeclarationFragment) fieldDecl.fragments().get(0)).getName()
                        .getIdentifier();
                if (source.isRemovedField(fieldName)) {
                    fieldDecl.delete();//w  w  w.  j  a va 2s.  co m
                } else if (Modifier.isTransient(fieldDecl.getModifiers())
                        && !(source.isPreservedField(fieldName))) {
                    fieldDecl.delete();
                } else {
                    nonTransientFields.add(fieldDecl);
                }
            }
        }

        for (BodyDeclaration bodyDecl : new ArrayList<BodyDeclaration>(abstractTypeDecl.bodyDeclarations())) {
            if (bodyDecl.getNodeType() == ASTNode.METHOD_DECLARATION) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDecl;
                if (!methodDeclaration.isConstructor()) {
                    //                            removeOverrideAnnotation(methodDeclaration);
                    final String methodName = methodDeclaration.getName().getIdentifier();
                    if (methodName.equals("init")) {
                        Block body = methodDeclaration.getBody();
                        for (Iterator<Statement> iterator2 = body.statements().iterator(); iterator2
                                .hasNext();) {
                            iterator2.next();
                            iterator2.remove();
                        }
                    } else if (source.isRemovedMethod(methodName)) {
                        methodDeclaration.delete();
                    } else if (!(source.isPreservedMethod(methodName))) {
                        if (!(isRelatedToNonTransientFields(methodName, nonTransientFields))
                                || isOverriding(methodDeclaration)) {
                            methodDeclaration.delete();
                        }
                    }
                }
            }
        }
    }
}