Example usage for org.aspectj.asm IProgramElement getAccessibility

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

Introduction

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

Prototype

public Accessibility getAccessibility();

Source Link

Usage

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

License:Open Source License

private String getAccessibilityString(IProgramElement declareElt) {
    return (declareElt.getAccessibility() != Accessibility.PACKAGE ? declareElt.getAccessibility().toString()
            : "") + " ";
}

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

License:Open Source License

protected Object createElementInfo() {

    AspectElementInfo info = new AspectElementInfo();
    info.setAJKind(IProgramElement.Kind.ASPECT);
    info.setHandle(this);
    info.setSourceRangeStart(0);/*from  w  w w.ja  v a2s  . c  o m*/

    IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
            .javaElementToProgramElement(this);
    if (ipe != null && ipe != IHierarchy.NO_STRUCTURE) {
        info.setAJExtraInfo(ipe.getExtraInfo());
        info.setAJModifiers(ipe.getModifiers());
        info.setFlags(getProgramElementModifiers(ipe));
        info.setAJAccessibility(ipe.getAccessibility());
        ISourceLocation sourceLocation = ipe.getSourceLocation();
        info.setSourceRangeStart(sourceLocation.getOffset());
        info.setNameSourceStart(sourceLocation.getOffset());
        info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length());
        // info.setPrivileged(???); not setting this yet
    }
    return info;
}

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

License:Open Source License

public static int getModifierCode(IProgramElement elem) {
    IProgramElement.Accessibility acc = elem.getAccessibility();
    List<Modifiers> others = elem.getModifiers();
    int modifiers = 0;
    if (acc == IProgramElement.Accessibility.PUBLIC) {
        modifiers |= ClassFileConstants.AccPublic;
    } else if (acc == IProgramElement.Accessibility.PROTECTED) {
        modifiers |= ClassFileConstants.AccProtected;
    } else if (acc == IProgramElement.Accessibility.PRIVATE) {
        modifiers |= ClassFileConstants.AccPrivate;
    }/*www .  j av  a  2 s .c  om*/

    if (others != null) {
        if (others.contains(IProgramElement.Modifiers.ABSTRACT)) {
            modifiers |= ClassFileConstants.AccAbstract;
        }
        if (others.contains(IProgramElement.Modifiers.FINAL)) {
            modifiers |= ClassFileConstants.AccFinal;
        }
        if (others.contains(IProgramElement.Modifiers.NATIVE)) {
            modifiers |= ClassFileConstants.AccNative;
        }
        if (others.contains(IProgramElement.Modifiers.STATIC)) {
            modifiers |= ClassFileConstants.AccStatic;
        }
        if (others.contains(IProgramElement.Modifiers.SYNCHRONIZED)) {
            modifiers |= ClassFileConstants.AccSynchronized;
        }
        if (others.contains(IProgramElement.Modifiers.TRANSIENT)) {
            modifiers |= ClassFileConstants.AccTransient;
        }
        if (others.contains(IProgramElement.Modifiers.VOLATILE)) {
            modifiers |= ClassFileConstants.AccVolatile;
        }
    }
    return modifiers;
}

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  2s .c o  m*/
        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.MockSourceMethod.java

License:Open Source License

protected Object createElementInfo() {
    if (elementInfo != null) {
        return elementInfo;
    }/*from   w  w w  .j a  v  a2  s .  com*/

    try {
        IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
                .javaElementToProgramElement(this);

        elementInfo = new MethodElementInfo();
        ISourceLocation sourceLocation = ipe.getSourceLocation();
        elementInfo.setSourceRangeStart(sourceLocation.getOffset());
        elementInfo.setNameSourceStart(sourceLocation.getOffset());
        elementInfo.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length());
        elementInfo.setAJExtraInfo(ipe.getExtraInfo());
        elementInfo.setName(name.toCharArray());
        elementInfo.setAJKind(IProgramElement.Kind.METHOD);
        elementInfo.setAJModifiers(ipe.getModifiers());
        elementInfo.setAJAccessibility(ipe.getAccessibility());

        return elementInfo;
    } catch (Exception e) {
        // can fail for any of a number of reasons.
        // return null so that we can try again later.
        return null;
    }
}

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

License:Open Source License

protected Object createElementInfo() {
    IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
            .javaElementToProgramElement(this);

    PointcutElementInfo info = new PointcutElementInfo();
    info.setAJKind(IProgramElement.Kind.POINTCUT);
    info.setName(this.getElementName().toCharArray());
    info.setAJAccessibility(ipe.getAccessibility());
    ISourceLocation sourceLocation = ipe.getSourceLocation();
    if (sourceLocation != null) {
        info.setSourceRangeStart(sourceLocation.getOffset());
        info.setNameSourceStart(sourceLocation.getOffset());
        info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length());
    }//from   w  w  w .  jav a 2s . co m
    return info;
}

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

License:Open Source License

/**
 * augments a type with ITD info/*from  w w  w .  j  av  a 2 s.c  om*/
 */
private void augmentType(TypeDeclaration type) {

    OrigContents orig = new OrigContents();
    orig.methods = type.methods;
    orig.fields = type.fields;
    orig.superClass = type.superclass;
    orig.superInterfaces = type.superInterfaces;
    orig.memberTypes = type.memberTypes;

    try {
        List<FieldDeclaration> itdFields = new LinkedList<FieldDeclaration>();
        List<AbstractMethodDeclaration> itdMethods = new LinkedList<AbstractMethodDeclaration>();
        List<TypeDeclaration> itits = new LinkedList<TypeDeclaration>();
        IType handle = getHandle(type);

        List<IProgramElement> ipes = getITDs(handle);
        for (IProgramElement elt : ipes) {
            if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_METHOD) {
                // ignore if type is an interface.
                // assumption is that this ITD is an implementation of an interface method
                // adding it here would cause a duplicate method error.
                // These are added to the first class that instantiates this interface
                // See bug 257437
                if (TypeDeclaration.kind(type.modifiers) == TypeDeclaration.CLASS_DECL) {
                    if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) {
                        itdMethods.add(createMethod(elt, type, handle));
                    }
                }

            } else if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR) {
                if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) {
                    itdMethods.add(createConstructor(elt, type));
                }
            } else if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_FIELD) {
                // XXX hmmmm..should I also skip this if the type is an interface???
                if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) {
                    itdFields.add(createField(elt, type));
                }
            } else if (elt.getKind() == IProgramElement.Kind.DECLARE_PARENTS) {
                boolean isClass = isClass(elt);
                if (isClass && TypeDeclaration.kind(type.modifiers) == TypeDeclaration.CLASS_DECL) {
                    addSuperClass(elt, type);
                } else {
                    addSuperInterfaces(elt, type);
                }
            } else if (elt.getKind() == IProgramElement.Kind.CLASS) {
                // this is an ITIT - intertype inner type
                TypeDeclaration ititAST = createITIT(elt.getName(), type);
                if (ititAST != null) {
                    // add children, etc
                    populateITIT(ititAST, elt);
                    itits.add(ititAST);
                }
            } else if (elt.getKind() == IProgramElement.Kind.ASPECT) {
                // probably an instantiation of a declare parents relationship from an abstact aspect
                Map<String, List<String>> parentsMap = elt.getDeclareParentsMap();
                if (parentsMap != null && type.binding != null && type.binding.compoundName != null) {
                    List<String> parents = parentsMap
                            .get(String.valueOf(CharOperation.concatWith(type.binding.compoundName, '.')));
                    List<String> interfacesToAdd = new LinkedList<String>();
                    for (String parent : parents) {
                        try {
                            IType parentElt = unit.getJavaProject().findType(parent, (IProgressMonitor) null);
                            if (parentElt != null && parentElt.isClass()) {
                                addSuperClass(parent, type);
                            } else if (parentElt != null && parentElt.isInterface()) {
                                interfacesToAdd.add(parent);
                            }
                        } catch (JavaModelException e) {
                        }
                    }
                    addSuperInterfaces(interfacesToAdd, type);
                }
            }
        }

        if (ipes.size() > 0) {
            origMap.put(type, orig);

            // now add the ITDs into the declaration
            if (itdFields.size() > 0) {
                int numFields = type.fields == null ? 0 : type.fields.length;
                FieldDeclaration[] fields = new FieldDeclaration[numFields + itdFields.size()];
                if (numFields > 0) {
                    System.arraycopy(type.fields, 0, fields, 0, numFields);
                }
                for (int i = 0; i < itdFields.size(); i++) {
                    fields[i + numFields] = itdFields.get(i);
                }
                type.fields = fields;
            }
            if (itdMethods.size() > 0) {
                int numMethods = type.methods == null ? 0 : type.methods.length;
                AbstractMethodDeclaration[] methods = new AbstractMethodDeclaration[numMethods
                        + itdMethods.size()];
                if (numMethods > 0) {
                    System.arraycopy(type.methods, 0, methods, 0, numMethods);
                }
                for (int i = 0; i < itdMethods.size(); i++) {
                    methods[i + numMethods] = itdMethods.get(i);
                }
                type.methods = methods;
            }
            if (itits.size() > 0) {
                int numInners = type.memberTypes == null ? 0 : type.memberTypes.length;
                TypeDeclaration[] inners = new TypeDeclaration[numInners + itits.size()];
                if (numInners > 0) {
                    System.arraycopy(type.memberTypes, 0, inners, 0, numInners);
                }
                for (int i = 0; i < itits.size(); i++) {
                    inners[i + numInners] = itits.get(i);
                }
                type.memberTypes = inners;
            }
        }
    } catch (Exception e) {
        // back out what we have done
        origMap.remove(type);
        revertType(type, orig);
    }
}