When I read about the source codes of Eclipse, I found one file named "$className$.java". Part of its content is as follows:
package $packageName$;
% if viewType =="treeViewer"
import java.util.ArrayList;
% endif
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.*;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
% if viewType == "treeViewer"
import org.eclipse.core.runtime.IAdaptable;
% endif
% Options in the template:
%
% packageName
% className
% viewName
% viewCategoryId
% viewCategoryName
% viewType
% doubleClick
% popup
% localToolbar
% localPulldown
% sorter
% filter
% drillDown
public class $className$ extends ViewPart {
%if viewType == "tableViewer"
private TableViewer viewer;
%else
% if viewType == "treeViewer"
private TreeViewer viewer;
private DrillDownAdapter drillDownAdapter;
% endif
%endif
%if (localToolbar || localPulldown || popup)
private Action action1;
private Action action2;
%endif
%if doubleClick
private Action doubleClickAction;
%endif
I was trying to extract the AST of if, then I got an error. What do "% if" and "% endif" mean in java? And how can I get the AST of it?
This is not a valid Java source file, it is either an Eclipse file template used to generate Java files of a certain type, or it is a file that first needs to be run through a preprocessor before it is an actually valid Java source file.
If the first, then you should not even try to obtain an AST from it, if the latter, you need to find out which preprocessor is used by this project (there is no standard one in Java), and run the file through it and extract the AST from the result of the preprocessing step.