Example usage for org.eclipse.jdt.core Flags AccVarargs

List of usage examples for org.eclipse.jdt.core Flags AccVarargs

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Flags AccVarargs.

Prototype

int AccVarargs

To view the source code for org.eclipse.jdt.core Flags AccVarargs.

Click Source Link

Document

Varargs method property flag (added in J2SE 1.5).

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java

License:Open Source License

private AbstractMethodDeclaration convert(IMethod method, IType type) throws JavaModelException {

    AbstractMethodDeclaration methodDeclaration;

    org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = null;

    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {
        /* convert type parameters */
        ITypeParameter[] typeParameters = method.getTypeParameters();
        if (typeParameters != null && typeParameters.length > 0) {
            int parameterCount = typeParameters.length;
            typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                ITypeParameter typeParameter = typeParameters[i];
                typeParams[i] = createTypeParameter(typeParameter.getElementName().toCharArray(),
                        stringArrayToCharArray(typeParameter.getBounds()), 0, 0);
            }//w  w w. j  ava 2 s .c  o m
        }
    }

    if (method.isConstructor()) {
        ConstructorDeclaration decl = new ConstructorDeclaration(this.compilationResult);
        decl.bits &= ~ASTNode.IsDefaultConstructor;
        decl.typeParameters = typeParams;
        methodDeclaration = decl;
    } else {
        MethodDeclaration decl = type.isAnnotation() ? new AnnotationMethodDeclaration(this.compilationResult)
                : new MethodDeclaration(this.compilationResult);
        /* convert return type */
        TypeReference typeReference = createTypeReference(method.getReturnType());
        if (typeReference == null)
            return null;
        decl.returnType = typeReference;
        decl.typeParameters = typeParams;
        methodDeclaration = decl;
    }
    methodDeclaration.selector = method.getElementName().toCharArray();
    int flags = method.getFlags();
    boolean isVarargs = Flags.isVarargs(flags);
    methodDeclaration.modifiers = flags & ~Flags.AccVarargs;

    /* convert arguments */
    String[] argumentTypeNames = method.getParameterTypes();
    String[] argumentNames = method.getParameterNames();
    int argumentCount = argumentTypeNames == null ? 0 : argumentTypeNames.length;
    // Ignore synthetic arguments (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212224)
    int startIndex = (method.isConstructor() && type.isMember() && !Flags.isStatic(type.getFlags())) ? 1 : 0;
    argumentCount -= startIndex;
    methodDeclaration.arguments = new Argument[argumentCount];
    for (int i = 0; i < argumentCount; i++) {
        String argumentTypeName = argumentTypeNames[startIndex + i];
        TypeReference typeReference = createTypeReference(argumentTypeName);
        if (typeReference == null)
            return null;
        if (isVarargs && i == argumentCount - 1) {
            typeReference.bits |= ASTNode.IsVarArgs;
        }
        methodDeclaration.arguments[i] = new Argument(argumentNames[i].toCharArray(), 0, typeReference,
                ClassFileConstants.AccDefault);
        // do not care whether was final or not
    }

    /* convert thrown exceptions */
    String[] exceptionTypeNames = method.getExceptionTypes();
    int exceptionCount = exceptionTypeNames == null ? 0 : exceptionTypeNames.length;
    if (exceptionCount > 0) {
        methodDeclaration.thrownExceptions = new TypeReference[exceptionCount];
        for (int i = 0; i < exceptionCount; i++) {
            TypeReference typeReference = createTypeReference(exceptionTypeNames[i]);
            if (typeReference == null)
                return null;
            methodDeclaration.thrownExceptions[i] = typeReference;
        }
    }
    return methodDeclaration;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorPattern.java

License:Open Source License

public ConstructorPattern(char[] declaringSimpleName, char[] declaringQualification,
        char[][] parameterQualifications, char[][] parameterSimpleNames, String[] parameterSignatures,
        IMethod method, int limitTo, int matchRule) {

    this(declaringSimpleName, declaringQualification, parameterQualifications, parameterSimpleNames, limitTo,
            matchRule);/*w  w w .j  ava  2s .  c  o  m*/

    // Set flags
    try {
        this.varargs = (method.getFlags() & Flags.AccVarargs) != 0;
    } catch (JavaModelException e) {
        // do nothing
    }

    // Get unique key for parameterized constructors
    String genericDeclaringTypeSignature = null;
    if (method.isResolved()) {
        String key = method.getKey();
        BindingKey bindingKey = new BindingKey(key);
        if (bindingKey.isParameterizedType()) {
            genericDeclaringTypeSignature = Util.getDeclaringTypeSignature(key);
            // Store type signature and arguments for declaring type
            if (genericDeclaringTypeSignature != null) {
                this.typeSignatures = Util.splitTypeLevelsSignature(genericDeclaringTypeSignature);
                setTypeArguments(Util.getAllTypeArguments(this.typeSignatures));
            }
        }
    } else {
        this.constructorParameters = true;
        storeTypeSignaturesAndArguments(method.getDeclaringType());
    }

    // store type signatures and arguments for method parameters type
    if (parameterSignatures != null) {
        int length = parameterSignatures.length;
        if (length > 0) {
            this.parametersTypeSignatures = new char[length][][];
            this.parametersTypeArguments = new char[length][][][];
            for (int i = 0; i < length; i++) {
                this.parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]);
                this.parametersTypeArguments[i] = Util.getAllTypeArguments(this.parametersTypeSignatures[i]);
            }
        }
    }

    // Store type signatures and arguments for method
    this.constructorArguments = extractMethodArguments(method);
    if (hasConstructorArguments())
        this.mustResolve = true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodPattern.java

License:Open Source License

public MethodPattern(char[] selector, char[] declaringQualification, char[] declaringSimpleName,
        char[] returnQualification, char[] returnSimpleName, String returnSignature,
        char[][] parameterQualifications, char[][] parameterSimpleNames, String[] parameterSignatures,
        IMethod method, int limitTo, int matchRule) {

    this(selector, declaringQualification, declaringSimpleName, returnQualification, returnSimpleName,
            parameterQualifications, parameterSimpleNames, method.getDeclaringType(), limitTo, matchRule);

    // Set flags// www  . j  ava 2 s.co m
    try {
        this.varargs = (method.getFlags() & Flags.AccVarargs) != 0;
    } catch (JavaModelException e) {
        // do nothing
    }

    // Get unique key for parameterized constructors
    String genericDeclaringTypeSignature = null;
    if (method.isResolved()) {
        String key = method.getKey();
        BindingKey bindingKey = new BindingKey(key);
        if (bindingKey.isParameterizedType()) {
            genericDeclaringTypeSignature = Util.getDeclaringTypeSignature(key);
            // Store type signature and arguments for declaring type
            if (genericDeclaringTypeSignature != null) {
                this.typeSignatures = Util.splitTypeLevelsSignature(genericDeclaringTypeSignature);
                setTypeArguments(Util.getAllTypeArguments(this.typeSignatures));
            }
        }
    } else {
        this.methodParameters = true;
        storeTypeSignaturesAndArguments(this.declaringType);
    }

    // Store type signatures and arguments for return type
    if (returnSignature != null) {
        this.returnTypeSignatures = Util.splitTypeLevelsSignature(returnSignature);
    }

    // Store type signatures and arguments for method parameters type
    if (parameterSignatures != null) {
        int length = parameterSignatures.length;
        if (length > 0) {
            this.parametersTypeSignatures = new char[length][][];
            this.parametersTypeArguments = new char[length][][][];
            for (int i = 0; i < length; i++) {
                this.parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]);
                this.parametersTypeArguments[i] = Util.getAllTypeArguments(this.parametersTypeSignatures[i]);
            }
        }
    }

    // Store type signatures and arguments for method
    this.methodArguments = extractMethodArguments(method);
    if (hasMethodArguments())
        this.mustResolve = true;
}

From source file:org.eclipse.emf.test.tools.merger.facade.FacadeAPITest.java

License:Open Source License

@Test
public void testFacadeFlags() {
    assertEquals(Flags.AccAbstract, FacadeFlags.ABSTRACT);
    assertEquals(Flags.AccAnnotation, FacadeFlags.ANNOTATION);
    assertEquals(Flags.AccBridge, FacadeFlags.BRIDGE);
    assertEquals(Flags.AccDefault, FacadeFlags.DEFAULT);
    assertEquals(Flags.AccDeprecated, FacadeFlags.DEPRECATED);
    assertEquals(Flags.AccEnum, FacadeFlags.ENUM);
    assertEquals(Flags.AccFinal, FacadeFlags.FINAL);
    assertEquals(Flags.AccInterface, FacadeFlags.INTERFACE);
    assertEquals(Flags.AccNative, FacadeFlags.NATIVE);
    assertEquals(Flags.AccPrivate, FacadeFlags.PRIVATE);
    assertEquals(Flags.AccProtected, FacadeFlags.PROTECTED);
    assertEquals(Flags.AccPublic, FacadeFlags.PUBLIC);
    assertEquals(Flags.AccStatic, FacadeFlags.STATIC);
    assertEquals(Flags.AccStrictfp, FacadeFlags.STRICTFP);
    assertEquals(Flags.AccSuper, FacadeFlags.SUPER);
    assertEquals(Flags.AccSynchronized, FacadeFlags.SYNCHRONIZED);
    assertEquals(Flags.AccSynthetic, FacadeFlags.SYNTHETIC);
    assertEquals(Flags.AccTransient, FacadeFlags.TRANSIENT);
    assertEquals(Flags.AccVarargs, FacadeFlags.VARARGS);
    assertEquals(Flags.AccVolatile, FacadeFlags.VOLATILE);
}