]> source.dussan.org Git - aspectj.git/commitdiff
necessary magic. Factory 'mechanism' used so that the JDT project doesnt have a...
authoraclement <aclement>
Thu, 26 Jan 2006 10:57:12 +0000 (10:57 +0000)
committeraclement <aclement>
Thu, 26 Jan 2006 10:57:12 +0000 (10:57 +0000)
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java

index 1e569ce2b19b99b7642d611043325ae7c8278017..d7e1a7124a7e186ee654507c9d346a0a6155feb0 100644 (file)
@@ -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 (file)
index 0000000..41ae03e
--- /dev/null
@@ -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);
+       }
+
+}
index b395dbde35e49277c76e2dd28da9a6c93ad7c304..6e928d1fa3541145cee063dccb7d6a41386b57f4 100644 (file)
@@ -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);
+       }
 }
index 075c66a910d9440bb0082401138bb498d8f58c14..0f0ff286fb1f9c9cb0b89393a4f7570642bd7a78 100644 (file)
@@ -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) {
+       }
 }