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

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

Introduction

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

Prototype

@Override
public String toString();

Source Link

Document

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

Usage

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

/**
 * @return <code>true</code> if "subConstructor" is constructor of inner class which call
 *         "superConstructor".//w w  w.j av  a  2 s.  c o m
 */
private static boolean isSuperConstructor(IMethodBinding superConstructor, IMethodBinding subConstructor) {
    String superString = superConstructor.toString();
    String subString = subConstructor.toString();
    return superString.endsWith(subString);
}

From source file:com.motorola.studio.android.generatecode.AbstractCodeGenerator.java

License:Apache License

/**
 * Checks if a method is already declared
 * @param methodToCheck method to verify if already existent in the code
 * @param bindingString/*from  ww w  . j a  v  a  2s. c o  m*/
 * @return null if there method not declared yet, or the the method found (if already declared)
 */
protected MethodDeclaration isMethodAlreadyDeclared(MethodDeclaration methodToCheck, String bindingString) {
    MethodDeclaration result = null;
    if (typeDeclaration.bodyDeclarations() != null) {
        //check if method already declared                  
        for (Object bd : typeDeclaration.bodyDeclarations()) {
            if (bd instanceof MethodDeclaration) {
                MethodDeclaration md = (MethodDeclaration) bd;
                IMethodBinding binding = md.resolveBinding();
                if ((binding != null) && (bindingString != null)
                        && binding.toString().trim().equals(bindingString.trim())) {
                    result = md;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:com.motorola.studio.android.generatemenucode.model.codegenerators.CodeGeneratorBasedOnMenuVisitor.java

License:Apache License

/**
 * Visit method declaration, searching for instructions 
 * onCreate for activity or fragment/*w w  w  .  jav a 2  s  .  c  o  m*/
 */
@Override
public boolean visit(MethodDeclaration node) {
    //Fill Method information
    SimpleName name = node.getName();
    if (name.getIdentifier().equals(ACTIVITY_ON_CREATE_MENU)
            || name.getIdentifier().equals(FRAGMENT_ON_CREATE_MENU)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            if (binding.toString().trim().contains(ACTIVITY_ON_CREATE_MENU_DECLARATION)
                    || binding.toString().trim().contains(FRAGMENT_ON_CREATE_MENU_DECLARATION)) {
                visitMethodBodyToIdentifyMenu(node);
            }
        }
    }

    return super.visit(node);
}

From source file:com.motorola.studio.android.generateviewbylayout.GenerateCodeBasedOnLayoutVisitor.java

License:Apache License

/**
 * Visit method declaration, searching for instructions 
 * onCreate for activity or fragment/*from w w  w  .  j a va2 s  .  co m*/
 */
@Override
public boolean visit(MethodDeclaration node) {
    //Fill Method information
    SimpleName name = node.getName();
    if (name.getIdentifier().equals(ACTIVITY_ON_CREATE) || name.getIdentifier().equals(FRAGMENT_ON_CREATE)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            if (binding.toString().trim().contains(ACTIVITY_ON_CREATE_DECLARATION)) {
                visitMethodBodyToIdentifyLayout(node);
            } else if (binding.toString().trim().contains(FRAGMENT_ON_CREATE_DECLARATION)) {
                if (node.getBody().statements().size() <= 1) {
                    throw new IllegalArgumentException(
                            CodeUtilsNLS.MethodVisitor_InvalidFormatForFragmentOnCreateView);
                } else {
                    visitMethodBodyToIdentifyLayout(node);
                }
            } else {
                //for each method visit to identify views already declared
                visitToIdentifyViewsAlreadyDeclared(node);
            }
        }
    } else if (name.getIdentifier().equals(ACTIVITY_ON_PAUSE)
            || name.getIdentifier().equals(ACTIVITY_ON_RESUME)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            //find declared save state
            if (binding.toString().trim().contains(ACTIVITY_ON_PAUSE_DECLARATION)) {
                findSavedViews(node);
            }
            //find declared restore state
            else if (binding.toString().trim().contains(ACTIVITY_ON_RESUME_DECLARATION)) {
                findRestoredViews(node);
            }

        }
    } else {
        //for each method visit to identify views already declared
        visitToIdentifyViewsAlreadyDeclared(node);
    }
    return super.visit(node);
}

From source file:com.motorolamobility.preflighting.samplechecker.findviewbyid.implementation.FindViewByIdVisitor.java

License:Apache License

/**
 * Visit method invocations to find invocation of <code>findViewById</code>.
 * //from w w w .  j  a va 2 s.com
 * @param invoked method that is being called and will be analyzed to check if it is a <code>findViewById</code> call. 
 */
@Override
public boolean visit(MethodInvocation invoked) {
    //find the signature of the method that is being called
    IMethodBinding methodBinding = invoked.resolveMethodBinding();
    if (methodBinding != null) {
        if (methodBinding.toString().trim().equalsIgnoreCase(FIND_VIEW_BY_ID_METHOD_BINDING)) {
            //according to the signature, findViewById was called
            ASTNode parentNode = invoked.getParent();
            Object firstElement = invoked.arguments().get(0);
            if (firstElement != null && firstElement.toString() != null
                    && firstElement.toString().startsWith(R_CONSTANT)) {
                //argument has a constant R. (indicating access that could be possibly done outside the loop)
                if (hasLoopStatementAsParent(parentNode)) {
                    //print in the console (if DEBUG level set for verbosity of App Validator output)
                    PreflightingLogger.debug("Found findViewById invocation inside loop statement");

                    //call is inside a loop statement - raise issue                            
                    ValidationResultData validationResult = createResult(invoked);
                    results.addValidationResult(validationResult);
                }
            }
        }
    }
    return super.visit(invoked);
}

From source file:org.autorefactor.refactoring.rules.TestNGAssertRefactoring.java

License:Open Source License

private boolean canUseAssertNotEquals(ImportDeclaration node) {
    final ITypeBinding typeBinding = resolveTypeBinding(node);
    if (hasType(typeBinding, "org.testng.Assert")) {
        for (IMethodBinding mb : typeBinding.getDeclaredMethods()) {
            if (mb.toString().contains("assertNotEquals")) {
                return true;
            }/*from  w w w . j  a  va2  s  . c  o  m*/
        }
    }
    return false;
}

From source file:org.eclim.plugin.jdt.command.impl.ImplCommand.java

License:Open Source License

private String getMethodBindingSignature(IMethodBinding binding) {
    return binding.toString().trim().replaceAll("\\bjava\\.lang\\.", "").replaceAll("\\s+throws\\s+.*", "")
            .replaceAll("#RAW", "").replaceFirst("\\w+\\s*\\(.*?\\)", getMethodBindingCallSignature(binding));
}

From source file:org.eclipse.andmore.android.generatecode.AbstractCodeGenerator.java

License:Apache License

/**
 * Checks if a method is already declared
 * //  w ww .  j a  va2  s .c om
 * @param methodToCheck
 *            method to verify if already existent in the code
 * @param bindingString
 * @return null if there method not declared yet, or the the method found
 *         (if already declared)
 */
protected MethodDeclaration isMethodAlreadyDeclared(MethodDeclaration methodToCheck, String bindingString) {
    MethodDeclaration result = null;
    if (typeDeclaration.bodyDeclarations() != null) {
        // check if method already declared
        for (Object bd : typeDeclaration.bodyDeclarations()) {
            if (bd instanceof MethodDeclaration) {
                MethodDeclaration md = (MethodDeclaration) bd;
                IMethodBinding binding = md.resolveBinding();
                if ((binding != null) && (bindingString != null)
                        && binding.toString().trim().equals(bindingString.trim())) {
                    result = md;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:org.eclipse.andmore.android.generatemenucode.model.codegenerators.CodeGeneratorBasedOnMenuVisitor.java

License:Apache License

/**
 * Visit method declaration, searching for instructions onCreate for
 * activity or fragment//  ww  w  . j  a  va 2 s. c o  m
 */
@Override
public boolean visit(MethodDeclaration node) {
    // Fill Method information
    SimpleName name = node.getName();
    if (name.getIdentifier().equals(ACTIVITY_ON_CREATE_MENU)
            || name.getIdentifier().equals(FRAGMENT_ON_CREATE_MENU)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            if (binding.toString().trim().contains(ACTIVITY_ON_CREATE_MENU_DECLARATION)
                    || binding.toString().trim().contains(FRAGMENT_ON_CREATE_MENU_DECLARATION)) {
                visitMethodBodyToIdentifyMenu(node);
            }
        }
    }

    return super.visit(node);
}

From source file:org.eclipse.andmore.android.generateviewbylayout.GenerateCodeBasedOnLayoutVisitor.java

License:Apache License

/**
 * Visit method declaration, searching for instructions onCreate for
 * activity or fragment//from   ww  w  .j  av a 2 s  .c  om
 */
@Override
public boolean visit(MethodDeclaration node) {
    // Fill Method information
    SimpleName name = node.getName();
    if (name.getIdentifier().equals(ACTIVITY_ON_CREATE) || name.getIdentifier().equals(FRAGMENT_ON_CREATE)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            if (binding.toString().trim().contains(ACTIVITY_ON_CREATE_DECLARATION)) {
                visitMethodBodyToIdentifyLayout(node);
            } else if (binding.toString().trim().contains(FRAGMENT_ON_CREATE_DECLARATION)) {
                if (node.getBody().statements().size() <= 1) {
                    throw new IllegalArgumentException(
                            CodeUtilsNLS.MethodVisitor_InvalidFormatForFragmentOnCreateView);
                } else {
                    visitMethodBodyToIdentifyLayout(node);
                }
            } else {
                // for each method visit to identify views already declared
                visitToIdentifyViewsAlreadyDeclared(node);
            }
        }
    } else if (name.getIdentifier().equals(ACTIVITY_ON_PAUSE)
            || name.getIdentifier().equals(ACTIVITY_ON_RESUME)) {
        IMethodBinding binding = node.resolveBinding();
        if (binding != null) {
            // find declared save state
            if (binding.toString().trim().contains(ACTIVITY_ON_PAUSE_DECLARATION)) {
                findSavedViews(node);
            }
            // find declared restore state
            else if (binding.toString().trim().contains(ACTIVITY_ON_RESUME_DECLARATION)) {
                findRestoredViews(node);
            }

        }
    } else {
        // for each method visit to identify views already declared
        visitToIdentifyViewsAlreadyDeclared(node);
    }
    return super.visit(node);
}