]> source.dussan.org Git - aspectj.git/commitdiff
Fixed 39626: Added AsmBuilderTest class that tests handling for this and related...
authormkersten <mkersten>
Wed, 30 Jul 2003 09:10:45 +0000 (09:10 +0000)
committermkersten <mkersten>
Wed, 30 Jul 2003 09:10:45 +0000 (09:10 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjdtBuilderTests.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java [new file with mode: 0644]

index 96ddef7af4a878feafb73fff506b8a418034ea8e..9b363b88c2bc34dec768d13c3706d673854dfc33 100644 (file)
@@ -69,7 +69,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
        private final Stack stack;
        private final CompilationResult currCompilationResult;
        
-    private AsmBuilder(CompilationResult result) {
+    protected AsmBuilder(CompilationResult result) {
         LangUtil.throwIaxIfNull(result, "result");
         currCompilationResult = result;
         stack = new Stack();
@@ -228,7 +228,13 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
        
        public boolean visit(LocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
                String name = new String(memberTypeDeclaration.name);
-               String fullName = new String(memberTypeDeclaration.binding.constantPoolName());
+               
+               String fullName = "<undefined>";
+               if (memberTypeDeclaration.binding != null
+                       && memberTypeDeclaration.binding.constantPoolName() != null) {
+                       fullName = new String(memberTypeDeclaration.binding.constantPoolName());
+               }
+                
                int dollar = fullName.indexOf('$');
                fullName = fullName.substring(dollar+1);
 //             
@@ -428,7 +434,9 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
 
        // ??? handle non-existant files
        private ISourceLocation makeLocation(AstNode node) {
-               String fileName = new String(currCompilationResult.getFileName());
+               
+               String fileName = "";
+               if (currCompilationResult.getFileName() != null) new String(currCompilationResult.getFileName());
                // AMC - different strategies based on node kind
                int startLine = getStartLine(node);
                int endLine = getEndLine(node);
index 25d0f40ec9fa2512cdcd1b3331e341811dd47efd..e17a5e54202772caa56e99cea87fa8f2fd9a5b8f 100644 (file)
@@ -22,6 +22,7 @@ public class AjdtBuilderTests extends TestCase {
         TestSuite suite = new TestSuite(AjdtBuilderTests.class.getName());
         //$JUnit-BEGIN$
         suite.addTestSuite(AjBuildManagerTest.class); 
+               suite.addTestSuite(AsmBuilderTest.class); 
         //$JUnit-END$
         return suite;
     }
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java
new file mode 100644 (file)
index 0000000..759dbcb
--- /dev/null
@@ -0,0 +1,69 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation, 
+ *               2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     PARC     initial implementation 
+ * ******************************************************************/
+
+
+package org.aspectj.ajdt.internal.core.builder;
+
+import java.util.EmptyStackException;
+
+import junit.framework.*;
+
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.LocalTypeDeclaration;
+import org.eclipse.jdt.internal.compiler.env.*;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+
+public class AsmBuilderTest extends TestCase {
+
+    public static Test suite() { 
+        TestSuite suite = new TestSuite(AsmBuilderTest.class.getName());
+        //$JUnit-BEGIN$
+        suite.addTestSuite(AsmBuilderTest.class); 
+        //$JUnit-END$
+        return suite;
+    }
+
+       /**
+        * Test for bug#39626
+        */
+       public void testNullHandlingOfVisit() { 
+               ICompilationUnit cu = new ICompilationUnit() {
+                       public char[] getContents() {
+                               return null;
+                       }
+
+                       public char[] getMainTypeName() {
+                               return null;
+                       }
+
+                       public char[][] getPackageName() {
+                               return null;
+                       }
+                       
+                       public char[] getFileName() { 
+                               return null;
+                       }
+                       
+               };
+               LocalTypeDeclaration local = new LocalTypeDeclaration(new CompilationResult(cu, 0, 0, 0));
+               local.name = new char[2];
+               BlockScope scope = null;
+               
+               try { 
+                       new AsmBuilder(new CompilationResult(cu, 0, 0, 0)).visit(local, scope);
+               } catch (Exception e) {
+                       assertTrue(e instanceof EmptyStackException);
+               }
+       }
+
+}