Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:03+00:00 2026-06-17T06:32:03+00:00

I am writing some code to parse java source code. I am experimenting with

  • 0

I am writing some code to parse java source code. I am experimenting with Eclipse JDT AST Parser. My code is given below. (Parsing code). I am testing the parser against a Mailer application that I wrote in Java (second code snippet). My parser is visiting all methods except the generateEmail() and the debug() methods. I have looked all over the place but I am not able to understand for the life of me why its happening. Can anyone tell me what I am doing wrong? Is it a memory issue? I am not getting any OutOfMemoryException

I want to visit the specific methods with the MethodVisitor method to get access to statements and variables in a particular method.

My Parsing code

public class RuleEngine {

public static void parse(String file) {
    File java = new File(file);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    String code = readFile(java);
    parser.setSource(code.toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    final CompilationUnit cu = (CompilationUnit) parser.createAST(null);


    cu.accept(new ASTVisitor() {

        public boolean visit(ImportDeclaration id) {
            Name imp = id.getName();
            debug("import", id.getName().getFullyQualifiedName());
            return false;
        }

        public boolean visit(VariableDeclarationFragment node) {
            SimpleName name = node.getName();
            debug("var.declaration", (name.getFullyQualifiedName() + ":" + cu.getLineNumber(name.getStartPosition())));
            return false; // do not continue 
        }

        public boolean visit(MethodDeclaration method) {
            debug("method", method.getName().getFullyQualifiedName());
            debug("method.return", method.getReturnType2().toString());
            List<SingleVariableDeclaration> params = method.parameters();

            for(SingleVariableDeclaration param: params) {
                debug("param", param.getName().getFullyQualifiedName());
            }

            Block methodBlock = method.getBody();
            String myblock = methodBlock.toString();
            methodVisitor(myblock);
            return false;
        }


    });

}

public static void methodVisitor(String content) {
    debug("entering met visitor", "1");
    ASTParser metparse = ASTParser.newParser(AST.JLS3);
    metparse.setSource(content.toCharArray());
    metparse.setKind(ASTParser.K_STATEMENTS);
    Block block = (Block) metparse.createAST(null);

    block.accept(new ASTVisitor() {
        public boolean visit(VariableDeclarationFragment var) {
            debug("met.var", var.getName().getFullyQualifiedName());
            return false;
        }

        public boolean visit(SimpleName node) {
            debug("SimpleName node", node.getFullyQualifiedName());
            return false;
        }
        public boolean visit(IfStatement myif) {
            debug("if.statement", myif.toString());
            return false;
        }

    });
}

public static void debug(String ref, String message) {
    System.out.println(ref +": " + message);
}

public static void main(String[]args) {
    parse("MailerDaemon.java");
}

This is my MailerDaemon Code

public boolean isBccMode() {
    return bccMode;
}

public void setBccMode(boolean bccMode) {
    this.bccMode = bccMode;
}

public void setServerPort(String serverPortAddr) {
    String[] elems = serverPortAddr.split("\\:");
    this.setServerAddr(elems[0]);
    this.setSmtpPort(elems[1]);
}

public String getServerAddr() {
    int i = 0;
    return serverAddr;
}
public void setServerAddr(String serverAddr) {
    this.serverAddr = serverAddr;
}
public boolean isSslOn() {
    return isSslOn;
}
public void setSslOn(boolean isSslOn) {
    this.isSslOn = isSslOn;
}
public String getSmtpPort() {
    return smtpPort;
}
public void setSmtpPort(String smtpPort) {
    this.smtpPort = smtpPort;
}
public String getFromEmail() {
    return fromEmail;
}
public void setFromEmail(String fromEmail) {
    this.fromEmail = fromEmail;
}
public String getToEmails() {
    return toEmails;
}
public void setToEmails(String toEmails) {
    this.toEmails = toEmails;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getSubject() {
    return subject;
}
public void setSubject(String subject) {
    this.subject = subject;
}
public String getMessage() {
    return message;
}
public void setMessage(String message) {
    this.message = message;
}
public String getCcList() {
    return ccList;
}
public void setCcList(String ccList) {
    this.ccList = ccList;
}
public String getBccList() {
    return bccList;
}
public void setBccList(String bccList) {
    this.bccList = bccList;
}



public String getFile() {
    return file;
}
public void setFile(String file) {
    debug("filename: " + file);
    this.file = file;
}
public void generateEmail() {
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", this.getSmtpPort());
    if(isSslOn()) {
        props.put("mail.smtp.socketFactory.port", this.getSmtpPort());
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    }
    props.put("mail.smtp.host", getServerAddr());

    Session session = Session.getDefaultInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(getUsername(), getPassword());
        }
    });


    Message msg = new MimeMessage(session);
    try {
        msg.setFrom(new InternetAddress(this.getFromEmail()));
        if (getToEmails() != null) {
            msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getToEmails()));
        } else if (isBccMode()) {
            msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getFromEmail()));
        }

        //msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(getCcList()));
        msg.setSubject(getSubject());
        //msg.setText(getMessage());
        MimeBodyPart messagePart = new MimeBodyPart();
        messagePart.setText(getMessage());

        /*
        MimeBodyPart attachments = new MimeBodyPart();
        FileDataSource fd = new FileDataSource(getFile());
        attachments.setDataHandler(new DataHandler(fd));
        attachments.setFileName(fd.getName());
        */

        Multipart mp = new MimeMultipart();
        mp.addBodyPart(messagePart);
        //mp.addBodyPart(attachments);

        msg.setContent(mp);
        Transport.send(msg);
        debug("Done. Closing Session...");

    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

private static void debug(String message) {
    System.out.println("[DEBUG]: " + message);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:32:04+00:00Added an answer on June 17, 2026 at 6:32 am

    I see no evident problem with your parsing code. I hope its failing somewhere when its trying to parse the generateEmail() method. Since the parser follows a sequential approach, the debug() method is also not getting parsed. Try to enclose the statements within the public boolean visit(MethodDeclaration method) in a try-catch block with probably a Throwable clause.

    Also have a check for your readFile() method. One issue that is mostly seen while reading a file is missing to append new line character to each line. Not appending a new line results in erroneous construction of the code, especially when there are comments in the code. You may inspect compilationUnit.getProblems() method to check any such problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some java code that's supposed to parse csv files with different column
I'm writing some code that will take a screenshot of another application, given its'
I'm writing some C code to parse IEEE 802.11 frames, but I'm stuck trying
I'm writing some code using PacketDotNet and SharpPCap to parse H.225 packets for a
I'm writing some python code that's supposed to parse a CSV file. Calculate the
I'm writing some code to parse RTF documents, and need to handle the various
I am writing some code to parse an xml file of the following format
I'm re-writing some code that uses a XmlDocument to parse some XML. I want
I'm writing some code to load and parse HTML docs from the web. I'm
I'm writing a Java GUI application that is doing some XML parsing and analysis.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.