本文整理汇总了Java中net.sourceforge.pmd.lang.ast.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于net.sourceforge.pmd.lang.ast包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
@Test
public void test() throws Exception {
FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
String nullableDescription = null;
ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
Optional<String> copyright = Optional.absent();
Optional<String> header = Optional.absent();
GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
File dstFile = entry.getValue();
Node c = parse(dstFile);
assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
assertHasMethodNamed(c, "customValidation");
assertHasMethodNamed(c, "createInstance");
}
示例2: select
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
public void select(Node node) {
SwingUtilities.invokeLater(() -> {
String[] lines = getLines();
if (node.getBeginLine() >= 0) {
selectRange(getPosition(lines, node.getBeginLine(), node.getBeginColumn()),
getPosition(lines, node.getEndLine(), node.getEndColumn()) + 1);
// setSelectionStart(getPosition(lines, node.getBeginLine(), node.getBeginColumn()));
// setSelectionEnd(getPosition(lines, node.getEndLine(), node.getEndColumn()) + 1);
}
// requestFocus();
});
}
示例3: containsPlainJunitAssert
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
/**
* Recursively verifies if node contains plain JUnit assert statements.
* @param node Root statement node to search
* @return True if statement contains plain JUnit assertions, false
* otherwise
*/
private boolean containsPlainJunitAssert(final Node node) {
boolean found = false;
if (node instanceof ASTStatementExpression
&& ProhibitPlainJunitAssertionsRule.isPlainJunitAssert(node)) {
found = true;
}
if (!found) {
for (int iter = 0; iter < node.jjtGetNumChildren(); iter += 1) {
final Node child = node.jjtGetChild(iter);
if (this.containsPlainJunitAssert(child)) {
found = true;
break;
}
}
}
return found;
}
示例4: isPlainJunitAssert
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
/**
* Tells if the statement is an assert statement or not.
* @param statement Root node to search assert statements
* @return True is statement is assert, false otherwise
*/
private static boolean isPlainJunitAssert(final Node statement) {
final ASTPrimaryExpression expression =
ProhibitPlainJunitAssertionsRule.getChildNodeWithType(
statement, ASTPrimaryExpression.class
);
final ASTPrimaryPrefix prefix =
ProhibitPlainJunitAssertionsRule.getChildNodeWithType(
expression, ASTPrimaryPrefix.class
);
final ASTName name = ProhibitPlainJunitAssertionsRule
.getChildNodeWithType(prefix, ASTName.class);
boolean assrt = false;
if (name != null) {
final String img = name.getImage();
assrt = img != null && (img.startsWith("assert")
|| img.startsWith("Assert.assert"));
}
return assrt;
}
示例5: getCompilationUnit
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
static Node getCompilationUnit(LanguageVersionHandler languageVersionHandler, String code) {
Parser parser = languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions());
Node node = parser.parse(null, new StringReader(code));
languageVersionHandler.getSymbolFacade().start(node);
languageVersionHandler.getTypeResolutionFacade(DesignerFx.class.getClassLoader()).start(node);
return node;
}
示例6: ASTTreeNode
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
public ASTTreeNode(Node theNode) {
node = theNode;
Node parent = node.jjtGetParent();
if (parent != null) {
this.parent = new ASTTreeNode(parent);
}
}
示例7: actionPerformed
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
public void actionPerformed(ActionEvent ae) {
TreeNode tn;
try {
Node lastCompilationUnit = getCompilationUnit();
tn = new ASTTreeNode(lastCompilationUnit);
} catch (ParseException pe) {
tn = new ExceptionNode(pe);
}
loadASTTreeData(tn);
loadSymbolTableTreeData(null);
}
示例8: getListCellRendererComponent
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
String text;
if (value instanceof Node) {
Node node = (Node) value;
StringBuffer sb = new StringBuffer();
String name = node.getClass().getName().substring(node.getClass().getName().lastIndexOf('.') + 1);
if (Proxy.isProxyClass(value.getClass())) {
name = value.toString();
}
sb.append(name).append(" at line ").append(node.getBeginLine()).append(" column ").append(node.getBeginColumn())
.append(PMD.EOL);
text = sb.toString();
} else {
text = value.toString();
}
setText(text);
return this;
}
示例9: valueChanged
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (!lsm.isSelectionEmpty()) {
Object o = xpathResults.get(lsm.getMinSelectionIndex());
if (o instanceof Node) {
codeEditorPane.select((Node) o);
}
}
}
示例10: createASTPanel
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
private javafx.scene.Node createASTPanel() {
astTreeWidget.setCellRenderer(createNoImageTreeCellRenderer());
TreeSelectionModel model = astTreeWidget.getSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
model.addTreeSelectionListener(new SymbolTableListener());
model.addTreeSelectionListener(new CodeHighlightListener());
SwingNode swingNode = new SwingNode();
createSwingContent(swingNode, new JScrollPane(astTreeWidget));
return swingNode;
}
示例11: createXPathResultPanel
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
private javafx.scene.Node createXPathResultPanel() {
xpathResults.addElement("No XPath results yet, run an XPath Query first.");
xpathResultList.setBorder(BorderFactory.createLineBorder(Color.black));
xpathResultList.setFixedCellWidth(300);
xpathResultList.setCellRenderer(new ASTListCellRenderer());
xpathResultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
xpathResultList.getSelectionModel().addListSelectionListener(new ASTSelectionListener());
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().setView(xpathResultList);
SwingNode swingNode = new SwingNode();
createSwingContent(swingNode, scrollPane);
return swingNode;
}
示例12: createSymbolTableResultPanel
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
private javafx.scene.Node createSymbolTableResultPanel() {
symbolTableTreeWidget.setCellRenderer(createNoImageTreeCellRenderer());
SwingNode swingNode = new SwingNode();
JScrollPane jScrollPane = new JScrollPane(symbolTableTreeWidget);
createSwingContent(swingNode, jScrollPane);
return swingNode;
}
示例13: createXPathVersionPanel
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
private javafx.scene.Node createXPathVersionPanel() {
HBox p = new HBox(5);
p.setPadding(new Insets(5, 5, 5, 5));
// JPanel p = new JPanel();
Label e = new Label("XPath Version:");
e.setAlignment(Pos.CENTER_LEFT);
p.add(e);
for (Object[] values : XPathRule.VERSION_DESCRIPTOR.choices()) {
// JRadioButton b = new JRadioButton();
RadioButton b = new RadioButton((String) values[0]);
// b.setText((String) values[0]);
b.setUserData(b.getText());
// b.setActionCommand(b.getText());
if (values[0].equals(XPathRule.VERSION_DESCRIPTOR.defaultValue())) {
b.setSelected(true);
}
b.setToggleGroup(xpathVersionButtonGroup);
// xpathVersionButtonGroup.add(b);
p.add(b);
}
// SwingNode swingNode = new SwingNode();
// createSwingContent(swingNode, p);
return p;
}
示例14: getXmlTreeCode
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
private final String getXmlTreeCode() {
if (codeEditorPane.getText() != null && codeEditorPane.getText().trim().length() > 0) {
Node cu = getCompilationUnit();
return getXmlTreeCode(cu);
}
return null;
}
示例15: getXmlString
import net.sourceforge.pmd.lang.ast.Node; //导入依赖的package包/类
/**
* Returns an unformatted xml string (without the declaration)
*
* @throws TransformerException if the XML cannot be converted to a string
*/
private static String getXmlString(Node node) throws TransformerException {
StringWriter writer = new StringWriter();
Source source = new DOMSource(node.getAsDocument());
Result result = new StreamResult(writer);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer xformer = transformerFactory.newTransformer();
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.transform(source, result);
return writer.toString();
}