List of usage examples for org.aspectj.org.eclipse.jdt.core.dom AjASTVisitor AjASTVisitor
public AjASTVisitor()
From source file:org.eclipse.ajdt.core.codeconversion.AJSourceIndexerRequestor.java
License:Open Source License
/** * Here, we must index special AJ declarations like ITDs and declare parents/annotations *//*from w w w. j a v a 2 s.c om*/ @Override public void enterField(FieldInfo fieldInfo) { super.enterField(fieldInfo); try { char[] fieldName = fieldInfo.name; char[] fieldType = fieldInfo.type; int last = CharOperation.lastIndexOf('$', fieldName) + 1; if (maybeDeclare(fieldName, fieldType)) { try { char[] contents = getContents(); BodyDeclaration node = PointcutUtilities.createSingleBodyDeclarationNode( fieldInfo.declarationStart, fieldInfo.node.sourceEnd, contents); if (node instanceof DeclareParentsDeclaration) { // found it! DeclareParentsDeclaration declare = (DeclareParentsDeclaration) node; // Visit the children AjASTVisitor typePatternVisitor = new AjASTVisitor() { protected void index(String tokenString) { char[][] tokens = tokenize(tokenString); for (char[] token : tokens) { // must accept an uknown reference since we don't really know if this is a type, method, or field reference // source position is wrong, but this is ok. AJSourceIndexerRequestor.super.acceptUnknownReference(token, 0); } // AJSourceIndexerRequestor.super // .acceptAnnotationTypeReference(tokens, // node.getStartPosition(), // node.getStartPosition() + node.getLength()); } public boolean visit(IdentifierTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(AnyWithAnnotationTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(TypeCategoryTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(SignaturePattern node) { index(node.getDetail()); return true; } //TODO: Add more as needed. Extract visitor to file if too large }; declare.accept(typePatternVisitor); } else if (node instanceof DeclareAnnotationDeclaration) { // found it! DeclareAnnotationDeclaration declare = (DeclareAnnotationDeclaration) node; SimpleName annotationName = declare.getAnnotationName(); // index the annotation name if (annotationName != null) { String annotationStr = annotationName.toString(); if (annotationStr.startsWith("@")) { annotationStr = annotationStr.substring(1, annotationStr.length()); } char[][] splitChars = CharOperation.splitOn('.', annotationStr.toCharArray()); super.acceptTypeReference(splitChars, annotationName.getStartPosition(), annotationName.getStartPosition() + annotationName.getLength()); } PatternNode targetPattern = declare.getPatternNode(); if (targetPattern instanceof IdentifierTypePattern) { String detail = ((IdentifierTypePattern) targetPattern).getTypePatternExpression(); char[][] tokens = detail != null ? CharOperation.splitOn('.', detail.toCharArray()) : null; super.acceptTypeReference(tokens, targetPattern.getStartPosition(), targetPattern.getStartPosition() + targetPattern.getLength()); } else if (targetPattern instanceof SignaturePattern) { char[][] tokens = tokenize(((SignaturePattern) targetPattern).getDetail()); for (char[] token : tokens) { // must accept an uknown reference since we don't really know if this is a type, method, or field reference // source position is wrong, but this is ok. super.acceptUnknownReference(token, targetPattern.getStartPosition()); } } } } catch (Exception e) { // lots of things can go wrong, so surround in a big try-catch block and log to the console } } else if (maybeITD(fieldName, last)) { // assume this is an itd char[][] splits = CharOperation.splitAndTrimOn('$', fieldName); // should be array of length 2 at least. Last element is the realMethodName // one before that is the simple name of the type // if more than length 2, then the rest are package names int length = splits.length; this.indexer.addFieldDeclaration(fieldInfo.type, splits[splits.length - 1]); if (length > 1) { // remove the last segment char[][] newSplits = new char[splits.length - 1][]; System.arraycopy(splits, 0, newSplits, 0, splits.length - 1); super.acceptUnknownReference(newSplits, fieldInfo.nameSourceStart, fieldInfo.nameSourceEnd - splits[length - 1].length - 1); } } } catch (Exception e) { } }