List of usage examples for org.eclipse.jdt.internal.core JavaElement JEM_COMPILATIONUNIT
char JEM_COMPILATIONUNIT
To view the source code for org.eclipse.jdt.internal.core JavaElement JEM_COMPILATIONUNIT.
Click Source Link
From source file:org.eclipse.ajdt.core.AJMementoTokenizer.java
License:Open Source License
public String nextToken() { int start = this.index; StringBuffer buffer = null;//from w ww .ja v a2s . co m 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.AspectJCore.java
License:Open Source License
public static IJavaElement create(String handleIdentifier, WorkingCopyOwner owner) { if (handleIdentifier == null) { return null; }//from w ww . ja v a2 s.c o m Map aspectsInJavaFiles = new HashMap(); boolean isCodeElement = false; String codeElementHandle = ""; //$NON-NLS-1$ int codeElementDelimPos = indexOfIgnoringEscapes(handleIdentifier, AspectElement.JEM_CODEELEMENT); if (codeElementDelimPos != -1) { isCodeElement = true; codeElementHandle = handleIdentifier.substring(codeElementDelimPos + 1); handleIdentifier = handleIdentifier.substring(0, codeElementDelimPos); } AJMementoTokenizer memento = new AJMementoTokenizer(handleIdentifier); while (memento.hasMoreTokens()) { String token = memento.nextToken(); if ((token.charAt(0) == AspectElement.JEM_ASPECT_CU) || (token.charAt(0) == JavaElement.JEM_COMPILATIONUNIT) || (token.charAt(0) == JavaElement.JEM_CLASSFILE)) { int index; if (token.charAt(0) == AspectElement.JEM_ASPECT_CU) { index = handleIdentifier.indexOf(AspectElement.JEM_ASPECT_CU); } else if (token.charAt(0) == JavaElement.JEM_COMPILATIONUNIT) { index = handleIdentifier.indexOf(JavaElement.JEM_COMPILATIONUNIT); } else { // JEM_CLASSFILE index = handleIdentifier.indexOf(JavaElement.JEM_CLASSFILE); } if (index != -1) { IJavaElement je = JavaCore.create(handleIdentifier.substring(0, index)); if (je instanceof PackageFragment) { PackageFragment pf = (PackageFragment) je; String cuName = handleIdentifier.substring(index + 1); int ind1 = cuName.indexOf(JavaElement.JEM_TYPE); if (ind1 != -1) { cuName = cuName.substring(0, ind1); } int ind2 = cuName.indexOf(AspectElement.JEM_ASPECT_TYPE); if (ind2 != -1) { cuName = cuName.substring(0, ind2); } int ind3 = cuName.indexOf(AspectElement.JEM_ITD_METHOD); if (ind3 != -1) { cuName = cuName.substring(0, ind3); } ind3 = cuName.indexOf(AspectElement.JEM_ITD_FIELD); if (ind3 != -1) { cuName = cuName.substring(0, ind3); } int ind4 = cuName.indexOf(AspectElement.JEM_DECLARE); if (ind4 != -1) { cuName = cuName.substring(0, ind4); } int ind5 = cuName.indexOf(AspectElement.JEM_IMPORTDECLARATION); if (ind5 != -1) { cuName = cuName.substring(0, ind5); } int ind6 = cuName.indexOf(AspectElement.JEM_PACKAGEDECLARATION); if (ind6 != -1) { cuName = cuName.substring(0, ind6); } if (CoreUtils.ASPECTJ_SOURCE_ONLY_FILTER.accept(cuName)) { // no need to use a cuprovider because we know this // is an AJCompilationUnit JavaElement cu = new AJCompilationUnit(pf, cuName, owner); token = memento.nextToken(); if (!memento.hasMoreTokens()) { return cu; } IJavaElement restEl = cu.getHandleFromMemento(memento.nextToken(), memento, owner); if (restEl != null) { if (isCodeElement) { // there was an AJCodeElement at the end of // the handle IJavaElement codeEl = getCodeElement(codeElementHandle, (JavaElement) restEl); if (codeEl != null) { return codeEl; } } return restEl; } } else { // Use the default working copy owner for Java elements IJavaElement restEl = pf.getHandleFromMemento(token, memento, DefaultWorkingCopyOwner.PRIMARY); if (restEl != null) { if (isCodeElement) { // there was an AJCodeElement at the end of // the handle IJavaElement codeEl = getCodeElement(codeElementHandle, (JavaElement) restEl); if (codeEl != null) { return codeEl; } } return restEl; } else if (ind2 != -1) { // An aspect in a .java file... int index3 = handleIdentifier.indexOf(AspectElement.JEM_ASPECT_TYPE); String aspectName = handleIdentifier.substring(index3 + 1); boolean identifierIsAspect = true; int ind7 = aspectName.indexOf(AspectElement.JEM_DECLARE); if (ind7 != -1) { aspectName = aspectName.substring(0, ind7); identifierIsAspect = false; } int ind8 = aspectName.indexOf(AspectElement.JEM_ADVICE); if (ind8 != -1) { aspectName = aspectName.substring(0, ind8); identifierIsAspect = false; } int ind9 = aspectName.indexOf(AspectElement.JEM_ITD_METHOD); if (ind9 != -1) { aspectName = aspectName.substring(0, ind9); identifierIsAspect = false; } ind9 = aspectName.indexOf(AspectElement.JEM_ITD_FIELD); if (ind9 != -1) { aspectName = aspectName.substring(0, ind9); identifierIsAspect = false; } int ind10 = aspectName.indexOf(AspectElement.JEM_ASPECT_TYPE); if (ind10 != -1) { aspectName = aspectName.substring(0, ind10); identifierIsAspect = false; } int ind11 = aspectName.indexOf(AspectElement.JEM_TYPE); if (ind11 != -1) { aspectName = aspectName.substring(0, ind11); identifierIsAspect = false; } int ind12 = aspectName.indexOf(AspectElement.JEM_FIELD); if (ind12 != -1) { aspectName = aspectName.substring(0, ind12); identifierIsAspect = false; } int ind13 = aspectName.indexOf(AspectElement.JEM_METHOD); if (ind13 != -1) { aspectName = aspectName.substring(0, ind13); identifierIsAspect = false; } int ind14 = aspectName.indexOf(AspectElement.JEM_POINTCUT); if (ind14 != -1) { aspectName = aspectName.substring(0, ind14); identifierIsAspect = false; } IOpenable openable; if (cuName.endsWith(".class")) { openable = pf.getClassFile(cuName); } else { openable = pf.getCompilationUnit(cuName); } List l; if (aspectsInJavaFiles.get(openable) instanceof List) { l = (List) aspectsInJavaFiles.get(openable); } else { l = new ArrayList(); aspectsInJavaFiles.put(openable, l); } JavaElement aspectEl = null; for (Iterator iter = l.iterator(); iter.hasNext();) { AspectElement element = (AspectElement) iter.next(); if (element.getElementName().equals(aspectName)) { aspectEl = element; } } if (aspectEl == null) { if (openable instanceof ClassFile) { ClassFile cOpenable = (ClassFile) openable; aspectEl = new BinaryAspectElement((JavaElement) cOpenable, aspectName); } else { aspectEl = new AspectElement((JavaElement) openable, aspectName); } l.add(aspectEl); } int afterAspectIndex = index3 + aspectName.length() + 1; if (identifierIsAspect) { return aspectEl; } else { memento.setIndexTo(afterAspectIndex); return aspectEl.getHandleFromMemento(memento.nextToken(), memento, owner); } } } } } } } // XXX can we get here??? if (isCodeElement) { // an injar aspect with no parent return new AJInjarElement(codeElementHandle); } return JavaCore.create(handleIdentifier); }
From source file:org.eclipse.ajdt.core.AspectJCore.java
License:Open Source License
/** * Converts a handle signifying Java class to a handle signifying an * aspect element./*from w ww .j a v a2 s . c om*/ * * This method is necessary because JavaCore does not create * AspectElements when it is building structure using the {@link AspectsConvertingParser} * * Note that this changes the top level class to being an aspect and keeps * all others the same. This may not work in all situations (eg- an inner aspect) * * @param classHandle * @return converts the handle to using {@link AspectElement#JEM_ASPECT_CU} and * {@link AspectElement#JEM_ASPECT_TYPE} */ public static String convertToAspectHandle(String classHandle, IJavaElement elt) { String aspectHandle = classHandle.replaceFirst("\\" + Character.toString(JavaElement.JEM_TYPE), Character.toString(AspectElement.JEM_ASPECT_TYPE)); if (CoreUtils.ASPECTJ_SOURCE_ONLY_FILTER.accept(elt.getResource().getName())) { aspectHandle = aspectHandle.replace(JavaElement.JEM_COMPILATIONUNIT, AspectElement.JEM_ASPECT_CU); } return aspectHandle; }
From source file:org.eclipse.ajdt.core.AspectJCore.java
License:Open Source License
public static String convertToJavaCUHandle(String aspectHandle, IJavaElement elt) { String javaHandle = aspectHandle; if (elt != null) { IResource resource = elt.getResource(); if (resource != null) { if (CoreUtils.ASPECTJ_SOURCE_ONLY_FILTER.accept(resource.getName())) { javaHandle = javaHandle.replaceFirst("\\" + AspectElement.JEM_ASPECT_CU, Character.toString(JavaElement.JEM_COMPILATIONUNIT)); }//from ww w. j a v a 2s . c o m } } return javaHandle; }
From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java
License:Open Source License
public String getHandleIdentifier() { if (AspectJPlugin.USING_CU_PROVIDER) { return super.getHandleIdentifier(); }//from www . ja v a2s .com // this horrid code only exists so that when we are not using the weaving service, // we don't get exceptions on refactoring String callerName = (new RuntimeException()).getStackTrace()[1].getClassName(); final String deletionClass = "org.eclipse.jdt.internal.corext.refactoring.changes.DeleteSourceManipulationChange"; //$NON-NLS-1$ // are we being called in the context of a delete operation? if (callerName.equals(deletionClass)) { AJCompilationUnitManager.INSTANCE.removeFileFromModel((IFile) getResource()); // need to return a handle identifier that JDT can use (bug 74426) String handleIdentifier = JavaCore.create(ajFile).getHandleIdentifier(); ajFile = null; return handleIdentifier; } // are we being called in the context of a move/DnD operation? final String moveClass = "org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitReorgChange"; //$NON-NLS-1$ if (callerName.equals(moveClass)) { // need to return a handle identifier that JDT can use (bug 121533) String modifiedHandle = super.getHandleIdentifier().replace(AspectElement.JEM_ASPECT_CU, JavaElement.JEM_COMPILATIONUNIT); return modifiedHandle; } return super.getHandleIdentifier(); }
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 ww w . ja v a 2s . c o m*/ 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
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 w w. j a v a 2s . com*/ 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 w w w. j a v a2 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; }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
/** * @see JavaElement#getHandleMementoDelimiter() */ protected char getHandleMementoDelimiter() { return JavaElement.JEM_COMPILATIONUNIT; }