use of com.github.javaparser.ast.Node in project Gargoyle by callakrsos.
the class VOEditorParser2 method main.
public static void main(String[] args) throws ParseException, IOException {
String fileName = "C:\\Users\\KYJ\\JAVA_FX\\gagoyleWorkspace\\VisualFxVoEditor\\src\\main\\java\\com\\kyj\\fx\\voeditor\\visual\\main\\model\\vo\\ClassPathEntry.java";
FileInputStream in = new FileInputStream(fileName);
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
PackageDeclaration packageDeclaration = cu.getPackage();
// System.out.println(packageDeclaration.getName().toString());
// System.out.println();
// System.out.println(String.format("package name : %s",
// packageDeclaration.getName().getName()));
ClassMeta classMeta = new ClassMeta("");
classMeta.setPackageName(packageDeclaration.getName().toString());
ArrayList<FieldMeta> fields = new ArrayList<FieldMeta>();
VoEditor voEditor = new VoEditor(classMeta, fields);
List<Node> childrenNodes = cu.getChildrenNodes();
for (Node n : childrenNodes) {
}
new MethodVisitor().visit(cu, null);
}
use of com.github.javaparser.ast.Node in project controller by opendaylight.
the class MbeASTVisitor method visit.
@Override
public void visit(final NormalAnnotationExpr expr, final Void arg) {
super.visit(expr, arg);
final String fqcn = expr.getName().toString();
if (fqcn.equals(RequireInterface.class.getCanonicalName()) && expr.getParentNode() instanceof MethodDeclaration) {
final Node parent = expr.getParentNode();
if (parent instanceof MethodDeclaration) {
// remember only top level description annotation
String reqVal = expr.getPairs().get(0).toString();
requireIfc.put(((MethodDeclaration) parent).getName(), reqVal);
}
}
}
use of com.github.javaparser.ast.Node in project activityinfo by bedatadriven.
the class DefaultUpdatingVisitor method updateAnnotationValue.
private void updateAnnotationValue(AnnotationExpr annotation, String literalValue) {
List<Node> children = annotation.getChildrenNodes();
if (children.size() == 2 && children.get(0) instanceof NameExpr && children.get(1) instanceof StringLiteralExpr) {
StringLiteralExpr literal = (StringLiteralExpr) children.get(1);
if (!literal.getValue().equals(literalValue)) {
literal.setValue(literalValue);
dirty = true;
}
} else if (annotation instanceof SingleMemberAnnotationExpr) {
// Annotations can contain more complex ASTs, for example "part of a string" + "part of another string"
// In this case, replace wholesale
SingleMemberAnnotationExpr smae = (SingleMemberAnnotationExpr) annotation;
smae.setMemberValue(new StringLiteralExpr(literalValue));
} else {
throw new RuntimeException("Expected @" + defaultAnnotationName + " to be of type " + SingleMemberAnnotationExpr.class.getName() + ", found: " + annotation.getClass().getName());
}
}
use of com.github.javaparser.ast.Node in project javaparser by javaparser.
the class Difference method calculate.
/**
* Calculate the Difference between two CalculatedSyntaxModel elements, determining which elements were kept,
* which were added and which were removed.
*/
static Difference calculate(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) {
// For performance reasons we use the positions of matching children
// to guide the calculation of the difference
//
// Suppose we have:
// qwerty[A]uiop
// qwer[A]uiop
//
// with [A] being a child and lowercase letters being tokens
//
// We would calculate the Difference between "qwerty" and "qwer" then we know the A is kept, and then we
// would calculate the difference between "uiop" and "uiop"
Map<Node, Integer> childrenInOriginal = findChildrenPositions(original);
Map<Node, Integer> childrenInAfter = findChildrenPositions(after);
List<Node> commonChildren = new LinkedList<>(childrenInOriginal.keySet());
commonChildren.retainAll(childrenInAfter.keySet());
commonChildren.sort(Comparator.comparingInt(childrenInOriginal::get));
List<DifferenceElement> elements = new LinkedList<>();
int originalIndex = 0;
int afterIndex = 0;
int commonChildrenIndex = 0;
while (commonChildrenIndex < commonChildren.size()) {
Node child = commonChildren.get(commonChildrenIndex++);
int posOfNextChildInOriginal = childrenInOriginal.get(child);
int posOfNextChildInAfter = childrenInAfter.get(child);
if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) {
elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter)).elements);
}
elements.add(new Kept(new CsmChild(child)));
originalIndex = posOfNextChildInOriginal + 1;
afterIndex = posOfNextChildInAfter + 1;
}
if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) {
elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size())).elements);
}
return new Difference(elements);
}
use of com.github.javaparser.ast.Node in project javaparser by javaparser.
the class LexicalPreservingPrinter method storeInitialTextForOneNode.
private static void storeInitialTextForOneNode(Node node, List<JavaToken> nodeTokens) {
if (nodeTokens == null) {
nodeTokens = Collections.emptyList();
}
List<Pair<Range, TextElement>> elements = new LinkedList<>();
for (Node child : node.getChildNodes()) {
if (!PhantomNodeLogic.isPhantomNode(child)) {
if (!child.getRange().isPresent()) {
throw new RuntimeException("Range not present on node " + child);
}
elements.add(new Pair<>(child.getRange().get(), new ChildTextElement(child)));
}
}
for (JavaToken token : nodeTokens) {
elements.add(new Pair<>(token.getRange().get(), new TokenTextElement(token)));
}
elements.sort(comparing(e -> e.a.begin));
node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(Collectors.toList())));
}
Aggregations