Example usage for org.aspectj.asm IHierarchy NO_STRUCTURE

List of usage examples for org.aspectj.asm IHierarchy NO_STRUCTURE

Introduction

In this page you can find the example usage for org.aspectj.asm IHierarchy NO_STRUCTURE.

Prototype

IProgramElement NO_STRUCTURE

To view the source code for org.aspectj.asm IHierarchy NO_STRUCTURE.

Click Source Link

Usage

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  ww  w .  j  a  v  a2s. co  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.DeclareElement.java

License:Open Source License

protected Object createElementInfo() {
    try {/*from w  w  w.jav a2s.c om*/
        IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
                .javaElementToProgramElement(this);

        DeclareElementInfo elementInfo = new DeclareElementInfo();
        if (ipe != IHierarchy.NO_STRUCTURE) {
            elementInfo.setSourceRangeStart(ipe.getSourceLocation().getOffset());
            elementInfo.setName(name.toCharArray());
            elementInfo.setAJKind(getKindForString(name));

            List<String> types = ipe.getParentTypes();
            if (types != null) {
                List<String> typesConverted = new ArrayList<String>(types.size());
                for (String parentTypeName : types) {

                    parentTypeName = parentTypeName.replaceAll("\\$", "\\.");
                    typesConverted.add(parentTypeName);
                }
                elementInfo.setTypes((String[]) typesConverted.toArray(new String[typesConverted.size()]));
            }

            elementInfo.setAnnotationRemover(ipe.isAnnotationRemover());
        }
        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.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());//from  w  w w . j a va2 s  .  com
        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

public String[] getQualifiedParameterTypes() {
    IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this)
            .javaElementToProgramElement(this);
    if (ipe != IHierarchy.NO_STRUCTURE) {
        return CoreUtils.listAJSigToJavaSig(ipe.getParameterSignatures());
    } else {//from   w w w .  ja  va2s . co m
        return getParameterTypes();
    }
}

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;
    }//w w  w .j  av 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.model.AJProjectModelFacade.java

License:Open Source License

/**
 * @param handle an AspectJ program element handle
 * @return a program element for the handle, or an empty element
 * if the program element is not found/*from   w  ww .j a  v  a2  s .  c  om*/
 */
public IProgramElement getProgramElement(String handle) {
    IProgramElement ipe = structureModel.findElementForHandleOrCreate(handle, false);
    if (ipe != null) {
        return ipe;
    } else {
        // occurs when the handles are not working properly
        //            AspectJPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, AspectJPlugin.PLUGIN_ID, 
        //                    "Could not find the AspectJ program element for handle: " + 
        //                    handle, new RuntimeException()));
        return IHierarchy.NO_STRUCTURE;
    }
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * @return a human readable name for the given Java element that is
 * meant to be displayed on menus and labels.
 *///w ww.ja va 2s. co  m
public String getJavaElementLinkName(IJavaElement je) {
    IProgramElement ipe = javaElementToProgramElement(je);
    if (ipe != IHierarchy.NO_STRUCTURE) { // null if model isn't initialized
        String name = ipe.toLinkLabelString(false);
        if ((name != null) && (name.length() > 0)) {
            return name;
        }
    }
    // use element name instead, qualified with parent
    String name = je.getElementName();
    if (je instanceof ISourceReference && !(je instanceof ITypeRoot)) {
        IJavaElement parent = je.getParent();
        while (parent != null && !(parent instanceof ITypeRoot)) {
            name = parent.getElementName() + "." + name;
            parent = parent.getParent();
        }
    }
    return name;
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * @return a program element that corresponds to the given java element.
 *//*from   w  ww .j a  v  a 2s  .  c  om*/
public IProgramElement javaElementToProgramElement(IJavaElement je) {
    if (!isInitialized) {
        return IHierarchy.NO_STRUCTURE;
    }
    String ajHandle = je.getHandleIdentifier();

    boolean isBinary = false;
    if (isBinaryHandle(ajHandle) || je.isReadOnly()) {
        ajHandle = convertToAspectJBinaryHandle(ajHandle, false);
        isBinary = true;
    } else if (isFromExternalProject(je)) {
        ajHandle = convertToAspectJBinaryHandle(ajHandle, true);
        isBinary = true;
    }

    // check to see if we need to replace { (compilation unit) with * (aj compilation unit)
    // if using cuprovider, then aj compilation units have {, but needs to change to *
    ICompilationUnit cu = null;
    if (je instanceof IMember) {
        cu = ((IMember) je).getCompilationUnit();
    } else if (je instanceof IPackageDeclaration) {
        IJavaElement parent = ((IPackageDeclaration) je).getParent();
        if (parent instanceof ICompilationUnit) {
            cu = (ICompilationUnit) parent;
        }
    } else if (je instanceof AJCodeElement) {
        cu = ((AJCodeElement) je).getCompilationUnit();
        // get the occurence count 
        int count = ((AJCodeElement) je).occurrenceCount;
        // need the first bang after the last close paren
        int lastParen = ajHandle.lastIndexOf(')');
        int firstBang = ajHandle.indexOf(JavaElement.JEM_COUNT, lastParen);
        if (firstBang > -1) {
            ajHandle = ajHandle.substring(0, firstBang);
            if (count > 1) {
                // there is more than one element
                // with this name
                ajHandle += "" + JavaElement.JEM_COUNT + count;
            }
        }

    } else if (je instanceof ILocalVariable) {
        IOpenable openable = ((ILocalVariable) je).getOpenable();
        cu = openable instanceof ICompilationUnit ? (ICompilationUnit) openable : null;
    } else if (je instanceof ImportDeclaration) {
        cu = ((ImportDeclaration) je).getCompilationUnit();
    } else if (je instanceof ImportContainer) {
        cu = ((ImportContainer) je).getCompilationUnit();
    } else if (je instanceof ICompilationUnit) {
        cu = (ICompilationUnit) je;
    }
    if (cu != null) {
        IResource resource = cu.getResource();
        if (resource != null && resource.exists()
                && CoreUtils.ASPECTJ_SOURCE_ONLY_FILTER.accept(resource.getName())) {
            ajHandle = ajHandle.replaceFirst("" + JavaElement.JEM_ESCAPE + JavaElement.JEM_COMPILATIONUNIT,
                    Character.toString(AspectElement.JEM_ASPECT_CU));
        }
    }

    IProgramElement ipe = structureModel.findElementForHandleOrCreate(ajHandle, false);
    if (ipe == null) {
        if (isBinary) {
            // might be an aspect in a class file.  JDT doesn't know it is an aspect
            // try looking for handle again, but use an Aspect token
            // problem will be if this is an aspect contained in a class or vice versa
            ajHandle = ajHandle.replace(JavaElement.JEM_TYPE, AspectElement.JEM_ASPECT_TYPE);
            ipe = structureModel.findElementForHandleOrCreate(ajHandle, false);
        }
        if (ipe == null) {
            // occurs when the handles are not working properly
            return IHierarchy.NO_STRUCTURE;
        }
    }
    return ipe;
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * This will return false in the cases where a java elt exists, but
 * a program elt does not.  This may happen when there are some kinds
 * of errors in the file that prevent the aspectj compiler from running, but
 * the Java compiler can still run.//from  w  w w  . ja  va  2 s  . c om
 * @param je
 * @return
 */
public boolean hasProgramElement(IJavaElement je) {
    return IHierarchy.NO_STRUCTURE != javaElementToProgramElement(je);
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * this type root exists in a jar file.  Try to find the 
 * java element specified in the handleInfo.  We are not going to be
 * able to convert this to source/* www.j  a  v  a2  s  .  c om*/
 */
private IJavaElement findElementInJar(HandleInfo handleInfo, IClassFile classFile) throws JavaModelException {
    IJavaElement candidate = classFile;

    if (handleInfo.isType && !handleInfo.isInAspect) {
        candidate = classFile.getType();
    } else if (!handleInfo.isFile) {
        String newHandle = classFile.getHandleIdentifier() + handleInfo.restHandle;
        IJavaElement newElt = AspectJCore.create(newHandle);
        IProgramElement ipe;
        if (!handleInfo.isFile && (!handleInfo.isType || handleInfo.isInAspect)) {
            // program element will exist only if coming from aspect path
            ipe = getProgramElement(handleInfo.origAJHandle);
        } else {
            ipe = IHierarchy.NO_STRUCTURE;
        }
        if (newElt instanceof AspectJMemberElement && ipe != IHierarchy.NO_STRUCTURE) {
            JavaModelManager.getJavaModelManager().resetTemporaryCache();
            AspectJMemberElement ajElt = (AspectJMemberElement) newElt;
            ajElt.setStartLocation(offsetFromLine(classFile, ipe.getSourceLocation()));
        }
        candidate = newElt;
    }
    return candidate;
}