Package org.eclipse.jdt.core.dom

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


  // 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(Label.class.getName());
    methods = CFGTestUtils.createMethodNameMap(compUnit);
  }
View Full Code Here


public class ConstructorDecl {
  static List<MethodDeclaration> decls;

  @BeforeClass
  public static void setup() throws CoreException {
    CompilationUnit compUnit = CFGTestUtils.parseCode(ConstructorDecl.class.getName());
    decls = WorkspaceUtilities.scanForMethodDeclarationsFromAST(compUnit);
  }
View Full Code Here

*/
public class EclipseTACFieldInitTest {

  @Test
  public void testFieldInitializer() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("FieldInit", FIELD_INIT);
    MethodDeclaration c = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNotNull(init);
View Full Code Here

    "    public int getF() { return f; }" +
    "}";
 
  @Test
  public void testFieldInitNew() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("FieldInitNew", FIELD_INIT_NEW);
    MethodDeclaration c = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNotNull(init);
View Full Code Here

    "    public Object getF() { return f; }" +
    "}";
 
  @Test
  public void testFieldNoInitializer() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("FieldNoInit", FIELD_NO_INIT);
    MethodDeclaration c = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNull(init);
View Full Code Here

*/
public class EclipseTACSimpleTest {

  @Test
  public void testSimpleBinop() throws Exception {
    CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("SimpleBinop", SIMPLE_BINOP);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    InfixExpression infix = (InfixExpression) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(infix);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testSimpleCall() throws Exception {
    CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("SimpleCall", SIMPLE_CALL);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    MethodInvocation invoke = (MethodInvocation) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(invoke);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testStaticCall() throws Exception {
    CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("StaticCall", STATIC_CALL);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    MethodInvocation invoke = (MethodInvocation) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(invoke);
    Assert.assertTrue(instr != null);
View Full Code Here

    "    }" +
    "}";
 
  @Test
  public void testSimpleReturn() throws Exception {
    CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("SimpleReturn", SIMPLE_RETURN);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    ReturnStatement ret = (ReturnStatement) EclipseTACSimpleTestDriver.getLastStatementReturn(m);
    Assert.assertTrue(ret.getExpression() != null);
    TACInstruction instr = tac.instruction(ret);
View Full Code Here

    ASTNode root = node.getRoot();

    // Identify the closest resource to the ASTNode,
    // otherwise fall back to using the high-level workspace root.
    if (root.getNodeType() == ASTNode.COMPILATION_UNIT) {
      CompilationUnit cu = (CompilationUnit) root;
      IJavaElement je = cu.getJavaElement();
      resource = je.getResource();
    }
    else {
      // Use the high-level Workspace
      resource = ResourcesPlugin.getWorkspace().getRoot();
    }

    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, "[" + analysisName + "]: " + 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.