Example usage for org.aspectj.asm IProgramElement getCorrespondingType

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

Introduction

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

Prototype

public String getCorrespondingType(boolean getFullyQualifiedType);

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
    //       {//from  w  ww. java  2 s. co  m
    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  ww w.j  ava2  s .c o  m
    //      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.codeconversion.AspectsConvertingParser.java

License:Open Source License

/**
 * @param sb//w  w  w . ja  va2 s.  c  om
 * @param declareElt
 */
protected void createITITText(StringBuffer sb, IProgramElement declareElt) {
    sb.append("\n\tstatic class ").append(declareElt.getName()).append(" {\n");
    List<IProgramElement> children = declareElt.getChildren();
    for (IProgramElement child : children) {
        sb.append("\t\tpublic static ");
        sb.append(child.getCorrespondingType(true) + " ");
        sb.append(child.getName());
        if (child.getKind() == IProgramElement.Kind.FIELD) {
            sb.append(";\n");
        } else {
            sb.append("(");
            List<String> names = child.getParameterNames();
            List<char[]> types = child.getParameterTypes();
            if (types != null && names != null) {
                for (Iterator<?> typeIter = types.iterator(), nameIter = names.iterator(); typeIter
                        .hasNext();) {
                    String paramType = String.valueOf((char[]) typeIter.next());
                    String paramName = (String) nameIter.next();
                    sb.append(paramType + " " + paramName);
                    if (typeIter.hasNext()) {
                        sb.append(", ");
                    }
                }
            }
            sb.append(") { }\n");
        }
    }
    sb.append("\t}\n");
}

From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java

License:Open Source License

/**
 * @param currentTypeName//from   w  w  w  .  j  av  a  2 s .  c  o m
 * @param sb
 * @param declareElt
 * @param name
 */
protected void createITDMethodText(char[] currentTypeName, StringBuffer sb, IProgramElement declareElt,
        String name) {
    sb.append(getAccessibilityString(declareElt));
    for (IProgramElement.Modifiers modifier : declareElt.getModifiers()) {
        sb.append(modifier + " ");
    }
    // need to add a return statement?
    if (declareElt.getKind() == IProgramElement.Kind.INTER_TYPE_METHOD) {
        sb.append(declareElt.getCorrespondingType(true) + " " + name);
    } else {
        sb.append(currentTypeName);
    }
    sb.append("(");
    List<String> names = declareElt.getParameterNames();
    List<char[]> types = declareElt.getParameterTypes();
    if (types != null && names != null) {
        for (Iterator<?> typeIter = types.iterator(), nameIter = names.iterator(); typeIter.hasNext();) {
            String paramType = String.valueOf((char[]) typeIter.next());
            String paramName = (String) nameIter.next();
            sb.append(paramType + " " + paramName);
            if (typeIter.hasNext()) {
                sb.append(", ");
            }
        }
    }
    sb.append(") { }\n");
}

From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java

License:Open Source License

/**
 * @param sb/*from w  w  w  .ja  va  2s  .  co m*/
 * @param declareElt
 * @param name
 */
protected void createITDFieldText(StringBuffer sb, IProgramElement declareElt, String name) {
    for (IProgramElement.Modifiers modifier : declareElt.getModifiers()) {
        sb.append(modifier + " ");
    }
    sb.append(declareElt.getCorrespondingType(true) + " " + name + ";\n\t");
}

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  ww  .j a  v  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.javaelements.IntertypeElement.java

License:Open Source License

char[] getQualifiedReturnTypeName(IntertypeElementInfo info) {
    char[] returnType = info.getQualifiedReturnType();
    if (returnType != null) {
        return returnType;
    }/*from  w  ww . j  a  v a  2 s.c o m*/

    IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
            .javaElementToProgramElement(this);
    if (ipe != IHierarchy.NO_STRUCTURE) {
        return ipe.getCorrespondingType(true).toCharArray();
    } else {
        return info.getReturnTypeName();
    }
}

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  ww w  .  j  a v  a 2 s .c  o 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 {/* w w w . j  ava2  s  .  c  om*/
        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;
}