Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.CompilationUnit


      }
     
      if(!lookCloser)
        continue;
     
      CompilationUnit cu =
          (CompilationUnit) WorkspaceUtilities.getASTNodeFromCompilationUnit(icu);
      Collection<TestType> tests = findTestTypes(cu);

      for (TestType test : tests) {
        // These three array elements correspond to the three parameters
View Full Code Here


  // Assume that we are using a class where every method has a unique name
  static Map<String, MethodDeclaration> methods = new HashMap<String, MethodDeclaration>();

  @BeforeClass
  static public void setup() throws CoreException {
    CompilationUnit compUnit = CFGTestUtils.parseCode(Switch.class
        .getName());
    methods = CFGTestUtils.createMethodNameMap(compUnit);
  }
View Full Code Here

public class TestUtilities {

  static public void runTest(String code, String subFolder, String file,
      boolean doCompare, boolean store) throws Exception {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    CompilationUnit node;
    Graph testGraph;
    OutputStream out;

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    // parser.setBindingsRecovery(true);
    parser.setSource(code.toCharArray());
    parser.setUnitName("Foo.java");
    // parser.setProject(JavaCore.create(null));
    node = (CompilationUnit) parser.createAST(null);

    for (IProblem problem : node.getProblems()) {
      System.out.println("Compile problem for " + subFolder + "_" + file);
      System.out.println(problem.getMessage());
    }

    Assert.assertEquals(0, node.getProblems().length);
    List<MethodDeclaration> methods = WorkspaceUtilities
        .scanForMethodDeclarationsFromAST(node);
    Assert.assertEquals(1, methods.size());
    IControlFlowGraph cfg = new EclipseNodeFirstCFG(methods.get(0));
View Full Code Here

  // Assume that we are using a class where every method has a unique name
  static Map<String, MethodDeclaration> methods = new HashMap<String, MethodDeclaration>();

  @BeforeClass
  static public void setup() throws CoreException {
    CompilationUnit compUnit = CFGTestUtils.parseCode(Conditional.class
        .getName());
    methods = CFGTestUtils.createMethodNameMap(compUnit);
  }
View Full Code Here

            }
            if (logger.isLoggable(Level.FINE))
              logger.fine("Running Crystal on: " + cu.getResource().getLocation().toOSString());
           
            // Run each analysis on the current compilation unit.
            CompilationUnit ast_comp_unit =
                (CompilationUnit) WorkspaceUtilities.getASTNodeFromCompilationUnit(cu);

            // Here, create one TAC cache per compilation unit.
            final CompilationUnitTACs compUnitTacs = new CompilationUnitTACs();
View Full Code Here

*/
public class EclipseTACArrayTest {

  @Test
  public void testArrayRead() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayRead", ARRAY_READ);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    ArrayAccess read = (ArrayAccess) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(read);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testArrayWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayWrite", ARRAY_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    Assignment write = (Assignment) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(m)).getExpression();
    TACInstruction instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testArrayInc() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayInc", ARRAY_INC);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    PrefixExpression inc = (PrefixExpression) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(inc);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testNestedArrayWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("NestedArrayWrite", NESTED_ARRAY_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    MethodInvocation inv = (MethodInvocation) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(m)).getExpression();
    TACInstruction instr = tac.instruction(inv);
    Assert.assertTrue(instr != null);
View Full Code Here

    String prefix = null;

    // Identify the closest resource to the ASTNode,
    // otherwise fall back to using the high-level workspace root.
    if (root != null && root.getNodeType() == ASTNode.COMPILATION_UNIT) {
      CompilationUnit cu = (CompilationUnit) root;
      IJavaElement je = cu.getJavaElement();
      resource = je.getResource();
      // print type root name into message if no resource
      prefix = resource == null ?
          "[" + analysisName + " in " + je.getElementName() + "]" :
          "[" + analysisName + "]";
    }
    if (resource == null)
      // Fall back to the high-level Workspace
      resource = ResourcesPlugin.getWorkspace().getRoot();
    if (prefix == null)
      prefix = "[" + analysisName + " in ???]";

    int sevMarker;

    if (severity == SEVERITY.ERROR)
      sevMarker = IMarker.SEVERITY_ERROR;
    else if (severity == SEVERITY.WARNING)
      sevMarker = IMarker.SEVERITY_WARNING;
    else
      sevMarker = IMarker.SEVERITY_INFO;

    // Create the marker
    // TODO: create markers according to the type of the analysis
    try {
      IMarker marker = resource.createMarker(Crystal.MARKER_DEFAULT);
      marker.setAttribute(IMarker.CHAR_START, node.getStartPosition());
      marker.setAttribute(IMarker.CHAR_END, node.getStartPosition() + node.getLength());
      marker.setAttribute(IMarker.MESSAGE, prefix + ": " + problemDescription);
      marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
      marker.setAttribute(IMarker.SEVERITY, sevMarker);
      marker.setAttribute(Crystal.MARKER_ATTR_ANALYSIS, analysisName);
      CompilationUnit cu = (CompilationUnit) node.getRoot();
      int line = cu.getLineNumber(node.getStartPosition());
      if (line >= 0) // -1 and -2 indicate error conditions
        marker.setAttribute(IMarker.LINE_NUMBER, line);
    }
    catch (CoreException ce) {
      logger.log(Level.SEVERE, "CoreException when creating marker", ce);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.CompilationUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.