List of usage examples for org.eclipse.jdt.internal.core JavaElement JEM_CLASSFILE
char JEM_CLASSFILE
To view the source code for org.eclipse.jdt.internal.core JavaElement JEM_CLASSFILE.
Click Source Link
From source file:de.tobject.findbugs.reporter.MarkerUtil.java
License:Open Source License
/** * * @param parentId/* w ww. java2 s .co m*/ * java element id of a parent element * @param childId * java element id of possible child * @return true if the second string represents a java element which is a * direct child of the parent element. */ @SuppressWarnings("restriction") private static boolean isDirectChild(String parentId, String childId) { return childId.startsWith(parentId) && (childId.length() > (parentId.length() + 1)) // if there is NOT a class file separator, then it's not a direct child && childId.charAt(parentId.length()) == JavaElement.JEM_CLASSFILE; }
From source file:org.eclipse.ajdt.core.AJMementoTokenizer.java
License:Open Source License
public String nextToken() { int start = this.index; StringBuffer buffer = null;/*w w w. j av a2 s.c o 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 www.j a va 2s . com*/ 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.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 www.ja va 2 s . co 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
private boolean isBinaryHandle(String ajHandle) { int jemClassIndex = ajHandle.indexOf(JavaElement.JEM_CLASSFILE); if (jemClassIndex != -1) { int classFileIndex = ajHandle.indexOf(".class", jemClassIndex); if (classFileIndex != -1) { return true; }//w ww .java2 s . co m } return false; }
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; }/* w w w . j ava 2s .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.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 w w .ja va2 s.co 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); }/* w w w . ja v a 2s. 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); }