List of usage examples for org.eclipse.jdt.internal.core JavaElement JEM_ESCAPE
char JEM_ESCAPE
To view the source code for org.eclipse.jdt.internal.core JavaElement JEM_ESCAPE.
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 w w .j a v a 2 s . 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
private static int indexOfIgnoringEscapes(String str, char ch) { boolean prevEscape = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == JavaElement.JEM_ESCAPE) { prevEscape = true;// ww w.j a v a2 s . c o m } else { if ((c == ch) && (!prevEscape)) { return i; } prevEscape = false; } } return -1; }
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 w w . java 2s.co 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
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 ww w . j ava 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; }