List of usage examples for org.eclipse.jdt.internal.core JavaElement JEM_TYPE
char JEM_TYPE
To view the source code for org.eclipse.jdt.internal.core JavaElement JEM_TYPE.
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 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.AspectJCore.java
License:Open Source License
public static IJavaElement create(String handleIdentifier, WorkingCopyOwner owner) { if (handleIdentifier == null) { return null; }/*from www . j a v a 2 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 ww w .j a v a 2s.co m * * 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.javaelements.AJCompilationUnit.java
License:Open Source License
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) { JavaElement type = this; if (!(memento instanceof AJMementoTokenizer)) { memento = new AJMementoTokenizer(memento, name); }/*from w w w. j a v a 2s . c om*/ if ((token.charAt(0) == JavaElement.JEM_IMPORTDECLARATION) || (token.charAt(0) == JavaElement.JEM_PACKAGEDECLARATION)) { return super.getHandleFromMemento(token, memento, workingCopyOwner); } // need to handle types ourselves, because they may contain inner aspects // (or inner classes containing inner aspects etc) while ((token.charAt(0) == AspectElement.JEM_ASPECT_TYPE) || (token.charAt(0) == JavaElement.JEM_TYPE) || (token.charAt(0) == JavaElement.JEM_ANNOTATION)) { // note that we are also testing for JEM_ANNOTATION here. // this is because when the type handle identifiers were changed prior to 2.1.1, // JEM_ASPECT_TYPE and JEM_ANNOTATION were the same. // Some people have had problems in that the old handles were cached. // this can probably be safely removed post 2.1.2. if (!memento.hasMoreTokens()) return type; String typeName = memento.nextToken(); if (token.charAt(0) == AspectElement.JEM_ASPECT_TYPE || token.charAt(0) == JavaElement.JEM_ANNOTATION) { type = new AspectElement(type, typeName); } else if (token.charAt(0) == JavaElement.JEM_TYPE) { type = getType(type, typeName); if (type == null) type = (JavaElement) getType(typeName); } if (!memento.hasMoreTokens()) return type; token = memento.nextToken(); } // handle pointcuts in a class (bug 124992) if (!(type instanceof AspectElement) && (token.charAt(0) == AspectElement.JEM_POINTCUT)) { String name = memento.nextToken(); ArrayList params = new ArrayList(); nextParam: while (memento.hasMoreTokens()) { token = memento.nextToken(); switch (token.charAt(0)) { case JEM_TYPE: case JEM_TYPE_PARAMETER: break nextParam; case AspectElement.JEM_POINTCUT: if (!memento.hasMoreTokens()) return this; String param = memento.nextToken(); StringBuffer buffer = new StringBuffer(); while (param.length() == 1 && Signature.C_ARRAY == param.charAt(0)) { // backward compatible with 3.0 mementos buffer.append(Signature.C_ARRAY); if (!memento.hasMoreTokens()) return this; param = memento.nextToken(); } params.add(buffer.toString() + param); break; default: break nextParam; } } String[] parameters = new String[params.size()]; params.toArray(parameters); JavaElement pointcut = new PointcutElement(type, name, parameters); return pointcut.getHandleFromMemento(memento, workingCopyOwner); } return type.getHandleFromMemento(token, memento, workingCopyOwner); }
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. *//* w ww .j a v a 2 s . 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
private boolean isBinaryAspectJHandle(String ajHandle) { int classFileIndex = ajHandle.indexOf(JavaElement.JEM_CLASSFILE); boolean doIt = false; if (classFileIndex != -1) { int dotClassIndex = ajHandle.indexOf(".class") + ".class".length(); if (dotClassIndex >= ajHandle.length()) { // handle is for the class itself. doIt = true;/*from w ww . j a v a 2s .c o m*/ } else if (dotClassIndex != -1) { // make sure this isn't a code element char typeChar = ajHandle.charAt(dotClassIndex); doIt = (typeChar == AspectElement.JEM_ASPECT_TYPE || typeChar == JavaElement.JEM_TYPE || typeChar == JavaElement.JEM_IMPORTDECLARATION || typeChar == JavaElement.JEM_PACKAGEDECLARATION); } } else { // Bug 274558 ADE HACK...handles are not always right for aspects on aspect path // sometimes the source handle is used, bug should be binary handle if (ajHandle.indexOf("/binaries<") != -1) { doIt = true; } } return doIt; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
private HandleInfo qualifiedNameFromBinaryHandle(String ajHandle) { int packageStart = ajHandle.indexOf(JavaElement.JEM_PACKAGEFRAGMENT); int packageEnd = ajHandle.indexOf(JavaElement.JEM_CLASSFILE, packageStart + 1); if (packageEnd < 0) { // this is a package fragment String packageName = ajHandle.substring(packageStart + 1); return new HandleInfo(ajHandle, "", packageName, "", "", false, false, false); }/*from w w w . ja v a 2 s. c o m*/ int typeNameEnd = ajHandle.indexOf(".class", packageEnd + 1); if (typeNameEnd < 0) { return null; } StringBuffer sb = new StringBuffer(); String packageName = ajHandle.substring(packageStart + 1, packageEnd); sb.append(packageName); if (sb.length() > 0) { sb.append("."); } String simpleName = ajHandle.substring(packageEnd + 1, typeNameEnd); sb.append(simpleName); int aspectStart = ajHandle.indexOf(AspectElement.JEM_ASPECT_TYPE, typeNameEnd); int classStart = ajHandle.indexOf(JavaElement.JEM_TYPE, typeNameEnd); int typeStart = classStart == -1 ? aspectStart : aspectStart == -1 ? classStart : Math.min(classStart, aspectStart); boolean isFile = typeStart == -1; boolean isType; if (!isFile) { isType = typeStart + simpleName.length() + 1 == ajHandle.length(); } else { isType = false; } boolean isInAspect = aspectStart >= 0; String restHandle = typeStart >= 0 ? ajHandle.substring(typeStart) : ""; return new HandleInfo(ajHandle, simpleName, packageName, sb.toString(), restHandle, isFile, isType, isInAspect); }