Example usage for org.aspectj.asm IProgramElement getRawModifiers

List of usage examples for org.aspectj.asm IProgramElement getRawModifiers

Introduction

In this page you can find the example usage for org.aspectj.asm IProgramElement getRawModifiers.

Prototype

public int getRawModifiers();

Source Link

Usage

From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java

License:Open Source License

private Operation createOperation(Class classifier, IProgramElement child) throws JavaModelException {

    //       protected Operation createOperation(Element element, IMethod method) throws JavaModelException
    //       {/*w ww.j a  v a  2 s  .c  om*/
    String methodName = child.getName();

    Operation operationObject = UMLFactory.eINSTANCE.createOperation();
    operationObject.setName(methodName);

    update(operationObject, child.getRawModifiers());

    int flags = child.getRawModifiers();
    operationObject.setIsAbstract(Flags.isAbstract(flags));
    operationObject.setIsStatic(Flags.isStatic(flags));

    attachJavadoc(operationObject, child);

    createParameters(classifier, operationObject, child);

    //JWK:  For now, I'm assuming that the child will exist and won't be a Constructor of some sort.
    //      if (child.exists() && !child.isConstructor())
    //      {
    // TEMP      createTemplateParameters(child, operationObject);

    //      String returnTypeSig = child.getReturnType();
    //
    //      String returnTypeWithoutArray = Signature.getElementType(returnTypeSig);
    //      String returnTypeName = Signature.toString(Signature.getTypeErasure(returnTypeWithoutArray));
    String returnTypeName = child.getCorrespondingType(true);
    Type returnType = findTemplateParameter(classifier, returnTypeName);
    if (returnType == null) {
        returnType = findTemplateParameter(operationObject, returnTypeName);
    }

    if (returnType == null) {
        returnType = findOrCreateType(classifier.getNearestPackage(), returnTypeName);
    }

    // Type returnType = findOrCreateType(element.getNearestPackage(),
    // returnTypeName);
    if (returnType != null) {
        operationObject.createReturnResult("return", returnType);
    }
    //      }

    return operationObject;

}

From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java

License:Open Source License

private Property createProperty(Element element, IProgramElement field) throws JavaModelException {

    String fieldName = field.getName();
    //      String fieldTypeSig = field.getCorrespondingType();
    ////from w ww .  ja v a  2s . c  om
    //      String fieldTypeWithoutArray = Signature.getElementType(fieldTypeSig);
    //      String fieldTypeName = Signature.toString(Signature.getTypeErasure(fieldTypeWithoutArray));
    String fieldTypeName = field.getCorrespondingType(true);
    Type fieldType = findTemplateParameter(element, fieldTypeName);
    if (fieldType == null) {
        fieldType = findOrCreateType(element.getNearestPackage(), fieldTypeName);
    }

    Property propertyObject = UMLFactory.eINSTANCE.createProperty();
    //           if (isGenericType(fieldType))
    //           {
    //               // TODO : find the explicit type and define a template parameter
    //               // extractGenericTypesFromCurrentSignature(fieldTypeSig);
    //           }
    propertyObject.setName(fieldName);
    if (fieldType != null) {
        propertyObject.setType(fieldType);
    }
    attachJavadoc(propertyObject, field);

    //BOOKMARK
    //JWK:  I'm hoping that getRawModifiers() = getFlags for IField.
    update(propertyObject, field.getRawModifiers());

    //      // No need to check the null (done with instanceof which returns always false)
    //      if (field.getConstant() instanceof String)
    //      {
    //         LiteralString defaultValue = (LiteralString) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralString().eClass());
    //         defaultValue.setValue((String) field.getConstant());
    //      }
    //      else if (field.getConstant() instanceof Integer)
    //      {
    //         LiteralInteger defaultValue = (LiteralInteger) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralInteger().eClass());
    //         defaultValue.setValue((Integer) field.getConstant());
    //      }
    //      else if (field.getConstant() instanceof Boolean)
    //      {
    //         LiteralBoolean defaultValue = (LiteralBoolean) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralBoolean().eClass());
    //         defaultValue.setValue((Boolean) field.getConstant());
    //      }

    return propertyObject;

}

From source file:org.eclipse.ajdt.core.javaelements.IntertypeElement.java

License:Open Source License

protected Object createElementInfo() {
    IntertypeElementInfo info = new IntertypeElementInfo();

    IProject project = this.getJavaProject().getProject();
    IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForProject(project)
            .javaElementToProgramElement(this);
    if (ipe != IHierarchy.NO_STRUCTURE) {
        // this way of creating the element info does not contain proper source locations for the name and target type
        info.setAJExtraInfo(ipe.getExtraInfo());
        info.setName(name.toCharArray());
        info.setAJKind(ipe.getKind());// w w w . j  av a 2 s  . c om
        info.setAJModifiers(ipe.getModifiers());
        info.setFlags(ipe.getRawModifiers());
        info.setDeclaredModifiers(info.getModifiers());
        info.setAJAccessibility(ipe.getAccessibility());
        ISourceLocation sourceLocation = ipe.getSourceLocation();
        info.setSourceRangeStart(sourceLocation.getOffset());
        info.setNameSourceStart(sourceLocation.getOffset()); // This is wrong
        info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // also wrong

        info.setConstructor(info.getAJKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
        char[][] argumentNames = CoreUtils.listStringsToCharArrays(ipe.getParameterNames());
        char[][] argumentTypeNames = CoreUtils.listCharsToCharArrays(ipe.getParameterTypes());
        if (argumentNames.length == 0 && argumentTypeNames.length > 0) {
            // argument names not found.  likely coming from binary class file w/p source attachment
            // generate argument names
            argumentNames = new char[argumentTypeNames.length][];
            for (int i = 0; i < argumentNames.length; i++) {
                argumentNames[i] = ("arg" + i).toCharArray();
            }
        }

        info.setArgumentNames(argumentNames);
        info.setArgumentTypeNames(argumentTypeNames);
        info.setReturnType(ipe.getCorrespondingType(false).toCharArray());
        info.setQualifiedReturnType(ipe.getCorrespondingType(true).toCharArray());

        info.setTypeParameters(createTypeParameters(project));

        if (argumentNames != null && argumentNames.length > 0) {
            ILocalVariable[] arguments = new ILocalVariable[argumentNames.length];
            for (int i = 0; i < argumentNames.length; i++) {
                arguments[i] = new LocalVariable(this, String.valueOf(argumentNames[i]),
                        // sloc is not correct, but it is close enough
                        sourceLocation.getOffset(), sourceLocation.getOffset() + 1, sourceLocation.getOffset(),
                        sourceLocation.getOffset() + 1, String.valueOf(argumentTypeNames[i]), new Annotation[0],
                        Flags.AccDefault, true);
            }
            info.setArguments(arguments);
        }

    } else {
        // no successful build yet, we don't know the contents
        info.setName(name.toCharArray());
        info.setAJKind(IProgramElement.Kind.ERROR);
        info.setAJModifiers(Collections.<Modifiers>emptyList());
    }
    return info;
}

From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java

License:Open Source License

private FieldDeclaration createField(IProgramElement field, TypeDeclaration type) {
    FieldDeclaration decl = new FieldDeclaration();
    String[] split = field.getName().split("\\.");
    decl.name = split[split.length - 1].toCharArray();
    decl.type = createTypeReference(field.getCorrespondingType(true));
    decl.modifiers = field.getRawModifiers();
    return decl;//from   w w  w.  ja  va  2  s  .co  m
}

From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java

License:Open Source License

private MethodDeclaration createMethod(IProgramElement method, TypeDeclaration type, IType handle) {
    MethodDeclaration decl = new MethodDeclaration(type.compilationResult);
    decl.scope = new MethodScope(type.scope, decl, true);

    String[] split = method.getName().split("\\.");
    decl.selector = split[split.length - 1].toCharArray();
    decl.modifiers = method.getRawModifiers();

    decl.returnType = createTypeReference(method.getCorrespondingType(true));
    decl.modifiers = method.getRawModifiers();
    Argument[] args = method.getParameterTypes() != null ? new Argument[method.getParameterTypes().size()]
            : new Argument[0];
    try {/*from  w  ww  .  ja v a  2  s.  co  m*/
        ErasedTypeSignature sig = null;
        if (handle != null) {
            AJWorldFacade world = new AJWorldFacade(handle.getJavaProject().getProject());
            sig = world.getMethodTypeSignatures(
                    Signature.createTypeSignature(handle.getFullyQualifiedName(), true), method);
        }
        if (sig == null) {
            String[] params = new String[method.getParameterTypes().size()];
            for (int i = 0; i < params.length; i++) {
                params[i] = new String(Signature.getTypeErasure((char[]) method.getParameterTypes().get(i)));
            }
            sig = new ErasedTypeSignature(method.getCorrespondingTypeSignature(), params);
        }

        List<String> pNames = method.getParameterNames();
        // bug 270123... no parameter names if coming in from a jar and
        // not build with debug info...mock it up.
        if (pNames == null || pNames.size() != args.length) {
            pNames = new ArrayList<String>(args.length);
            for (int i = 0; i < args.length; i++) {
                pNames.add("args" + i);
            }
        }
        for (int i = 0; i < args.length; i++) {
            args[i] = new Argument(((String) pNames.get(i)).toCharArray(), 0,
                    createTypeReference(Signature.getElementType(sig.paramTypes[i])), 0);
        }

        decl.returnType = createTypeReferenceFromSignature(sig.returnTypeSig);
        decl.typeParameters = createTypeParameters(sig.typeParameters);
    } catch (Exception e) {
        AJLog.log("Exception occurred in ITDInserter.createMethod().  (Ignoring)");
        AJLog.log("Relevant method: " + method.getParent().getName() + "." + method.getName());
        List<String> pNames = method.getParameterNames();
        // bug 270123... no parameter names if coming in from a jar and
        // not build with debug info...mock it up.
        if (pNames == null || pNames.size() != args.length) {
            pNames = new ArrayList<String>(args.length);
            for (int i = 0; i < args.length; i++) {
                pNames.add("args" + i);
            }
        }
        for (int i = 0; i < args.length; i++) {
            args[i] = new Argument(((String) pNames.get(i)).toCharArray(), 0,
                    createTypeReference(new String((char[]) method.getParameterTypes().get(i))), 0);
        }
    }
    decl.arguments = args;
    return decl;
}

From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java

License:Open Source License

private ConstructorDeclaration createConstructor(IProgramElement constructor, TypeDeclaration type) {
    ConstructorDeclaration decl = new ConstructorDeclaration(type.compilationResult);
    decl.scope = new MethodScope(type.scope, decl, true);
    decl.selector = constructor.getName().split("\\.")[1].toCharArray();
    decl.modifiers = constructor.getRawModifiers();
    Argument[] args = constructor.getParameterTypes() != null
            ? new Argument[constructor.getParameterTypes().size()]
            : new Argument[0];

    List<String> pNames = constructor.getParameterNames();
    // bug 270123, bug 334328... no parameter names if coming in from a jar and
    // not build with debug info...mock it up.
    if (pNames == null || pNames.size() != args.length) {
        pNames = new ArrayList<String>(args.length);
        for (int i = 0; i < args.length; i++) {
            pNames.add("args" + i);
        }//from  w  w w .  ja v a2 s.co  m
    }

    for (int i = 0; i < args.length; i++) {
        args[i] = new Argument(pNames.get(i).toCharArray(), 0,
                createTypeReference(new String((char[]) constructor.getParameterTypes().get(i))), 0);
    }
    decl.arguments = args;
    return decl;
}