From 6d31507785b6803062e46d071ff969160b979b5a Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 26 Jan 2006 10:57:12 +0000 Subject: [PATCH] necessary magic. Factory 'mechanism' used so that the JDT project doesnt have a direct dependency on the ajdt.core project. It references the factory name through a string and dynamically loads the type. --- .../eclipse/jdt/core/dom/AjASTConverter.java | 129 +++++++++++++++++- .../eclipse/jdt/core/dom/AjASTFactory.java | 21 +++ .../eclipse/jdt/core/dom/AjASTMatcher.java | 7 + .../eclipse/jdt/core/dom/AjASTVisitor.java | 85 +++++++++++- 4 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java index 1e569ce2b..d7e1a7124 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java @@ -14,6 +14,7 @@ package org.aspectj.org.eclipse.jdt.core.dom; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration; @@ -50,6 +51,15 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Scanner; import org.aspectj.org.eclipse.jdt.internal.compiler.parser.TerminalTokens; import org.aspectj.weaver.AdviceKind; +import org.aspectj.weaver.patterns.Declare; +import org.aspectj.weaver.patterns.DeclareAnnotation; +import org.aspectj.weaver.patterns.DeclareErrorOrWarning; +import org.aspectj.weaver.patterns.DeclareParents; +import org.aspectj.weaver.patterns.DeclarePrecedence; +import org.aspectj.weaver.patterns.DeclareSoft; +import org.aspectj.weaver.patterns.PatternNode; +import org.aspectj.weaver.patterns.SignaturePattern; +import org.aspectj.weaver.patterns.TypePattern; import org.eclipse.core.runtime.IProgressMonitor; /** @@ -377,11 +387,107 @@ public class AjASTConverter extends ASTConverter { public ASTNode convert(DeclareDeclaration declareDecl) { - // ajh02: method added - checkCanceled(); // ajh02: is this line needed? - final org.aspectj.org.eclipse.jdt.core.dom.DeclareDeclaration declareDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.DeclareDeclaration(this.ast,declareDecl.declareDecl); + checkCanceled(); // is this line needed? + org.aspectj.org.eclipse.jdt.core.dom.DeclareDeclaration declareDeclaration = null; + Declare declare = declareDecl.declareDecl; + if (declare instanceof DeclareAnnotation) { + DeclareAnnotation da = (DeclareAnnotation)declare; + if (da.getKind().equals(DeclareAnnotation.AT_TYPE)) { + declareDeclaration = new DeclareAtTypeDeclaration(this.ast); + ((DeclareAtTypeDeclaration)declareDeclaration).setPatternNode(convert(da.getTypePattern())); + SimpleName annotationName = new SimpleName(this.ast); + annotationName.internalSetIdentifier(new String(da.getAnnotationString())); + ((DeclareAtTypeDeclaration)declareDeclaration).setAnnotationName(annotationName); + } else if (da.getKind().equals(DeclareAnnotation.AT_CONSTRUCTOR)) { + declareDeclaration = new DeclareAtConstructorDeclaration(this.ast); + ((DeclareAtConstructorDeclaration)declareDeclaration).setPatternNode(convert(da.getSignaturePattern())); + SimpleName annotationName = new SimpleName(this.ast); + annotationName.internalSetIdentifier(new String(da.getAnnotationString())); + ((DeclareAtConstructorDeclaration)declareDeclaration).setAnnotationName(annotationName); + } else if (da.getKind().equals(DeclareAnnotation.AT_FIELD)) { + declareDeclaration = new DeclareAtFieldDeclaration(this.ast); + ((DeclareAtFieldDeclaration)declareDeclaration).setPatternNode(convert(da.getSignaturePattern())); + SimpleName annotationName = new SimpleName(this.ast); + annotationName.internalSetIdentifier(new String(da.getAnnotationString())); + ((DeclareAtFieldDeclaration)declareDeclaration).setAnnotationName(annotationName); + } else if (da.getKind().equals(DeclareAnnotation.AT_METHOD)) { + declareDeclaration = new DeclareAtMethodDeclaration(this.ast); + ((DeclareAtMethodDeclaration)declareDeclaration).setPatternNode(convert(da.getSignaturePattern())); + SimpleName annotationName = new SimpleName(this.ast); + annotationName.internalSetIdentifier(new String(da.getAnnotationString())); + ((DeclareAtMethodDeclaration)declareDeclaration).setAnnotationName(annotationName); + } + } else if (declare instanceof DeclareErrorOrWarning){ + DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare; + if (deow.isError()) { + declareDeclaration = new DeclareErrorDeclaration(this.ast); + ((DeclareErrorDeclaration)declareDeclaration).setPointcut(convert(deow.getPointcut())); + StringLiteral message = new StringLiteral(this.ast); + message.setEscapedValue(updateString(deow.getMessage())); + ((DeclareErrorDeclaration)declareDeclaration).setMessage(message); + } else { + declareDeclaration = new DeclareWarningDeclaration(this.ast); + ((DeclareWarningDeclaration)declareDeclaration).setPointcut(convert(deow.getPointcut())); + StringLiteral message = new StringLiteral(this.ast); + message.setEscapedValue(updateString(deow.getMessage())); + ((DeclareWarningDeclaration)declareDeclaration).setMessage(message); + } + } else if (declare instanceof DeclareParents) { + DeclareParents dp = (DeclareParents)declare; + declareDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.DeclareParentsDeclaration(this.ast,dp.isExtends()); + org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = convert(dp.getChild()); + if (pNode instanceof org.aspectj.org.eclipse.jdt.core.dom.TypePattern) { + ((DeclareParentsDeclaration)declareDeclaration).setChildTypePattern((org.aspectj.org.eclipse.jdt.core.dom.TypePattern)pNode); + } + TypePattern[] weaverTypePatterns = dp.getParents().getTypePatterns(); + List typePatterns = ((DeclareParentsDeclaration)declareDeclaration).parentTypePatterns(); + for (int i = 0; i < weaverTypePatterns.length; i++) { + typePatterns.add(convert(weaverTypePatterns[i])); + } + } else if (declare instanceof DeclarePrecedence) { + declareDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.DeclarePrecedenceDeclaration(this.ast); + DeclarePrecedence dp = (DeclarePrecedence)declare; + TypePattern[] weaverTypePatterns = dp.getPatterns().getTypePatterns(); + List typePatterns = ((DeclarePrecedenceDeclaration)declareDeclaration).typePatterns(); + for (int i = 0; i < weaverTypePatterns.length; i++) { + typePatterns.add(convert(weaverTypePatterns[i])); + } + } else if (declare instanceof DeclareSoft) { + declareDeclaration = new DeclareSoftDeclaration(this.ast); + DeclareSoft ds = (DeclareSoft)declare; + ((DeclareSoftDeclaration)declareDeclaration).setPointcut(convert(ds.getPointcut())); + org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = convert(ds.getException()); + if (pNode instanceof org.aspectj.org.eclipse.jdt.core.dom.TypePattern) { + ((DeclareSoftDeclaration)declareDeclaration).setTypePattern((org.aspectj.org.eclipse.jdt.core.dom.TypePattern)pNode); + } + } + declareDeclaration.setSourceRange(declareDecl.declarationSourceStart, + declareDecl.declarationSourceEnd - declareDecl.declarationSourceStart + 1); return declareDeclaration; } + + private String updateString(String message) { + StringBuffer sb = new StringBuffer(message); + int nextQuote = sb.toString().indexOf("\""); + while (nextQuote != -1) { + sb.insert(nextQuote,"\\"); + nextQuote = sb.toString().indexOf("\""); + } + int nextNewLine = sb.toString().indexOf("\n"); + while (nextNewLine != -1) { + sb.insert(nextNewLine,"\\"); + nextNewLine = sb.toString().indexOf("\n"); + } + if(!sb.toString().startsWith("\"")) { + sb.insert(0,"\""); + } + if(!sb.toString().endsWith("\"")) { + sb.insert(sb.toString().length(),"\""); + } + return sb.toString(); + } + + public ASTNode convert(InterTypeFieldDeclaration fieldDecl) { // ajh02: method added checkCanceled(); // ajh02: is this line needed? @@ -480,6 +586,23 @@ public class AjASTConverter extends ASTConverter { return pointcutDesi; } + public org.aspectj.org.eclipse.jdt.core.dom.PatternNode convert(PatternNode patternNode){ + // this is a stub to be used until dom classes have been created for + // the different weaver TypePattern's + org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = null; + if (patternNode instanceof TypePattern) { + TypePattern typePat = (TypePattern)patternNode; + pNode = new DefaultTypePattern(this.ast,typePat.toString()); + pNode.setSourceRange(typePat.getStart(),(typePat.getEnd() - typePat.getStart() + 1)); + } else if (patternNode instanceof SignaturePattern) { + SignaturePattern sigPat = (SignaturePattern)patternNode; + pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast,sigPat.toString()); + pNode.setSourceRange(sigPat.getStart(),(sigPat.getEnd() - sigPat.getStart() + 1)); + } + return pNode; + + } + public ASTNode convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) { checkCanceled(); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java new file mode 100644 index 000000000..41ae03e6b --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java @@ -0,0 +1,21 @@ +/******************************************************************** + * Copyright (c) 2006 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - iniital version + *******************************************************************/ +package org.aspectj.org.eclipse.jdt.core.dom; + +import org.aspectj.org.eclipse.jdt.core.dom.ASTParser.IASTFactory; + +public class AjASTFactory implements IASTFactory { + + public AST getAST(int level) { + return AjAST.newAjAST(level); + } + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java index b395dbde3..6e928d1fa 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java @@ -249,4 +249,11 @@ public class AjASTMatcher extends ASTMatcher { && safeSubtreeMatch(node.getBody(), o.getBody())); } + public boolean match(DefaultTypePattern node, Object other) { + return (other instanceof DefaultTypePattern); + } + + public boolean match(SignaturePattern node, Object other) { + return (other instanceof SignaturePattern); + } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java index 075c66a91..0f0ff286f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java @@ -118,7 +118,76 @@ public abstract class AjASTVisitor extends ASTVisitor { // ajh02: method added // default implementation: do nothing } - public boolean visit(PointcutDeclaration node) { + + public boolean visit(DeclareAnnotationDeclaration node) { + return true; + } + public void endVisit(DeclareAnnotationDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareAtTypeDeclaration node) { + return true; + } + public void endVisit(DeclareAtTypeDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareAtConstructorDeclaration node) { + return true; + } + public void endVisit(DeclareAtConstructorDeclaration node) { + // default implementation: do nothing + } + public boolean visit(DeclareAtMethodDeclaration node) { + return true; + } + public void endVisit(DeclareAtMethodDeclaration node) { + // default implementation: do nothing + } + public boolean visit(DeclareAtFieldDeclaration node) { + return true; + } + public void endVisit(DeclareAtFieldDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareErrorDeclaration node) { + return true; + } + public void endVisit(DeclareErrorDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareParentsDeclaration node) { + return true; + } + public void endVisit(DeclareParentsDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclarePrecedenceDeclaration node) { + return true; + } + public void endVisit(DeclarePrecedenceDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareSoftDeclaration node) { + return true; + } + public void endVisit(DeclareSoftDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(DeclareWarningDeclaration node) { + return true; + } + public void endVisit(DeclareWarningDeclaration node) { + // default implementation: do nothing + } + + public boolean visit(PointcutDeclaration node) { return true; } @@ -162,5 +231,17 @@ public abstract class AjASTVisitor extends ASTVisitor { public void endVisit(AdviceDeclaration node) { // default implementation: do nothing } - + + public boolean visit(DefaultTypePattern node) { + return true; + } + + public void endVisit(DefaultTypePattern node) { + } + public boolean visit(SignaturePattern node) { + return true; + } + + public void endVisit(SignaturePattern node) { + } } -- 2.39.5