Example usage for org.eclipse.jdt.core.dom MethodDeclaration getModifiers

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration getModifiers

Introduction

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

Prototype

public int getModifiers() 

Source Link

Document

Returns the modifiers explicitly specified on this declaration.

Usage

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean hasDefaultConstructor(TypeDeclaration type) {
    boolean hasConstructor = false;
    for (MethodDeclaration method : type.getMethods()) {
        if (method.isConstructor()) {
            hasConstructor = true;//  www .  j  a  v a2s .c om
            if (Modifier.isPublic(method.getModifiers()) && method.parameters().isEmpty())
                return true;
        }
    }

    return !hasConstructor;
}

From source file:cc.kave.eclipse.commons.analysis.transformer.DeclarationVisitor.java

License:Apache License

private void methodDeclHelper(MethodDeclaration decl) {
    if (decl != null) {
        MethodName methodName = (MethodName) NodeFactory.createNodeName(decl);

        // if (!isNestedDeclaration(methodName, context)) {
        cc.kave.commons.model.ssts.impl.declarations.MethodDeclaration sstDecl = new cc.kave.commons.model.ssts.impl.declarations.MethodDeclaration();
        sstDecl.setName(methodName);/*from w w w. j  a  va 2 s . co  m*/
        sstDecl.setEntryPoint(entryPoints.contains(methodName));

        context.getMethods().add(sstDecl);

        if (decl == marker.getAffectedNode()) {
            ExpressionStatement expStatement = new ExpressionStatement();
            expStatement.setExpression(new CompletionExpression());
            sstDecl.getBody().add(expStatement);
        }

        if (!Modifier.isAbstract(decl.getModifiers())) {
            BodyVisitor bodyVisitor = new BodyVisitor(new UniqueVariableNameGenerator(), marker,
                    new ArrayList<IStatement>());
            decl.accept(bodyVisitor);
        }
    }
    // }
}

From source file:com.architexa.diagrams.jdt.extractors.TypeMembersModifierExtractor.java

License:Open Source License

@Override
public boolean visit(MethodDeclaration methodDecl) {
    Resource methodDeclRes = bindingToResource(methodDecl.resolveBinding());
    addModifiers(methodDeclRes, methodDecl.getModifiers());
    return true;//from w w w . ja  va 2 s . co m
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns nodes description./* w ww  . j  av a  2  s  .c o m*/
 * 
 * @param node the AST-node
 * @return description string
 */
public static String getNodeDescr(ASTNode node) {
    StringBuffer elementDescr = new StringBuffer(node.getClass().getSimpleName());
    elementDescr.append(": ");

    int nodeType = node.getNodeType();
    switch (nodeType) {
    case ASTNode.COMPILATION_UNIT:
        CompilationUnit cu = (CompilationUnit) node;
        elementDescr.append(cu.getJavaElement().getElementName());
        break;

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration pd = (PackageDeclaration) node;
        elementDescr.append(pd.getName());
        break;

    case ASTNode.TYPE_DECLARATION:
        TypeDeclaration td = (TypeDeclaration) node;
        appendModifiers(td.getModifiers(), elementDescr);
        elementDescr.append(" class ");
        elementDescr.append(td.getName());
        break;

    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration md = (MethodDeclaration) node;
        appendModifiers(md.getModifiers(), elementDescr);
        elementDescr.append(md.getReturnType2() == null ? "" : md.getReturnType2().toString());
        elementDescr.append(' ');
        elementDescr.append(md.getName());
        elementDescr.append("()");
        break;

    case ASTNode.BLOCK:
        elementDescr.append("{...}");
        break;

    case ASTNode.IF_STATEMENT:
        IfStatement is = (IfStatement) node;
        elementDescr.append("if( ");
        elementDescr.append(is.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.FOR_STATEMENT:
        ForStatement fs = (ForStatement) node;
        elementDescr.append("for (...; ");
        elementDescr.append(fs.getExpression().toString());
        elementDescr.append("; ...){...}");
        break;

    case ASTNode.WHILE_STATEMENT:
        WhileStatement ws = (WhileStatement) node;
        elementDescr.append("while ( ");
        elementDescr.append(ws.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.DO_STATEMENT:
        DoStatement ds = (DoStatement) node;
        elementDescr.append("do {...} while (");
        elementDescr.append(ds.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.LABELED_STATEMENT:
        LabeledStatement ls = (LabeledStatement) node;
        elementDescr.append(ls.getLabel().toString());
        elementDescr.append(":");
        break;

    case ASTNode.CATCH_CLAUSE:
        CatchClause cs = (CatchClause) node;
        elementDescr.append("catch (");
        elementDescr.append(cs.getException().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_STATEMENT:
        SwitchStatement ss = (SwitchStatement) node;
        elementDescr.append("switch (");
        elementDescr.append(ss.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_CASE:
        SwitchCase sc = (SwitchCase) node;
        elementDescr.append("case ");
        elementDescr.append(sc.getExpression() == null ? "default" : sc.getExpression().toString());
        elementDescr.append(":");
        break;
    case ASTNode.JAVADOC:
    case ASTNode.BLOCK_COMMENT:
    case ASTNode.LINE_COMMENT:
    case ASTNode.TRY_STATEMENT:
        /* nothing to do */
        break;

    default:
        elementDescr.append(node.toString());
    }

    /* cut the string if it is too long */
    String str = elementDescr.toString();
    if (str.length() > 128) {
        str = str.substring(0, 128) + " ... ";
    }
    str = str.replaceAll("\n", "");
    return str;
}

From source file:com.github.parzonka.ccms.sorter.comparator.astextractor.AccessLevelComparatorExtractor.java

License:Open Source License

private static int getAccessLevel(MethodDeclaration method) {
    int modifiers = method.getModifiers();
    if (Modifier.isPublic(modifiers))
        return 0;
    if (Modifier.isProtected(modifiers))
        return 1;
    if (Modifier.isPrivate(modifiers))
        return 3;
    else/*ww w . j  a v a  2s  . c  o  m*/
        return 2;
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

@Override
protected String methodDeclaration(MethodDeclaration m) {
    int modifiers = m.getModifiers();
    if ((modifiers & Modifier.NATIVE) > 0) {
        return super.methodDeclaration(m) + " " + extractNativeMethodBody(m) + "\n\n";
    }//from w  w  w.  j a va2s .  c  o  m
    String methodBody = generateMethodBody(m);
    return super.methodDeclaration(m) + " " + reindent(methodBody) + "\n\n";
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

@Override
protected String mappedMethodDeclaration(MethodDeclaration method, IOSMethod mappedMethod) {
    String methodBody;/*from  w ww .  j  a  va 2 s .  c o m*/
    if ((method.getModifiers() & Modifier.NATIVE) > 0) {
        methodBody = extractNativeMethodBody(method);
    } else {
        methodBody = generateMethodBody(method);
    }
    return super.mappedMethodDeclaration(method, mappedMethod) + " " + reindent(methodBody) + "\n\n";
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

private String generateMethodBody(MethodDeclaration m) {
    if (Modifier.isAbstract(m.getModifiers())) {
        // Generate a body which throws a NSInvalidArgumentException.
        String body = "{\n // can't call an abstract method\n " + "[self doesNotRecognizeSelector:_cmd];\n ";
        if (!Types.isVoidType(m.getReturnType2())) {
            body += "return 0;\n"; // Never executes, but avoids a gcc warning.
        }//from w w w  . ja  va  2 s . co  m
        return body + "}";
    }
    // generate a normal method body
    String methodBody = generateStatement(m.getBody(), false);
    if (Types.hasAutoreleasePoolAnnotation(Types.getBinding(m))) {
        return reindent("{\nNSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n" + methodBody
                + "[pool__ release];\n}");
    } else {
        return methodBody;
    }
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

private void printMainMethod(MethodDeclaration m, String typeName, List<IMethodBinding> testMethods) {
    if (m != null) { // True for unit tests.
        Types.addFunction(Types.getMethodBinding(m));
    }//w w w  .  j av a 2  s .c  o m
    println("int main( int argc, const char *argv[] ) {");
    if (m != null && (m.getModifiers() & Modifier.NATIVE) > 0) {
        println(extractNativeMethodBody(m));
        return;
    }
    indent();
    if (Options.useReferenceCounting()) {
        printIndent();
        println("NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];");
    }

    if (m != null) {
        @SuppressWarnings("unchecked")
        List<SingleVariableDeclaration> params = m.parameters();
        assert params.size() == 1; // Previously checked in isMainMethod().
        printIndent();
        printf("IOSObjectArray *%s = JreEmulationMainArguments(argc, argv);\n\n",
                params.get(0).getName().getIdentifier());
        printMethodBody(m, true);
    }
    if (testMethods != null) {
        printIndent();
        printf("int exitCode = [JUnitRunner runTests:[%s class]", typeName);
        for (IMethodBinding test : testMethods) {
            printf(", @\"%s\"", test.getName());
        }
        println(", nil];");
    } else {
        printIndent();
        println("int exitCode = 0;");
    }
    if (Options.useReferenceCounting()) {
        print('\n');
        printIndent();
        println("[pool release];");
    }
    printIndent();
    println("return exitCode;");
    unindent();
    println("}");
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

private String extractNativeMethodBody(MethodDeclaration m) {
    assert (m.getModifiers() & Modifier.NATIVE) > 0;
    String nativeCode = extractNativeCode(m.getStartPosition(), m.getLength());
    if (nativeCode == null) {
        J2ObjC.error(m, "no native code found");
        return "ERROR";
    }/*from www  .j  a v  a  2  s. co  m*/
    indent();
    String code = reindent('{' + nativeCode + '}');
    unindent();
    return code;
}