Example usage for org.eclipse.jdt.internal.core JavaElement JEM_JAVAPROJECT

List of usage examples for org.eclipse.jdt.internal.core JavaElement JEM_JAVAPROJECT

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaElement JEM_JAVAPROJECT.

Prototype

char JEM_JAVAPROJECT

To view the source code for org.eclipse.jdt.internal.core JavaElement JEM_JAVAPROJECT.

Click Source Link

Usage

From source file:org.eclipse.ajdt.core.AJMementoTokenizer.java

License:Open Source License

public String nextToken() {
    int start = this.index;
    StringBuffer buffer = null;/*from  ww w. j av a  2  s.c om*/
    switch (this.memento[this.index++]) {
    case JavaElement.JEM_ESCAPE:
        buffer = new StringBuffer();
        buffer.append(this.memento[this.index]);
        start = ++this.index;
        break;
    case JavaElement.JEM_COUNT:
        return COUNT;
    case JavaElement.JEM_JAVAPROJECT:
        return JAVAPROJECT;
    case JavaElement.JEM_PACKAGEFRAGMENTROOT:
        return PACKAGEFRAGMENTROOT;
    case JavaElement.JEM_PACKAGEFRAGMENT:
        return PACKAGEFRAGMENT;
    case JavaElement.JEM_FIELD:
        return FIELD;
    case JavaElement.JEM_METHOD:
        return METHOD;
    case JavaElement.JEM_INITIALIZER:
        return INITIALIZER;
    case JavaElement.JEM_COMPILATIONUNIT:
        return COMPILATIONUNIT;
    case JavaElement.JEM_CLASSFILE:
        return CLASSFILE;
    case JavaElement.JEM_TYPE:
        return TYPE;
    case JavaElement.JEM_PACKAGEDECLARATION:
        return PACKAGEDECLARATION;
    case JavaElement.JEM_IMPORTDECLARATION:
        return IMPORTDECLARATION;
    case JavaElement.JEM_LOCALVARIABLE:
        return LOCALVARIABLE;
    case JavaElement.JEM_TYPE_PARAMETER:
        return TYPE_PARAMETER;
    case JavaElement.JEM_ANNOTATION:
        return ANNOTATION;
    // begin AspectJ change
    case AspectElement.JEM_ADVICE:
        return ADVICE;
    case AspectElement.JEM_ASPECT_TYPE:
        return ASPECT_TYPE;
    case AspectElement.JEM_CODEELEMENT:
        return CODEELEMENT;
    case AspectElement.JEM_ITD_METHOD:
        return ITD_METHOD;
    case AspectElement.JEM_ITD_FIELD:
        return ITD_FIELD;
    case AspectElement.JEM_DECLARE:
        return DECLARE;
    case AspectElement.JEM_POINTCUT:
        return POINTCUT;

    case AspectElement.JEM_ASPECT_CU:
        // only return here if JDT weaving is off
        // if JDT weaving is on, then a * here
        // means that we are in an on demand import declaration
        if (!AspectJPlugin.USING_CU_PROVIDER) {
            return ASPECT_CU;
        }
        // end AspectJ change
    }
    loop: while (this.index < this.length) {
        switch (this.memento[this.index]) {
        case JavaElement.JEM_ESCAPE:
            if (buffer == null)
                buffer = new StringBuffer();
            buffer.append(this.memento, start, this.index - start);
            start = ++this.index;
            break;
        case JavaElement.JEM_COUNT:
        case JavaElement.JEM_JAVAPROJECT:
        case JavaElement.JEM_PACKAGEFRAGMENTROOT:
        case JavaElement.JEM_PACKAGEFRAGMENT:
        case JavaElement.JEM_FIELD:
        case JavaElement.JEM_METHOD:
        case JavaElement.JEM_INITIALIZER:
        case JavaElement.JEM_COMPILATIONUNIT:
        case JavaElement.JEM_CLASSFILE:
        case JavaElement.JEM_TYPE:
        case JavaElement.JEM_PACKAGEDECLARATION:
        case JavaElement.JEM_IMPORTDECLARATION:
        case JavaElement.JEM_LOCALVARIABLE:
        case JavaElement.JEM_TYPE_PARAMETER:
        case JavaElement.JEM_ANNOTATION:
            // begin AspectJ change
        case AspectElement.JEM_ADVICE:
        case AspectElement.JEM_ASPECT_TYPE:
        case AspectElement.JEM_CODEELEMENT:
        case AspectElement.JEM_ITD_METHOD:
        case AspectElement.JEM_ITD_FIELD:
        case AspectElement.JEM_DECLARE:
        case AspectElement.JEM_POINTCUT:
            break loop;
        // end AspectJ change

        // begin AspectJ change
        case AspectElement.JEM_ASPECT_CU:
            // only break here if JDT weaving is off
            // if JDT weaving is on, then a * here
            // means that we are in an on demand import declaration
            if (!AspectJPlugin.USING_CU_PROVIDER) {
                break loop;
            }
            // end AspectJ change
        }
        this.index++;
    }
    if (buffer != null) {
        buffer.append(this.memento, start, this.index - start);
        return buffer.toString();
    }
    return new String(this.memento, start, this.index - start);
}

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

License:Open Source License

private String convertToAspectJBinaryHandle(String ajHandle, boolean isSourceFromDependingProject) {
    int packageIndex = ajHandle.indexOf(JavaElement.JEM_PACKAGEFRAGMENT);
    String newHandle = "" + JavaElement.JEM_JAVAPROJECT + project.getName()
            + JavaElement.JEM_PACKAGEFRAGMENTROOT + "binaries" + ajHandle.substring(packageIndex);

    if (isSourceFromDependingProject) {
        // also must convert from a source unit to a binary unit
        newHandle = newHandle.replace(".aj'", ".class'");
        if (AspectJPlugin.USING_CU_PROVIDER) {
            newHandle = newHandle.replace(JavaElement.JEM_COMPILATIONUNIT, JavaElement.JEM_CLASSFILE);
        } else {//from  w ww  .j  av a 2  s .  c o  m
            newHandle = newHandle.replace(AspectElement.JEM_ASPECT_CU, JavaElement.JEM_CLASSFILE);
        }
    }

    return newHandle;
}

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

License:Open Source License

public IJavaElement programElementToJavaElement(String ajHandle) {
    // check to see if this is a spurious handle. 
    // For ITDs, the aspectj compiler generates program elements before the
    // rest of the program is in place, and they therfore have no parent.
    // They should not exist and we can ignore them.
    if (ajHandle.length() == 0 || ajHandle.charAt(0) != JavaElement.JEM_JAVAPROJECT) {
        return ERROR_JAVA_ELEMENT;
    }/*from  www  .  j  a v  a 2  s .c  o  m*/

    String jHandle = ajHandle;

    // are we dealing with something inside of a classfile?
    // if so, then we have to handle it specially
    // because we want to convert this into a source reference if possible
    if (isBinaryAspectJHandle(jHandle)) {
        // Bug 274558 ADE HACK...fix aspect handles that are supposed to be binary, but are not.
        jHandle = jHandle.replace(AspectElement.JEM_ASPECT_CU, JavaElement.JEM_CLASSFILE);
        jHandle = jHandle.replace(".aj" + JEM_ASPECT_TYPE, ".class" + JEM_ASPECT_TYPE);
        return getElementFromClassFile(jHandle);
    }

    // if using cuprovider, then we don not use the '*' for Aspect compilation units,
    // it uses the '{' of Java Compilation Units
    if (AspectJPlugin.USING_CU_PROVIDER) {
        jHandle = jHandle.replaceFirst("" + JavaElement.JEM_ESCAPE + AspectElement.JEM_ASPECT_CU,
                Character.toString(JavaElement.JEM_COMPILATIONUNIT));
    }

    int codeEltIndex = jHandle.indexOf(AspectElement.JEM_CODEELEMENT);
    if (codeEltIndex != -1) {
        // because code elements are sub classes of local variables
        // must make the code element's handle look like a local
        // variable's handle
        int countIndex = jHandle.lastIndexOf(JavaElement.JEM_COUNT);
        int count = 0;
        if (countIndex > codeEltIndex) {
            try {
                count = Integer.parseInt(jHandle.substring(countIndex + 1));
                jHandle = jHandle.substring(0, countIndex);
            } catch (NumberFormatException e) {
                // if the count is not from the code element, but from one of its parents
                count = 0;
            }
        }
        jHandle += "!0!0!0!0!I!0!false";
        if (count > 1) {
            jHandle += "" + JavaElement.JEM_COUNT + count;
        }
    }

    // add escapes to various sundries
    jHandle = jHandle.replaceFirst("declare @", "declare \\\\@"); // declare declarations
    jHandle = jHandle.replaceFirst("\\.\\*", ".\\\\*"); // on demand imports
    jHandle = jHandle.replaceAll("\\*>", "\\\\*>"); // wild card type parameters

    IJavaElement je = AspectJCore.create(jHandle);
    if (je == null) {
        // occurs when the handles are not working properly
        return ERROR_JAVA_ELEMENT;
    }
    return je;
}