├── .DS_Store ├── src ├── .DS_Store ├── main │ ├── .DS_Store │ ├── java │ │ ├── .DS_Store │ │ └── org │ │ │ └── walkmod │ │ │ └── javalang │ │ │ ├── javadoclinks │ │ │ ├── Link.java │ │ │ ├── FieldLink.java │ │ │ ├── JavadocLinkParserConstants.java │ │ │ └── MethodLink.java │ │ │ ├── package-info.java │ │ │ ├── ast │ │ │ ├── package-info.java │ │ │ ├── type │ │ │ │ ├── package-info.java │ │ │ │ ├── VoidType.java │ │ │ │ ├── PrimitiveType.java │ │ │ │ └── IntersectionType.java │ │ │ ├── stmt │ │ │ │ ├── package-info.java │ │ │ │ ├── Statement.java │ │ │ │ ├── EmptyStmt.java │ │ │ │ ├── BreakStmt.java │ │ │ │ ├── ContinueStmt.java │ │ │ │ ├── ThrowStmt.java │ │ │ │ ├── ReturnStmt.java │ │ │ │ ├── ExpressionStmt.java │ │ │ │ └── LabeledStmt.java │ │ │ ├── body │ │ │ │ ├── package-info.java │ │ │ │ ├── JavadocComment.java │ │ │ │ ├── EmptyTypeDeclaration.java │ │ │ │ ├── AnnotationDeclaration.java │ │ │ │ ├── EmptyMemberDeclaration.java │ │ │ │ ├── VariableDeclaratorId.java │ │ │ │ └── MultiTypeParameter.java │ │ │ ├── expr │ │ │ │ ├── package-info.java │ │ │ │ ├── LiteralExpr.java │ │ │ │ ├── Expression.java │ │ │ │ ├── LongLiteralMinValueExpr.java │ │ │ │ ├── IntegerLiteralMinValueExpr.java │ │ │ │ ├── CharLiteralExpr.java │ │ │ │ ├── DoubleLiteralExpr.java │ │ │ │ ├── NullLiteralExpr.java │ │ │ │ ├── IntegerLiteralExpr.java │ │ │ │ ├── LongLiteralExpr.java │ │ │ │ ├── BooleanLiteralExpr.java │ │ │ │ ├── MarkerAnnotationExpr.java │ │ │ │ ├── QualifiedNameExpr.java │ │ │ │ ├── ClassExpr.java │ │ │ │ ├── EnclosedExpr.java │ │ │ │ ├── SuperExpr.java │ │ │ │ ├── ThisExpr.java │ │ │ │ ├── TypeExpr.java │ │ │ │ ├── AnnotationExpr.java │ │ │ │ ├── NameExpr.java │ │ │ │ ├── ArrayInitializerExpr.java │ │ │ │ ├── MemberValuePair.java │ │ │ │ └── SingleMemberAnnotationExpr.java │ │ │ ├── SymbolReference.java │ │ │ ├── Refactorizable.java │ │ │ ├── ConstructorSymbolData.java │ │ │ ├── ScopeAwareUtil.java │ │ │ ├── ScopeAware.java │ │ │ ├── FieldSymbolData.java │ │ │ ├── MethodSymbolData.java │ │ │ ├── LineComment.java │ │ │ ├── BlockComment.java │ │ │ ├── SymbolDataAware.java │ │ │ ├── Comment.java │ │ │ └── Refactorization.java │ │ │ ├── tags │ │ │ ├── package-info.java │ │ │ └── TagsParserConstants.java │ │ │ ├── util │ │ │ └── package-info.java │ │ │ ├── actions │ │ │ ├── ActionType.java │ │ │ ├── FormatterHelper.java │ │ │ ├── RemoveAction.java │ │ │ └── Action.java │ │ │ ├── comparators │ │ │ ├── package-info.java │ │ │ ├── TypeDeclarationComparator.java │ │ │ ├── EmptyMemberDeclarationComparator.java │ │ │ ├── InitializerDeclarationComparator.java │ │ │ ├── ImportDeclarationComparator.java │ │ │ ├── ClassOrInterfaceDeclarationComparator.java │ │ │ ├── AnnotationExprComparator.java │ │ │ ├── EnumConstantComparator.java │ │ │ ├── TypeDeclarationNameComparator.java │ │ │ ├── VariableDeclaratorComparator.java │ │ │ ├── EnumConstantDeclarationComparator.java │ │ │ ├── AnnotationMemberDeclarationComparator.java │ │ │ ├── ClassOrInterfaceTypeComparator.java │ │ │ ├── FieldDeclarationComparator.java │ │ │ ├── MethodDeclarationComparator.java │ │ │ ├── ConstructorDeclarationComparator.java │ │ │ ├── BodyDeclaratorComparator.java │ │ │ └── CompilationUnitComparator.java │ │ │ ├── merger │ │ │ └── package-info.java │ │ │ ├── visitors │ │ │ └── package-info.java │ │ │ ├── CleanerTokenManager.java │ │ │ ├── JavadocManager.java │ │ │ └── constraints │ │ │ └── NodesPerLineConstraint.java │ ├── license-header.txt │ └── javadoc │ │ └── overview.html └── test │ ├── resources │ ├── package-info.txt │ ├── lambda-failure-conditional.txt │ ├── lambda-failure-conditional2.txt │ ├── comments.txt │ ├── lambda-failure-conditional3.txt │ ├── lambdacast-error.txt │ ├── multipleLinesBetweenImports.txt │ ├── methodReferenceFailureNodePositions.txt │ ├── javadocFailure.txt │ ├── bigCommentBug.txt │ ├── multipleLinesBetweenParameters.txt │ └── lambda.txt │ └── java │ └── org │ └── walkmod │ └── javalang │ ├── ast │ ├── VoidVisitorAdapterTest.java │ ├── ASTUpdatesTest.java │ ├── CompilationUnitTest.java │ └── DumpVisitorTest.java │ └── javadoclinks │ └── JavadocLinksParserTest.java ├── .gitignore ├── walkmod.xml ├── .travis.yml ├── .cloudbees └── workflows │ └── my-automation.yaml ├── Readme-formatter.txt ├── fixup.sh └── README.asciidoc /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rpau/javalang/HEAD/.DS_Store -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rpau/javalang/HEAD/src/.DS_Store -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rpau/javalang/HEAD/src/main/.DS_Store -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rpau/javalang/HEAD/src/main/java/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /target/ 3 | /*.classpath 4 | /*.project 5 | .idea 6 | *.iml 7 | src/main/*.iml 8 | src/test/*.iml 9 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/javadoclinks/Link.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.javadoclinks; 2 | 3 | public interface Link { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/resources/package-info.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Common package comments :) 3 | */ 4 | @VisibleForTesting 5 | package com.example.hello; 6 | 7 | import com.google.common.annotations.VisibleForTesting; -------------------------------------------------------------------------------- /src/test/resources/lambda-failure-conditional.txt: -------------------------------------------------------------------------------- 1 | public class A{ 2 | static Predicate isEqual(Object targetRef) { 3 | return (null == targetRef)? Objects::isNull : object -> targetRef.equals(object); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/test/resources/lambda-failure-conditional2.txt: -------------------------------------------------------------------------------- 1 | public class A{ 2 | static Predicate isEqual(Object targetRef) { 3 | return (null == targetRef)? object -> targetRef.equals(object) : Objects::isNull; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/test/resources/comments.txt: -------------------------------------------------------------------------------- 1 | public class StepImpl { 2 | //comment 3 | public void stepWithComments() { 4 | // comment 5 | // comment 6 | /* 7 | comment 8 | */ 9 | } 10 | } -------------------------------------------------------------------------------- /src/test/resources/lambda-failure-conditional3.txt: -------------------------------------------------------------------------------- 1 | public class A{ 2 | static Predicate isEqual(Object targetRef) { 3 | return (object -> targetRef.equals(object) != null)? object -> targetRef.equals(object) : Objects::isNull; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/test/resources/lambdacast-error.txt: -------------------------------------------------------------------------------- 1 | public class A{ 2 | 3 | 4 | static final Comparator DATE_ORDER = 5 | (Comparator & Serializable) (date1, date2) -> { 6 | return Long.compare(date1.toEpochDay(), date2.toEpochDay()); 7 | }; 8 | } -------------------------------------------------------------------------------- /src/test/resources/multipleLinesBetweenImports.txt: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import org.walkmod.javalang.ASTManager; 7 | 8 | 9 | import org.walkmod.javalang.ast.CompilationUnit; 10 | 11 | public class A { 12 | } -------------------------------------------------------------------------------- /walkmod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | src/main/license-header.txt 5 | reformat 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | script: 5 | - mvn test 6 | env: 7 | global: 8 | - secure: DMYXwwHaehOhH9j1082yx3n9CCXgH6Vkm8Nb4A1zYGQNhz9q1d8VsJvjpVThYe6NAxjPKvyUakyXdxGjGELyO4eJ8k7emHEy9ngeQeqluzMnAuTL2IG+UUr4GBNg+13F28lVnsvmTjnDPN8KfVyNe/YqlQ0JWd+RJXjN53F7/AU= 9 | 10 | after_script: 11 | - ./fixup.sh 12 | -------------------------------------------------------------------------------- /.cloudbees/workflows/my-automation.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: automation.cloudbees.io/v1alpha1 2 | kind: workflow 3 | name: My automation 4 | 5 | on: 6 | push: 7 | branches: 8 | - '**' 9 | 10 | jobs: 11 | build: 12 | steps: 13 | - uses: cloudbees-io/checkout@v1 14 | - name: mvn test 15 | uses: docker://maven:3.9.5-eclipse-temurin-11 16 | shell: sh 17 | run: | 18 | mvn test 19 | - name: Scan with SonarQube bundled action 20 | uses: cloudbees-io/sonarqube-bundled-sast-scan-code@v1 21 | -------------------------------------------------------------------------------- /src/test/resources/methodReferenceFailureNodePositions.txt: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap6; 2 | 3 | import static java.util.stream.Collectors.*; 4 | import static lambdasinaction.chap6.Dish.menu; 5 | 6 | public class Reducing { 7 | 8 | public static void main(String ... args) { 9 | System.out.println("Total calories in menu: " + calculateTotalCaloriesWithMethodReference()); 10 | } 11 | 12 | 13 | private static int calculateTotalCaloriesWithMethodReference() { 14 | return menu.stream().collect(reducing(0, Dish::getCalories, Integer::sum)); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/main/license-header.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | 4 | Walkmod is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | Walkmod is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with Walkmod. If not, see . -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/javadoclinks/FieldLink.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.javadoclinks; 2 | 3 | public class FieldLink implements Link { 4 | 5 | private String className; 6 | 7 | private String name; 8 | 9 | 10 | 11 | public FieldLink(String className, String name) { 12 | this.className = className; 13 | this.name = name; 14 | } 15 | 16 | public String getClassName() { 17 | return className; 18 | } 19 | 20 | public void setClassName(String className) { 21 | this.className = className; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/walkmod/javalang/ast/VoidVisitorAdapterTest.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.ast; 2 | 3 | import java.io.File; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.walkmod.javalang.ASTManager; 8 | import org.walkmod.javalang.visitors.VoidVisitorAdapter; 9 | 10 | public class VoidVisitorAdapterTest { 11 | 12 | class MyVisitor extends VoidVisitorAdapter { 13 | 14 | }; 15 | 16 | @Test 17 | public void testVisit() throws Exception { 18 | File f = new File("src/test/resources/source1.8.txt"); 19 | CompilationUnit cu = ASTManager.parse(f); 20 | Assert.assertNotNull(cu); 21 | VoidVisitorAdapter vva = new MyVisitor(); 22 | 23 | vva.visit(cu, null); 24 | 25 | Assert.assertTrue(true); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/javadocFailure.txt: -------------------------------------------------------------------------------- 1 | * Returns the generic interfaces that this type directly {@code implements}. This method is 2 | * similar but different from {@link Class#getGenericInterfaces()}. For example, {@code new 3 | * TypeToken>() .getGenericInterfaces()} will return a list that contains {@code new 4 | * TypeToken>()} ; while {@code List.class.getGenericInterfaces()} will return an 5 | * array that contains {@code Iterable}, where the {@code T} is the type variable declared by 6 | * interface {@code Iterable}. 7 | * 8 | *

9 | * If this type is a type variable or wildcard, its upper bounds are examined and those that are 10 | * either an interface or upper-bounded only by interfaces are returned. This means that the 11 | * returned types could include type variables too. -------------------------------------------------------------------------------- /Readme-formatter.txt: -------------------------------------------------------------------------------- 1 | src/config/eclipse/formatter: 2 | 3 | eclipse-java-google-style.xml - original googly java style 4 | java.xml - slightly tuned 5 | 6 | 22 | 23 | Format with: 24 | 25 | mvn formatter:format 26 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * Parsers of Java source files. 17 | */ 18 | package org.walkmod.javalang; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST root nodes of Java source files. 17 | */ 18 | package org.walkmod.javalang.ast; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/tags/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST nodes to parse Javadoc tags. 17 | */ 18 | package org.walkmod.javalang.tags; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * Common utilities to process source files. 17 | */ 18 | package org.walkmod.javalang.util; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/actions/ActionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.actions; 16 | 17 | public enum ActionType { 18 | APPEND, REMOVE, REPLACE 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/type/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST nodes for types (e.g methods' type) 17 | */ 18 | package org.walkmod.javalang.ast.type; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST nodes for statements (e.g methods' body) 17 | */ 18 | package org.walkmod.javalang.ast.stmt; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * Identity comparators for AST nodes. 17 | */ 18 | package org.walkmod.javalang.comparators; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/merger/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * Specific merge policies for Java AST nodes. 17 | */ 18 | package org.walkmod.javalang.merger; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/visitors/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * Generic and simple visitors to process source files. 17 | */ 18 | package org.walkmod.javalang.visitors; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST nodes for types' members (e.g methods, fields, other types..). 17 | */ 18 | package org.walkmod.javalang.ast.body; 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /** 16 | * AST nodes for expressions (e.g values applied as arguments in method calls) 17 | */ 18 | package org.walkmod.javalang.ast.expr; 19 | 20 | -------------------------------------------------------------------------------- /src/test/java/org/walkmod/javalang/ast/ASTUpdatesTest.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.ast; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.walkmod.javalang.ASTManager; 8 | import org.walkmod.javalang.ast.body.BodyDeclaration; 9 | import org.walkmod.javalang.ast.body.MethodDeclaration; 10 | import org.walkmod.javalang.visitors.VoidVisitorAdapter; 11 | 12 | public class ASTUpdatesTest { 13 | 14 | @Test 15 | public void test() throws Exception { 16 | CompilationUnit cu = ASTManager.parse("public class Foo{ public void bar(){}}"); 17 | VoidVisitorAdapter visitor = new VoidVisitorAdapter() { 18 | public void visit(MethodDeclaration md, Object ctx) { 19 | md.remove(); 20 | } 21 | }; 22 | cu.accept(visitor, null); 23 | 24 | List members = cu.getTypes().get(0).getMembers(); 25 | Assert.assertTrue(members.isEmpty()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /fixup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$TRAVIS_PULL_REQUEST" = false ] ; then 4 | echo 'Skipped build. This is not a pull request' 5 | exit 0 6 | fi 7 | 8 | if [ -z "$TRAVIS_REPO_SLUG" ] 9 | then 10 | echo "There is not TRAVIS_REPO_SLUG defined" 11 | exit 1 12 | fi 13 | 14 | if [ -z "$TRAVIS_PULL_REQUEST_SHA" ] 15 | then 16 | echo "There is not TRAVIS_PULL_REQUEST_SHA defined" 17 | exit 1 18 | fi 19 | 20 | if [ -z "$OCTOPATCH_API_TOKEN" ] ; then 21 | echo "There is not OCTOPATCH_API_TOKEN defined" 22 | exit 1 23 | fi 24 | 25 | REQUEST="curl -X POST -H \"Content-Type: multipart/form-data\"" 26 | FILES=$(find . -type f -name "*.patch") 27 | if [ -z "$FILES" ] 28 | then 29 | echo "Perfect! There are not patch files" 30 | exit 0 31 | fi 32 | 33 | for FILE in $FILES 34 | do 35 | REQUEST+=" -F \"data=@$FILE\"" 36 | done 37 | 38 | REQUEST+=" -H \"Authorization: $OCTOPATCH_API_TOKEN\" api.octopatch.io/api/pulls/$TRAVIS_REPO_SLUG/$TRAVIS_PULL_REQUEST/$TRAVIS_PULL_REQUEST_SHA" 39 | eval $REQUEST -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/SymbolReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | public interface SymbolReference extends ScopeAware { 18 | 19 | public SymbolDefinition getSymbolDefinition(); 20 | 21 | public void setSymbolDefinition(SymbolDefinition symbolDefinition); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Javalang API 2.0 Overview 5 | 6 | 7 |

This package contains a Java 1.7 Parser with AST (Abstract 8 | Syntax Tree) generation and visitor support. The AST records the 9 | source code structure, javadoc and comments.

10 |

11 | This parser is based on Sreenivasa Viswanadha's Java 1.5 parser. The 12 | project was originally hosted at http://code.google.com/p/javaparser/ 14 | but seemed dead. This repository at https://github.com/rpau/javalang 16 | keeps the code alive for walkmod because it is modified according the walkmod needs. 19 |

20 |

Javadoc texts can be also parseable to process Javadoc tags.

21 |

The Java AST nodes can be merged to simplify code 22 | transformations, using a semantic merge engine.

23 | 24 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/Refactorizable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | public interface Refactorizable { 18 | 19 | /** 20 | * Renames the element and all their usages if the newName has no conflicts. 21 | * @param newName new name to set 22 | * @return if the rename has been applied successfully. 23 | */ 24 | public boolean rename(String newName); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/walkmod/javalang/ast/CompilationUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.ast; 2 | 3 | import org.junit.Test; 4 | import org.walkmod.javalang.ASTManager; 5 | 6 | import java.io.File; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class CompilationUnitTest { 11 | 12 | @Test 13 | public void shouldReturnCorrectFilenameForClass() throws Exception { 14 | final File packageInfoFile = new File(getClass().getClassLoader() 15 | .getResource("test.txt").getFile()); 16 | final CompilationUnit cu = ASTManager.parse(packageInfoFile); 17 | 18 | assertEquals("IntMath", cu.getSimpleName()); 19 | assertEquals("com/google/common/math/IntMath.java", cu.getFileName()); 20 | } 21 | 22 | @Test 23 | public void shouldReturnCorrectFilenameForPackageInfoFile() throws Exception { 24 | final File packageInfoFile = new File(getClass().getClassLoader() 25 | .getResource("package-info.txt").getFile()); 26 | final CompilationUnit cu = ASTManager.parse(packageInfoFile); 27 | 28 | assertEquals("package-info", cu.getSimpleName()); 29 | assertEquals("com/example/hello/package-info.java", cu.getFileName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/TypeDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.TypeDeclaration; 20 | 21 | public class TypeDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(TypeDeclaration t1, TypeDeclaration t2) { 25 | return t1.getName().compareTo(t2.getName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/EmptyMemberDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.EmptyMemberDeclaration; 20 | 21 | public class EmptyMemberDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(EmptyMemberDeclaration o1, EmptyMemberDeclaration o2) { 25 | return 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/InitializerDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.InitializerDeclaration; 20 | 21 | public class InitializerDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(InitializerDeclaration o1, InitializerDeclaration o2) { 25 | return -1; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/bigCommentBug.txt: -------------------------------------------------------------------------------- 1 | package foo; 2 | 3 | /* 4 | import static de.pixelboxx.pb.lang.ObjectUtil.nonNull; 5 | // 6 | import static de.pixelboxx.pb.lang.ObjectUtil.safeEquals; 7 | // 8 | // 9 | import static java.lang.Math.max; 10 | import static java.lang.Math.min; 11 | import static nads.pixelbox.lang.StringUtil.repeat; 12 | // 13 | 14 | // 15 | import java.util.ArrayDeque; 16 | import java.util.Deque; 17 | import java.util.Iterator; 18 | import java.util.NoSuchElementException; 19 | // 20 | // 21 | import java.util.Map; 22 | // 23 | 24 | import javax.annotation.CheckReturnValue; 25 | // 26 | import javax.annotation.Nullable; 27 | // 28 | // 29 | 30 | import com.google.common.collect.Iterators; 31 | // 32 | // 33 | 34 | // 35 | import nads.pixelbox.block.UnaryProc; 36 | // 37 | import nads.pixelbox.block.BinaryProc; 38 | // 39 | */ 40 | 41 | public class Bar{} -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/ConstructorSymbolData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import java.lang.reflect.Constructor; 18 | 19 | /** 20 | * This is the SymbolData used for representing Constructors. 21 | * @author rpau 22 | * 23 | */ 24 | public interface ConstructorSymbolData extends SymbolData { 25 | /** 26 | * The related constructor signature 27 | * @return the constructor signature 28 | */ 29 | public Constructor getConstructor(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/ImportDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.ImportDeclaration; 20 | 21 | public class ImportDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(ImportDeclaration id1, ImportDeclaration id2) { 25 | return id1.getName().toString().compareTo(id2.getName().toString()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/javadoclinks/JavadocLinkParserConstants.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JavaCC: Do not edit this line. JavadocLinkParserConstants.java */ 2 | package org.walkmod.javalang.javadoclinks; 3 | 4 | 5 | /** 6 | * Token literal values and constants. 7 | * Generated by org.javacc.parser.OtherFilesGen#start() 8 | */ 9 | public interface JavadocLinkParserConstants { 10 | 11 | /** End of File. */ 12 | int EOF = 0; 13 | /** RegularExpression Id. */ 14 | int OPENPAR = 1; 15 | /** RegularExpression Id. */ 16 | int CLOSEPAR = 2; 17 | /** RegularExpression Id. */ 18 | int SEPARATOR = 3; 19 | /** RegularExpression Id. */ 20 | int COMMA = 4; 21 | /** RegularExpression Id. */ 22 | int DOT = 5; 23 | /** RegularExpression Id. */ 24 | int IDENTIFIER = 6; 25 | /** RegularExpression Id. */ 26 | int LETTER = 7; 27 | /** RegularExpression Id. */ 28 | int PART_LETTER = 8; 29 | /** RegularExpression Id. */ 30 | int SPACE = 9; 31 | 32 | /** Lexical state. */ 33 | int DEFAULT = 0; 34 | 35 | /** Literal token values. */ 36 | String[] tokenImage = {"", "\"(\"", "\")\"", "\"#\"", "\",\"", "\".\"", "", "", 37 | "", "",}; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/walkmod/javalang/ast/DumpVisitorTest.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.ast; 2 | 3 | import junit.framework.Assert; 4 | 5 | import org.junit.Test; 6 | import org.walkmod.javalang.ASTManager; 7 | import org.walkmod.javalang.ast.body.MethodDeclaration; 8 | import org.walkmod.javalang.ast.body.Parameter; 9 | import org.walkmod.javalang.ast.body.VariableDeclaratorId; 10 | import org.walkmod.javalang.ast.type.PrimitiveType; 11 | import org.walkmod.javalang.ast.type.PrimitiveType.Primitive; 12 | 13 | public class DumpVisitorTest { 14 | 15 | 16 | @Test 17 | public void testAddParam() throws Exception { 18 | CompilationUnit cu = ASTManager.parse("public class A { public void foo(int x){}}"); 19 | MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0); 20 | md.getParameters().add(new Parameter(new PrimitiveType(Primitive.Int), new VariableDeclaratorId("y"))); 21 | String s = md.toString(); 22 | Assert.assertTrue(s.indexOf('\n') == -1); 23 | } 24 | 25 | @Test 26 | public void testIssue13() throws Exception { 27 | CompilationUnit cu = ASTManager.parse("public enum A{B{};}"); 28 | System.out.println(cu.toString()); 29 | Assert.assertTrue(true); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/CleanerTokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang; 16 | 17 | public class CleanerTokenManager extends ASTParserTokenManager { 18 | 19 | public CleanerTokenManager(JavaCharStream stream) { 20 | super(stream); 21 | } 22 | 23 | protected Token jjFillToken() { 24 | Token token = super.jjFillToken(); 25 | token.beginLine = 0; 26 | token.endLine = 0; 27 | token.beginColumn = 0; 28 | token.endColumn = 0; 29 | return token; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/ClassOrInterfaceDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.ClassOrInterfaceDeclaration; 20 | 21 | public class ClassOrInterfaceDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(ClassOrInterfaceDeclaration o1, ClassOrInterfaceDeclaration o2) { 25 | return o1.getName().compareTo(o2.getName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/AnnotationExprComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.expr.AnnotationExpr; 20 | 21 | public class AnnotationExprComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(AnnotationExpr an1, AnnotationExpr an2) { 25 | if (an1.getName().toString().equals(an2.getName().toString())) { 26 | return 0; 27 | } 28 | return -1; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/EnumConstantComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.EnumConstantDeclaration; 20 | 21 | public class EnumConstantComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(EnumConstantDeclaration o1, EnumConstantDeclaration o2) { 25 | if (o1.getName().equals(o2.getName())) { 26 | return 0; 27 | } 28 | return -1; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/TypeDeclarationNameComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.TypeDeclaration; 20 | 21 | public class TypeDeclarationNameComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(TypeDeclaration o1, TypeDeclaration o2) { 25 | if (o1.getName() == null || o2.getName() == null) { 26 | throw new IllegalArgumentException(o1.getClass().getName() + " must have a name. " + o1 + "-" + o2); 27 | } 28 | return o1.getName().compareTo(o2.getName()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/LiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | 19 | /** 20 | * @author Julio Vilmar Gesser 21 | */ 22 | public abstract class LiteralExpr extends Expression { 23 | 24 | public LiteralExpr() {} 25 | 26 | public LiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn) { 27 | super(beginLine, beginColumn, endLine, endColumn); 28 | } 29 | 30 | @Override 31 | public abstract LiteralExpr clone() throws CloneNotSupportedException; 32 | 33 | @Override 34 | public boolean removeChild(Node child) { 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/ScopeAwareUtil.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.ast; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | /** 8 | * Common implementations of {@link ScopeAware} methods for delegation. 9 | */ 10 | public class ScopeAwareUtil { 11 | private ScopeAwareUtil() {} 12 | 13 | public static ScopeAware findParentScope(Node n) { 14 | Node parent = n.getParentNode(); 15 | while (parent != null && !(parent instanceof ScopeAware)) { 16 | parent = parent.getParentNode(); 17 | } 18 | return parent != null ? (ScopeAware) parent : null; 19 | } 20 | 21 | public static Map getVariableDefinitions(Node n) { 22 | final ScopeAware scope = findParentScope(n); 23 | return scope != null ? scope.getVariableDefinitions() : new HashMap(); 24 | } 25 | 26 | public static Map> getMethodDefinitions(Node n) { 27 | final ScopeAware scope = findParentScope(n); 28 | return scope != null ? scope.getMethodDefinitions() : new HashMap>(); 29 | } 30 | 31 | public static Map getTypeDefinitions(Node n) { 32 | final ScopeAware scope = findParentScope(n); 33 | return scope != null ? scope.getTypeDefinitions() : new HashMap(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/actions/FormatterHelper.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.actions; 2 | 3 | public class FormatterHelper { 4 | 5 | public static String indent(String text, String indentation, char indentationChar, int indentationLevel, 6 | int indentationSize, boolean requiresExtraIndentationOnFirstLine) { 7 | 8 | String result = text; 9 | 10 | StringBuilder sb = new StringBuilder(); 11 | String[] lines = text.split("\n"); 12 | 13 | String theoricalIndentationText = lines[0].substring(0, indentationSize * indentationLevel); 14 | 15 | if (requiresExtraIndentationOnFirstLine) { 16 | for (int i = 0; i < indentationSize; i++) { 17 | sb.append(indentationChar); 18 | } 19 | } 20 | sb.append(lines[0].substring(indentationSize * indentationLevel)); 21 | 22 | 23 | for (int i = 1; i < lines.length; i++) { 24 | String line = lines[i]; 25 | 26 | if (indentation.length() > 0) { 27 | //we replace the supposed indentation chars at indentation level for the existing ones. 28 | line = line.replaceFirst(theoricalIndentationText, indentation); 29 | } 30 | 31 | sb.append('\n').append(line); 32 | } 33 | 34 | if (text.endsWith("\n")) { 35 | sb.append('\n'); 36 | } 37 | result = sb.toString(); 38 | 39 | return result; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/VariableDeclaratorComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.VariableDeclarator; 20 | 21 | public class VariableDeclaratorComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(VariableDeclarator local, VariableDeclarator remote) { 25 | if (local == null && remote == null) { 26 | return 0; 27 | } 28 | if (local == null || remote == null) { 29 | return -1; 30 | } else { 31 | return local.getId().getName().compareTo(remote.getId().getName()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/ScopeAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public interface ScopeAware { 21 | 22 | /** 23 | * Gets the available variables 24 | * @return the available variables 25 | */ 26 | public Map getVariableDefinitions(); 27 | 28 | 29 | /** 30 | * Gets the available variables 31 | * @return the available variables 32 | */ 33 | public Map getTypeDefinitions(); 34 | 35 | 36 | 37 | /** 38 | * Gets the available methods 39 | * @return the available variables 40 | */ 41 | public Map> getMethodDefinitions(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/EnumConstantDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.EnumConstantDeclaration; 20 | 21 | public class EnumConstantDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(EnumConstantDeclaration o1, EnumConstantDeclaration o2) { 25 | if (o1.getName() == null || o2.getName() == null) { 26 | throw new IllegalArgumentException( 27 | "EnumConstantDeclaration must have a name in order to be compared " + o1 + "-" + o2); 28 | } 29 | return o1.getName().compareTo(o2.getName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/AnnotationMemberDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.body.AnnotationMemberDeclaration; 20 | 21 | public class AnnotationMemberDeclarationComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(AnnotationMemberDeclaration an1, AnnotationMemberDeclaration an2) { 25 | if (an1.getName() == null || an2.getName() == null) { 26 | throw new IllegalArgumentException( 27 | "Annotation member must have a name in order to compare them" + an1 + "-" + an2); 28 | } 29 | return an1.getName().compareTo(an2.getName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/JavadocManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang; 16 | 17 | import java.io.ByteArrayInputStream; 18 | import java.io.InputStream; 19 | import java.util.List; 20 | 21 | import org.walkmod.javalang.ast.body.JavadocTag; 22 | import org.walkmod.javalang.tags.TagsParser; 23 | 24 | public class JavadocManager { 25 | 26 | public static List parse(String content) throws Exception { 27 | List javadocTags = null; 28 | if (content != null) { 29 | InputStream is = new ByteArrayInputStream(content.getBytes()); 30 | try { 31 | javadocTags = TagsParser.parse(is); 32 | } finally { 33 | is.close(); 34 | } 35 | } 36 | return javadocTags; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/ClassOrInterfaceTypeComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | 19 | import org.walkmod.javalang.ast.type.ClassOrInterfaceType; 20 | 21 | public class ClassOrInterfaceTypeComparator implements Comparator { 22 | 23 | @Override 24 | public int compare(ClassOrInterfaceType o1, ClassOrInterfaceType o2) { 25 | if (o1 == null && o2 == null) { 26 | return 0; 27 | } 28 | if (o1 == null && o2 != null) { 29 | return 1; 30 | } 31 | if (o1 != null && o2 == null) { 32 | return -1; 33 | } 34 | // o1 != null && o2 != null 35 | int scope = compare(o1.getScope(), o2.getScope()); 36 | if (scope == 0) { 37 | return o1.getName().compareTo(o2.getName()); 38 | } 39 | return scope; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/FieldDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | 16 | package org.walkmod.javalang.comparators; 17 | 18 | import java.util.Comparator; 19 | import java.util.List; 20 | 21 | import org.walkmod.javalang.ast.body.FieldDeclaration; 22 | import org.walkmod.javalang.ast.body.VariableDeclarator; 23 | 24 | public class FieldDeclarationComparator implements Comparator { 25 | 26 | @Override 27 | public int compare(FieldDeclaration fd1, FieldDeclaration fd2) { 28 | if (fd1.getType().equals(fd2.getType())) { 29 | List vds = fd1.getVariables(); 30 | List vds2 = fd2.getVariables(); 31 | if (vds == null || vds.size() == 0 || vds2 == null || vds2.size() == 0) { 32 | return -1; 33 | } 34 | if (vds.size() == vds2.size()) { 35 | if (vds.containsAll(vds2)) { 36 | return 0; 37 | } 38 | } 39 | } 40 | return -1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/javadoclinks/MethodLink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.javadoclinks; 16 | 17 | import java.util.List; 18 | 19 | public class MethodLink implements Link { 20 | 21 | private String className; 22 | 23 | private String name; 24 | 25 | private List arguments; 26 | 27 | public MethodLink(String className, String name, List arguments) { 28 | this.className = className; 29 | this.name = name; 30 | this.arguments = arguments; 31 | } 32 | 33 | public String getClassName() { 34 | return className; 35 | } 36 | 37 | public void setClassName(String className) { 38 | this.className = className; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public List getArguments() { 50 | return arguments; 51 | } 52 | 53 | public void setArguments(List arguments) { 54 | this.arguments = arguments; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/resources/multipleLinesBetweenParameters.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.common.base; 18 | 19 | import com.google.gwt.user.client.rpc.SerializationException; 20 | import com.google.gwt.user.client.rpc.SerializationStreamReader; 21 | import com.google.gwt.user.client.rpc.SerializationStreamWriter; 22 | 23 | /** 24 | * GWT serialization logic for {@link PairwiseEquivalence}. 25 | * 26 | * @author Kedar Kanitkar 27 | */ 28 | public class PairwiseEquivalence_CustomFieldSerializer { 29 | 30 | private PairwiseEquivalence_CustomFieldSerializer() {} 31 | 32 | public static void deserialize(SerializationStreamReader reader, 33 | PairwiseEquivalence instance) {} 34 | 35 | public static PairwiseEquivalence instantiate(SerializationStreamReader reader) 36 | throws SerializationException { 37 | return create((Equivalence) reader.readObject()); 38 | } 39 | 40 | private static PairwiseEquivalence create(Equivalence elementEquivalence) { 41 | return new PairwiseEquivalence(elementEquivalence); 42 | } 43 | 44 | public static void serialize(SerializationStreamWriter writer, PairwiseEquivalence instance) 45 | throws SerializationException { 46 | writer.writeObject(instance.elementEquivalence); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/Statement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.SymbolData; 22 | import org.walkmod.javalang.ast.SymbolDataAware; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public abstract class Statement extends Node implements SymbolDataAware { 28 | 29 | private SymbolData symbolData; 30 | 31 | public Statement() {} 32 | 33 | public Statement(int beginLine, int beginColumn, int endLine, int endColumn) { 34 | super(beginLine, beginColumn, endLine, endColumn); 35 | } 36 | 37 | @Override 38 | public SymbolData getSymbolData() { 39 | return symbolData; 40 | } 41 | 42 | @Override 43 | public void setSymbolData(SymbolData symbolData) { 44 | this.symbolData = symbolData; 45 | } 46 | 47 | @Override 48 | public abstract Statement clone() throws CloneNotSupportedException; 49 | 50 | @Override 51 | public List getChildren() { 52 | return new LinkedList(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.SymbolData; 22 | import org.walkmod.javalang.ast.SymbolDataAware; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public abstract class Expression extends Node implements SymbolDataAware { 28 | 29 | private SymbolData symbolData; 30 | 31 | public Expression() {} 32 | 33 | public Expression(int beginLine, int beginColumn, int endLine, int endColumn) { 34 | super(beginLine, beginColumn, endLine, endColumn); 35 | } 36 | 37 | @Override 38 | public SymbolData getSymbolData() { 39 | return symbolData; 40 | } 41 | 42 | @Override 43 | public void setSymbolData(SymbolData symbolData) { 44 | this.symbolData = symbolData; 45 | } 46 | 47 | @Override 48 | public abstract Expression clone() throws CloneNotSupportedException; 49 | 50 | @Override 51 | public List getChildren() { 52 | return new LinkedList(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/LongLiteralMinValueExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public final class LongLiteralMinValueExpr extends LongLiteralExpr { 24 | 25 | public LongLiteralMinValueExpr() { 26 | super(MIN_VALUE); 27 | } 28 | 29 | public LongLiteralMinValueExpr(int beginLine, int beginColumn, int endLine, int endColumn) { 30 | super(beginLine, beginColumn, endLine, endColumn, MIN_VALUE); 31 | } 32 | 33 | @Override 34 | public R accept(GenericVisitor v, A arg) { 35 | if (!check()) { 36 | return null; 37 | } 38 | return v.visit(this, arg); 39 | } 40 | 41 | @Override 42 | public void accept(VoidVisitor v, A arg) { 43 | if (check()) { 44 | v.visit(this, arg); 45 | } 46 | } 47 | 48 | @Override 49 | public LongLiteralMinValueExpr clone() throws CloneNotSupportedException { 50 | return new LongLiteralMinValueExpr(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/FieldSymbolData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /* 16 | * Copyright (C) 2015 Raquel Pau and Albert Coroleu. 17 | * 18 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 19 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 20 | * the License, or (at your option) any later version. 21 | * 22 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 23 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 24 | * General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 27 | * not, see . 28 | */ 29 | package org.walkmod.javalang.ast; 30 | 31 | import java.lang.reflect.Field; 32 | 33 | /** 34 | * This is the SymbolData used for representing Fields. 35 | * @author rpau 36 | * 37 | */ 38 | public interface FieldSymbolData extends SymbolData { 39 | 40 | /** 41 | * The related field signature 42 | * @return the field signature 43 | */ 44 | public Field getField(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/IntegerLiteralMinValueExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public final class IntegerLiteralMinValueExpr extends IntegerLiteralExpr { 24 | 25 | public IntegerLiteralMinValueExpr() { 26 | super(MIN_VALUE); 27 | } 28 | 29 | public IntegerLiteralMinValueExpr(int beginLine, int beginColumn, int endLine, int endColumn) { 30 | super(beginLine, beginColumn, endLine, endColumn, MIN_VALUE); 31 | } 32 | 33 | @Override 34 | public R accept(GenericVisitor v, A arg) { 35 | if (!check()) { 36 | return null; 37 | } 38 | return v.visit(this, arg); 39 | } 40 | 41 | @Override 42 | public void accept(VoidVisitor v, A arg) { 43 | if (check()) { 44 | v.visit(this, arg); 45 | } 46 | } 47 | 48 | @Override 49 | public IntegerLiteralMinValueExpr clone() throws CloneNotSupportedException { 50 | return new IntegerLiteralMinValueExpr(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/CharLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public final class CharLiteralExpr extends StringLiteralExpr { 24 | 25 | public CharLiteralExpr() {} 26 | 27 | public CharLiteralExpr(String value) { 28 | super(value); 29 | } 30 | 31 | public CharLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn, String value) { 32 | super(beginLine, beginColumn, endLine, endColumn, value); 33 | } 34 | 35 | @Override 36 | public R accept(GenericVisitor v, A arg) { 37 | if (!check()) { 38 | return null; 39 | } 40 | return v.visit(this, arg); 41 | } 42 | 43 | @Override 44 | public void accept(VoidVisitor v, A arg) { 45 | if (check()) { 46 | v.visit(this, arg); 47 | } 48 | } 49 | 50 | @Override 51 | public CharLiteralExpr clone() throws CloneNotSupportedException { 52 | return new CharLiteralExpr(getValue()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/MethodSymbolData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /* 16 | * Copyright (C) 2015 Raquel Pau and Albert Coroleu. 17 | * 18 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 19 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 20 | * the License, or (at your option) any later version. 21 | * 22 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 23 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 24 | * General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 27 | * not, see . 28 | */ 29 | package org.walkmod.javalang.ast; 30 | 31 | import java.lang.reflect.Method; 32 | 33 | /** 34 | * This is the SymbolData used for representing Methods. 35 | * @author rpau 36 | * 37 | */ 38 | public interface MethodSymbolData extends SymbolData { 39 | 40 | /** 41 | * The related method signature. 42 | * @return the method signature. 43 | */ 44 | public Method getMethod(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/DoubleLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public final class DoubleLiteralExpr extends StringLiteralExpr { 24 | 25 | public DoubleLiteralExpr() {} 26 | 27 | public DoubleLiteralExpr(String value) { 28 | super(value); 29 | } 30 | 31 | public DoubleLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn, String value) { 32 | super(beginLine, beginColumn, endLine, endColumn, value); 33 | } 34 | 35 | @Override 36 | public R accept(GenericVisitor v, A arg) { 37 | if (!check()) { 38 | return null; 39 | } 40 | return v.visit(this, arg); 41 | } 42 | 43 | @Override 44 | public void accept(VoidVisitor v, A arg) { 45 | if (check()) { 46 | v.visit(this, arg); 47 | } 48 | } 49 | 50 | @Override 51 | public DoubleLiteralExpr clone() throws CloneNotSupportedException { 52 | return new DoubleLiteralExpr(getValue()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/JavadocComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import org.walkmod.javalang.ast.Comment; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class JavadocComment extends Comment { 25 | 26 | public JavadocComment() {} 27 | 28 | public JavadocComment(String content) { 29 | super(content); 30 | } 31 | 32 | public JavadocComment(int beginLine, int beginColumn, int endLine, int endColumn, String content) { 33 | super(beginLine, beginColumn, endLine, endColumn, content); 34 | } 35 | 36 | @Override 37 | public R accept(GenericVisitor v, A arg) { 38 | if (!check()) { 39 | return null; 40 | } 41 | return v.visit(this, arg); 42 | } 43 | 44 | @Override 45 | public void accept(VoidVisitor v, A arg) { 46 | if (check()) { 47 | v.visit(this, arg); 48 | } 49 | } 50 | 51 | @Override 52 | public JavadocComment clone() throws CloneNotSupportedException { 53 | return new JavadocComment(getContent()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/NullLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class NullLiteralExpr extends LiteralExpr { 25 | 26 | public NullLiteralExpr() {} 27 | 28 | public NullLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn) { 29 | super(beginLine, beginColumn, endLine, endColumn); 30 | } 31 | 32 | @Override 33 | public R accept(GenericVisitor v, A arg) { 34 | if (!check()) { 35 | return null; 36 | } 37 | return v.visit(this, arg); 38 | } 39 | 40 | @Override 41 | public void accept(VoidVisitor v, A arg) { 42 | if (check()) { 43 | v.visit(this, arg); 44 | } 45 | } 46 | 47 | @Override 48 | public boolean replaceChildNode(Node oldChild, Node newChild) { 49 | return false; 50 | } 51 | 52 | @Override 53 | public NullLiteralExpr clone() throws CloneNotSupportedException { 54 | return new NullLiteralExpr(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/EmptyTypeDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public final class EmptyTypeDeclaration extends TypeDeclaration { 24 | 25 | public EmptyTypeDeclaration() {} 26 | 27 | public EmptyTypeDeclaration(JavadocComment javaDoc) { 28 | super(null, javaDoc, 0, null, null); 29 | } 30 | 31 | public EmptyTypeDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, JavadocComment javaDoc) { 32 | super(beginLine, beginColumn, endLine, endColumn, null, javaDoc, 0, null, null); 33 | } 34 | 35 | @Override 36 | public R accept(GenericVisitor v, A arg) { 37 | if (!check()) { 38 | return null; 39 | } 40 | return v.visit(this, arg); 41 | } 42 | 43 | @Override 44 | public void accept(VoidVisitor v, A arg) { 45 | if (check()) { 46 | v.visit(this, arg); 47 | } 48 | } 49 | 50 | @Override 51 | public EmptyTypeDeclaration clone() throws CloneNotSupportedException { 52 | return new EmptyTypeDeclaration(clone(getJavaDoc())); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/LineComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | *

22 | * AST node that represent line comments. 23 | *

24 | * Line comments are started with "//" and finish at the end of the line ("\n"). 25 | * 26 | * @author Julio Vilmar Gesser 27 | */ 28 | public final class LineComment extends Comment { 29 | 30 | public LineComment() {} 31 | 32 | public LineComment(String content) { 33 | super(content); 34 | } 35 | 36 | public LineComment(int beginLine, int beginColumn, int endLine, int endColumn, String content) { 37 | super(beginLine, beginColumn, endLine, endColumn, content); 38 | } 39 | 40 | @Override 41 | public R accept(GenericVisitor v, A arg) { 42 | if (!check()) { 43 | return null; 44 | } 45 | return v.visit(this, arg); 46 | } 47 | 48 | @Override 49 | public
void accept(VoidVisitor v, A arg) { 50 | if (check()) { 51 | v.visit(this, arg); 52 | } 53 | } 54 | 55 | @Override 56 | public LineComment clone() throws CloneNotSupportedException { 57 | return new LineComment(getContent()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/EmptyStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class EmptyStmt extends Statement { 25 | 26 | public EmptyStmt() {} 27 | 28 | public EmptyStmt(int beginLine, int beginColumn, int endLine, int endColumn) { 29 | super(beginLine, beginColumn, endLine, endColumn); 30 | } 31 | 32 | @Override 33 | public boolean removeChild(Node child) { 34 | return false; 35 | } 36 | 37 | @Override 38 | public R accept(GenericVisitor v, A arg) { 39 | if (!check()) { 40 | return null; 41 | } 42 | return v.visit(this, arg); 43 | } 44 | 45 | @Override 46 | public void accept(VoidVisitor v, A arg) { 47 | if (check()) { 48 | v.visit(this, arg); 49 | } 50 | } 51 | 52 | @Override 53 | public boolean replaceChildNode(Node oldChild, Node newChild) { 54 | return false; 55 | } 56 | 57 | @Override 58 | public EmptyStmt clone() throws CloneNotSupportedException { 59 | return new EmptyStmt(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/BlockComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | *

22 | * AST node that represent block comments. 23 | *

24 | * Block comments can has multi lines and are delimited by "/*" and "*/". 25 | * 26 | * @author Julio Vilmar Gesser 27 | */ 28 | public final class BlockComment extends Comment { 29 | 30 | public BlockComment() {} 31 | 32 | public BlockComment(String content) { 33 | super(content); 34 | } 35 | 36 | public BlockComment(int beginLine, int beginColumn, int endLine, int endColumn, String content) { 37 | super(beginLine, beginColumn, endLine, endColumn, content); 38 | } 39 | 40 | @Override 41 | public R accept(GenericVisitor v, A arg) { 42 | if (!check()) { 43 | return null; 44 | } 45 | return v.visit(this, arg); 46 | } 47 | 48 | @Override 49 | public
void accept(VoidVisitor v, A arg) { 50 | if (check()) { 51 | v.visit(this, arg); 52 | } 53 | } 54 | 55 | @Override 56 | public BlockComment clone() throws CloneNotSupportedException { 57 | return new BlockComment(getContent()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/constraints/NodesPerLineConstraint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.constraints; 16 | 17 | import java.util.HashSet; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.modelchecker.Constraint; 21 | 22 | public class NodesPerLineConstraint implements Constraint { 23 | 24 | private HashSet segments = new HashSet(); 25 | 26 | public NodesPerLineConstraint() {} 27 | 28 | public void addLine(int beginLine, int endLine) { 29 | 30 | for (int i = beginLine; i <= endLine; i++) { 31 | segments.add(i); 32 | } 33 | } 34 | 35 | public void addLine(int lineNumber) { 36 | segments.add(lineNumber); 37 | } 38 | 39 | @Override 40 | public boolean isConstrained(Node o) { 41 | if (o.isNewNode()) { 42 | return false; 43 | } 44 | int beginLine = o.getBeginLine(); 45 | int endLine = o.getEndLine(); 46 | 47 | if (segments.contains(beginLine) && segments.contains(endLine)) { 48 | return false; 49 | } 50 | boolean includesAChildrenNode = false; 51 | for (int i = beginLine; i <= endLine && !includesAChildrenNode; i++) { 52 | includesAChildrenNode = segments.contains(i); 53 | } 54 | return !includesAChildrenNode; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/SymbolDataAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /* 16 | * Copyright (C) 2015 Raquel Pau and Albert Coroleu. 17 | * 18 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 19 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 20 | * the License, or (at your option) any later version. 21 | * 22 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 23 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 24 | * General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 27 | * not, see . 28 | */ 29 | package org.walkmod.javalang.ast; 30 | 31 | public interface SymbolDataAware { 32 | 33 | /** 34 | * Returns the symbol data related to a given node. It is null if the node value 35 | * is the null literal or does not represent any valid information. In case of 36 | * statements nodes, it corresponds to the returned value, if exists. 37 | * @return the symbol data 38 | */ 39 | public T getSymbolData(); 40 | 41 | /** 42 | * Sets the symbol data from a semantic analyzer. 43 | * @param symbolData the symbol data. 44 | */ 45 | public void setSymbolData(T symbolData); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/actions/RemoveAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.actions; 16 | 17 | import org.walkmod.javalang.ast.LineComment; 18 | import org.walkmod.javalang.ast.Node; 19 | import org.walkmod.javalang.ast.body.TypeDeclaration; 20 | 21 | public class RemoveAction extends Action { 22 | 23 | private int endLine; 24 | 25 | private int endColumn; 26 | 27 | private String text; 28 | 29 | public RemoveAction(int beginLine, int beginPosition, int endLine, int endColumn, Node node) { 30 | super(beginLine, beginPosition, ActionType.REMOVE); 31 | this.endLine = endLine; 32 | this.endColumn = endColumn; 33 | 34 | 35 | this.text = node.toString(); 36 | if (text.endsWith("\n") && node instanceof LineComment) { 37 | text = text.substring(0, text.length() - 1); 38 | this.endColumn--; 39 | } else if (text.endsWith("}") && node instanceof TypeDeclaration) { 40 | this.endColumn++; 41 | } 42 | } 43 | 44 | public String getText() { 45 | return text; 46 | } 47 | 48 | public int getEndLine() { 49 | return endLine; 50 | } 51 | 52 | public void setEndLine(int endLine) { 53 | this.endLine = endLine; 54 | } 55 | 56 | public int getEndColumn() { 57 | return endColumn; 58 | } 59 | 60 | public void setEndColumn(int endColumn) { 61 | this.endColumn = endColumn; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | javalang: Java 8 parser customized for walkmod 2 | ============================================== 3 | 4 | image:https://travis-ci.org/rpau/javalang.svg?branch=master["Build Status", link="https://travis-ci.org/rpau/javalang"] 5 | image:http://walkmod.com/pulls/rpau/javalang/master/status.svg["Build Status", link="http://walkmod.com/rpau"] 6 | 7 | Java 8 parser and Abstract Syntax Tree (AST). Therefore, *lambda expressions*, *reference expressions*, *type annotations* and *default* methods are supported. 8 | 9 | The AST contains the source code structure, javadoc and comments. It also allows to parse Javadoc tags and the Java code links. 10 | 11 | This parser is based on Sreenivasa Viswanadha's Java 1.5 parser. 12 | 13 | The project was originally hosted at http://code.google.com/p/javaparser[javaparser] but 14 | seemed dead. This repository adds powerful parsing functionalities for http://www.walkmod.com[walkmod] such 15 | as AST merge support, AST dumping as the original format or Javadoc parsing. 16 | 17 | ---- 18 | This program is free software: you can redistribute it and/or modify 19 | it under the terms of the GNU Lesser General Public License as published by 20 | the Free Software Foundation, either version 3 of the License, or 21 | (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU Lesser General Public License for more details. 27 | 28 | You should have received a copy of the GNU Lesser General Public License 29 | along with this program. If not, see . 30 | ---- 31 | == Usage 32 | 33 | If you are interested in creating a new http://www.walkmod.com[walkmod] plugin for Java code, you must add the following dependency in your project. 34 | 35 | ---- 36 | 37 | org.walkmod 38 | javalang 39 | 4.3.0 40 | 41 | ---- 42 | 43 | == Contributing 44 | 45 | If you want to hack on this, fork it, improve it and send me a pull request. 46 | 47 | To get started using it, just clone it and call mvn install. 48 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/type/VoidType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.type; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.AnnotationExpr; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class VoidType extends Type { 28 | 29 | public VoidType() {} 30 | 31 | public VoidType(int beginLine, int beginColumn, int endLine, int endColumn) { 32 | super(beginLine, beginColumn, endLine, endColumn); 33 | } 34 | 35 | public VoidType(int beginLine, int beginColumn, int endLine, int endColumn, List annotations) { 36 | super(beginLine, beginColumn, endLine, endColumn, annotations); 37 | } 38 | 39 | @Override 40 | public boolean removeChild(Node child) { 41 | return false; 42 | } 43 | 44 | @Override 45 | public R accept(GenericVisitor v, A arg) { 46 | if (!check()) { 47 | return null; 48 | } 49 | return v.visit(this, arg); 50 | } 51 | 52 | @Override 53 | public void accept(VoidVisitor v, A arg) { 54 | if (check()) { 55 | v.visit(this, arg); 56 | } 57 | } 58 | 59 | @Override 60 | public VoidType clone() throws CloneNotSupportedException { 61 | return new VoidType(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/IntegerLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public class IntegerLiteralExpr extends StringLiteralExpr { 24 | 25 | private static final String UNSIGNED_MIN_VALUE = "2147483648"; 26 | 27 | protected static final String MIN_VALUE = "-" + UNSIGNED_MIN_VALUE; 28 | 29 | public IntegerLiteralExpr() {} 30 | 31 | public IntegerLiteralExpr(String value) { 32 | super(value); 33 | } 34 | 35 | public IntegerLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn, String value) { 36 | super(beginLine, beginColumn, endLine, endColumn, value); 37 | } 38 | 39 | @Override 40 | public R accept(GenericVisitor v, A arg) { 41 | if (!check()) { 42 | return null; 43 | } 44 | return v.visit(this, arg); 45 | } 46 | 47 | @Override 48 | public void accept(VoidVisitor v, A arg) { 49 | if (check()) { 50 | v.visit(this, arg); 51 | } 52 | } 53 | 54 | public final boolean isMinValue() { 55 | return value != null && value.length() == 10 && value.equals(UNSIGNED_MIN_VALUE); 56 | } 57 | 58 | @Override 59 | public IntegerLiteralExpr clone() throws CloneNotSupportedException { 60 | return new IntegerLiteralExpr(value); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/LongLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.visitors.GenericVisitor; 18 | import org.walkmod.javalang.visitors.VoidVisitor; 19 | 20 | /** 21 | * @author Julio Vilmar Gesser 22 | */ 23 | public class LongLiteralExpr extends StringLiteralExpr { 24 | 25 | private static final String UNSIGNED_MIN_VALUE = "9223372036854775808"; 26 | 27 | protected static final String MIN_VALUE = "-" + UNSIGNED_MIN_VALUE + "L"; 28 | 29 | public LongLiteralExpr() {} 30 | 31 | public LongLiteralExpr(String value) { 32 | super(value); 33 | } 34 | 35 | public LongLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn, String value) { 36 | super(beginLine, beginColumn, endLine, endColumn, value); 37 | } 38 | 39 | @Override 40 | public R accept(GenericVisitor v, A arg) { 41 | if (!check()) { 42 | return null; 43 | } 44 | return v.visit(this, arg); 45 | } 46 | 47 | @Override 48 | public void accept(VoidVisitor v, A arg) { 49 | if (check()) { 50 | v.visit(this, arg); 51 | } 52 | } 53 | 54 | public final boolean isMinValue() { 55 | return value != null && value.length() == 20 && value.startsWith(UNSIGNED_MIN_VALUE) 56 | && (value.charAt(19) == 'L' || value.charAt(19) == 'l'); 57 | } 58 | 59 | public LongLiteralExpr clone() throws CloneNotSupportedException { 60 | return new LongLiteralExpr(value); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/BooleanLiteralExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class BooleanLiteralExpr extends LiteralExpr { 25 | 26 | private boolean value; 27 | 28 | public BooleanLiteralExpr() {} 29 | 30 | public BooleanLiteralExpr(boolean value) { 31 | this.value = value; 32 | } 33 | 34 | public BooleanLiteralExpr(int beginLine, int beginColumn, int endLine, int endColumn, boolean value) { 35 | super(beginLine, beginColumn, endLine, endColumn); 36 | this.value = value; 37 | } 38 | 39 | @Override 40 | public R accept(GenericVisitor v, A arg) { 41 | if (!check()) { 42 | return null; 43 | } 44 | return v.visit(this, arg); 45 | } 46 | 47 | @Override 48 | public void accept(VoidVisitor v, A arg) { 49 | if (check()) { 50 | v.visit(this, arg); 51 | } 52 | } 53 | 54 | public boolean getValue() { 55 | return value; 56 | } 57 | 58 | public void setValue(boolean value) { 59 | this.value = value; 60 | } 61 | 62 | @Override 63 | public boolean replaceChildNode(Node oldChild, Node newChild) { 64 | return false; 65 | } 66 | 67 | @Override 68 | public BooleanLiteralExpr clone() throws CloneNotSupportedException { 69 | return new BooleanLiteralExpr(value); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/BreakStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class BreakStmt extends Statement { 25 | 26 | private String id; 27 | 28 | public BreakStmt() {} 29 | 30 | public BreakStmt(String id) { 31 | this.id = id; 32 | } 33 | 34 | public BreakStmt(int beginLine, int beginColumn, int endLine, int endColumn, String id) { 35 | super(beginLine, beginColumn, endLine, endColumn); 36 | this.id = id; 37 | } 38 | 39 | @Override 40 | public boolean removeChild(Node child) { 41 | return false; 42 | } 43 | 44 | @Override 45 | public R accept(GenericVisitor v, A arg) { 46 | if (!check()) { 47 | return null; 48 | } 49 | return v.visit(this, arg); 50 | } 51 | 52 | @Override 53 | public void accept(VoidVisitor v, A arg) { 54 | if (check()) { 55 | v.visit(this, arg); 56 | } 57 | } 58 | 59 | public String getId() { 60 | return id; 61 | } 62 | 63 | public void setId(String id) { 64 | this.id = id; 65 | } 66 | 67 | @Override 68 | public boolean replaceChildNode(Node oldChild, Node newChild) { 69 | return false; 70 | } 71 | 72 | @Override 73 | public BreakStmt clone() throws CloneNotSupportedException { 74 | return new BreakStmt(id); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/ContinueStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import org.walkmod.javalang.ast.Node; 18 | import org.walkmod.javalang.visitors.GenericVisitor; 19 | import org.walkmod.javalang.visitors.VoidVisitor; 20 | 21 | /** 22 | * @author Julio Vilmar Gesser 23 | */ 24 | public final class ContinueStmt extends Statement { 25 | 26 | private String id; 27 | 28 | public ContinueStmt() {} 29 | 30 | public ContinueStmt(String id) { 31 | this.id = id; 32 | } 33 | 34 | public ContinueStmt(int beginLine, int beginColumn, int endLine, int endColumn, String id) { 35 | super(beginLine, beginColumn, endLine, endColumn); 36 | this.id = id; 37 | } 38 | 39 | @Override 40 | public boolean removeChild(Node child) { 41 | return false; 42 | } 43 | 44 | @Override 45 | public R accept(GenericVisitor v, A arg) { 46 | if (!check()) { 47 | return null; 48 | } 49 | return v.visit(this, arg); 50 | } 51 | 52 | @Override 53 | public void accept(VoidVisitor v, A arg) { 54 | if (check()) { 55 | v.visit(this, arg); 56 | } 57 | } 58 | 59 | public String getId() { 60 | return id; 61 | } 62 | 63 | public void setId(String id) { 64 | this.id = id; 65 | } 66 | 67 | @Override 68 | public boolean replaceChildNode(Node oldChild, Node newChild) { 69 | return false; 70 | } 71 | 72 | @Override 73 | public ContinueStmt clone() throws CloneNotSupportedException { 74 | return new ContinueStmt(id); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/MethodDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | import org.walkmod.javalang.ast.body.MethodDeclaration; 22 | import org.walkmod.javalang.ast.body.Parameter; 23 | 24 | public class MethodDeclarationComparator implements Comparator { 25 | 26 | @Override 27 | public int compare(MethodDeclaration n1, MethodDeclaration n2) { 28 | if (n1.getName().equals(n2.getName())) { 29 | List params1 = n1.getParameters(); 30 | List params2 = n2.getParameters(); 31 | if ((params1 == null || params1.size() == 0) && (params2 == null || params2.size() == 0)) { 32 | return 0; 33 | } else if (params1 != null && params2 != null) { 34 | if (params1.size() == params2.size()) { 35 | Iterator itprms = n1.getParameters().iterator(); 36 | Iterator itprms2 = n2.getParameters().iterator(); 37 | boolean equalParams = false; 38 | while (itprms.hasNext() && itprms2.hasNext() && !equalParams) { 39 | equalParams = itprms.next().getType().toString().equals(itprms2.next().getType().toString()); 40 | } 41 | if (equalParams) 42 | return 0; 43 | else 44 | return new Integer(params1.size()).compareTo(params2.size()); 45 | } else { 46 | return new Integer(params1.size()).compareTo(params2.size()); 47 | } 48 | } 49 | } 50 | return n1.getName().compareTo(n2.getName()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/ConstructorDeclarationComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Comparator; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | import org.walkmod.javalang.ast.body.ConstructorDeclaration; 22 | import org.walkmod.javalang.ast.body.Parameter; 23 | 24 | public class ConstructorDeclarationComparator implements Comparator { 25 | 26 | @Override 27 | public int compare(ConstructorDeclaration o1, ConstructorDeclaration o2) { 28 | if (o1.getName().equals(o2.getName())) { 29 | List params1 = o1.getParameters(); 30 | List params2 = o2.getParameters(); 31 | if ((params1 == null || params1.size() == 0) && (params2 == null || params2.size() == 0)) { 32 | return 0; 33 | } else if (params1 != null && params2 != null) { 34 | if (params1.size() == params2.size()) { 35 | Iterator itprms = o1.getParameters().iterator(); 36 | Iterator itprms2 = o2.getParameters().iterator(); 37 | boolean equalParams = false; 38 | while (itprms.hasNext() && itprms2.hasNext() && !equalParams) { 39 | equalParams = itprms.next().getType().toString().equals(itprms2.next().getType().toString()); 40 | } 41 | if (equalParams) 42 | return 0; 43 | else 44 | return new Integer(params1.size()).compareTo(params2.size()); 45 | } else { 46 | return new Integer(params1.size()).compareTo(params2.size()); 47 | } 48 | } 49 | } 50 | return o1.getName().compareTo(o2.getName()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/AnnotationDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.AnnotationExpr; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class AnnotationDeclaration extends TypeDeclaration { 28 | 29 | public AnnotationDeclaration() {} 30 | 31 | public AnnotationDeclaration(int modifiers, String name) { 32 | super(modifiers, name); 33 | } 34 | 35 | public AnnotationDeclaration(JavadocComment javaDoc, int modifiers, List annotations, String name, 36 | List members) { 37 | super(annotations, javaDoc, modifiers, name, members); 38 | } 39 | 40 | public AnnotationDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, JavadocComment javaDoc, 41 | int modifiers, List annotations, String name, List members) { 42 | super(beginLine, beginColumn, endLine, endColumn, annotations, javaDoc, modifiers, name, members); 43 | } 44 | 45 | @Override 46 | public List getChildren() { 47 | return super.getChildren(); 48 | } 49 | 50 | @Override 51 | public R accept(GenericVisitor v, A arg) { 52 | if (!check()) { 53 | return null; 54 | } 55 | return v.visit(this, arg); 56 | } 57 | 58 | @Override 59 | public void accept(VoidVisitor v, A arg) { 60 | if (check()) { 61 | v.visit(this, arg); 62 | } 63 | } 64 | 65 | @Override 66 | public AnnotationDeclaration clone() throws CloneNotSupportedException { 67 | return new AnnotationDeclaration(getModifiers(), getName()); 68 | } 69 | 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/Comment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | /** 21 | * Abstract class for all AST nodes that represent comments. 22 | * 23 | * @see BlockComment 24 | * @see LineComment 25 | * @see org.walkmod.javalang.ast.body.JavadocComment 26 | * @author Julio Vilmar Gesser 27 | */ 28 | public abstract class Comment extends Node { 29 | 30 | private String content; 31 | 32 | public Comment() {} 33 | 34 | public Comment(String content) { 35 | this.content = content; 36 | } 37 | 38 | public Comment(int beginLine, int beginColumn, int endLine, int endColumn, String content) { 39 | super(beginLine, beginColumn, endLine, endColumn); 40 | this.content = content; 41 | } 42 | 43 | @Override 44 | public boolean removeChild(Node child) { 45 | return false; 46 | } 47 | 48 | /** 49 | * Return the text of the comment. 50 | * 51 | * @return text of the comment 52 | */ 53 | public final String getContent() { 54 | return content; 55 | } 56 | 57 | /** 58 | * Sets the text of the comment. 59 | * 60 | * @param content 61 | * the text of the comment to set 62 | */ 63 | public void setContent(String content) { 64 | this.content = content; 65 | } 66 | 67 | @Override 68 | public String getPrettySource(char indentationChar, int indentationLevel, int indentationSize) { 69 | String text = super.getPrettySource(indentationChar, indentationLevel, indentationSize); 70 | if (!text.endsWith("\n")) { 71 | text += "\n"; 72 | } 73 | return text; 74 | } 75 | 76 | public boolean replaceChildNode(Node oldChild, Node newChild) { 77 | return false; 78 | } 79 | 80 | @Override 81 | public List getChildren() { 82 | return new LinkedList(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/BodyDeclaratorComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Arrays; 18 | import java.util.Comparator; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.walkmod.javalang.ast.body.BodyDeclaration; 23 | 24 | public class BodyDeclaratorComparator implements Comparator { 25 | 26 | private String[] order; 27 | 28 | @SuppressWarnings("rawtypes") 29 | private Map comparator = new HashMap(); 30 | 31 | public BodyDeclaratorComparator() { 32 | order = new String[] {"FieldDeclaration", "EnumConstantDeclaration", "InitializerDeclaration", 33 | "ConstructorDeclaration", "AnnotationMemberDeclaration", "MethodDeclaration", "TypeDeclaration", 34 | "EmptyMemberDeclaration"}; 35 | comparator.put("FieldDeclaration", new FieldDeclarationComparator()); 36 | comparator.put("MethodDeclaration", new MethodDeclarationComparator()); 37 | comparator.put("EnumConstantDeclaration", new EnumConstantComparator()); 38 | comparator.put("AnnotationMemberDeclaration", new AnnotationMemberDeclarationComparator()); 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | @Override 43 | public int compare(BodyDeclaration o1, BodyDeclaration o2) { 44 | Integer o1_position = Arrays.binarySearch(order, o1.getClass().getSimpleName()); 45 | Integer o2_position = Arrays.binarySearch(order, o2.getClass().getSimpleName()); 46 | if (o1_position < 0) { 47 | return 0; 48 | } else if (o1_position == o2_position) { 49 | if (comparator.containsKey(order[o1_position])) { 50 | return comparator.get(order[o1_position]).compare(o1, o2); 51 | } else { 52 | return 0; 53 | } 54 | } else { 55 | return o1_position.compareTo(o2_position); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/EmptyMemberDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import java.util.Comparator; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.comparators.EmptyMemberDeclarationComparator; 22 | import org.walkmod.javalang.visitors.GenericVisitor; 23 | import org.walkmod.javalang.visitors.VoidVisitor; 24 | import org.walkmod.merger.MergeEngine; 25 | import org.walkmod.merger.Mergeable; 26 | 27 | /** 28 | * @author Julio Vilmar Gesser 29 | */ 30 | public final class EmptyMemberDeclaration extends BodyDeclaration implements Mergeable { 31 | 32 | public EmptyMemberDeclaration() {} 33 | 34 | public EmptyMemberDeclaration(JavadocComment javaDoc) { 35 | super(null, javaDoc); 36 | } 37 | 38 | public EmptyMemberDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, JavadocComment javaDoc) { 39 | super(beginLine, beginColumn, endLine, endColumn, null, javaDoc); 40 | } 41 | 42 | @Override 43 | public List getChildren() { 44 | 45 | return super.getChildren(); 46 | } 47 | 48 | @Override 49 | public R accept(GenericVisitor v, A arg) { 50 | if (!check()) { 51 | return null; 52 | } 53 | return v.visit(this, arg); 54 | } 55 | 56 | @Override 57 | public void accept(VoidVisitor v, A arg) { 58 | if (check()) { 59 | v.visit(this, arg); 60 | } 61 | } 62 | 63 | @Override 64 | public Comparator getIdentityComparator() { 65 | 66 | return new EmptyMemberDeclarationComparator(); 67 | } 68 | 69 | @Override 70 | public void merge(EmptyMemberDeclaration t1, MergeEngine configuration) { 71 | super.merge(t1, configuration); 72 | } 73 | 74 | @Override 75 | public EmptyMemberDeclaration clone() throws CloneNotSupportedException { 76 | return new EmptyMemberDeclaration(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/walkmod/javalang/javadoclinks/JavadocLinksParserTest.java: -------------------------------------------------------------------------------- 1 | package org.walkmod.javalang.javadoclinks; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class JavadocLinksParserTest { 7 | 8 | @Test 9 | public void testParser() throws ParseException { 10 | MethodLink ml = JavadocLinkParser.parse("Foo#bar()"); 11 | Assert.assertEquals("Foo", ml.getClassName()); 12 | Assert.assertEquals("bar", ml.getName()); 13 | } 14 | 15 | @Test 16 | public void testFullName() throws ParseException { 17 | MethodLink ml = JavadocLinkParser.parse("org.walkmod.Foo#bar()"); 18 | Assert.assertEquals("org.walkmod.Foo", ml.getClassName()); 19 | Assert.assertEquals("bar", ml.getName()); 20 | } 21 | 22 | @Test 23 | public void testInnerClass() throws ParseException { 24 | MethodLink ml = JavadocLinkParser.parse("org.walkmod.Foo$Aux#bar()"); 25 | Assert.assertEquals("org.walkmod.Foo$Aux", ml.getClassName()); 26 | Assert.assertEquals("bar", ml.getName()); 27 | } 28 | 29 | @Test 30 | public void testAnonymousClass() throws ParseException { 31 | MethodLink ml = JavadocLinkParser.parse("org.walkmod.Foo$Aux$1$2#bar()"); 32 | Assert.assertEquals("org.walkmod.Foo$Aux$1$2", ml.getClassName()); 33 | Assert.assertEquals("bar", ml.getName()); 34 | } 35 | 36 | @Test 37 | public void testOptionalName() throws ParseException { 38 | MethodLink ml = JavadocLinkParser.parse("#bar()"); 39 | Assert.assertEquals("", ml.getClassName()); 40 | Assert.assertEquals("bar", ml.getName()); 41 | } 42 | 43 | @Test 44 | public void testArguments() throws ParseException { 45 | MethodLink ml = JavadocLinkParser.parse("#bar(int)"); 46 | Assert.assertEquals("", ml.getClassName()); 47 | Assert.assertEquals("bar", ml.getName()); 48 | Assert.assertEquals(1, ml.getArguments().size()); 49 | } 50 | 51 | @Test 52 | public void testMultipleArguments() throws ParseException { 53 | MethodLink ml = JavadocLinkParser.parse("#bar(int, int)"); 54 | Assert.assertEquals("", ml.getClassName()); 55 | Assert.assertEquals("bar", ml.getName()); 56 | Assert.assertEquals(2, ml.getArguments().size()); 57 | } 58 | 59 | @Test 60 | public void testParseField() throws ParseException { 61 | FieldLink fl = JavadocLinkParser.parseField("org.walkmod.Foo#bar"); 62 | Assert.assertEquals("org.walkmod.Foo", fl.getClassName()); 63 | Assert.assertEquals("bar", fl.getName()); 64 | } 65 | 66 | @Test 67 | public void testParseAnyField() throws ParseException { 68 | FieldLink fl = JavadocLinkParser.parseField("#bar"); 69 | Assert.assertEquals("", fl.getClassName()); 70 | Assert.assertEquals("bar", fl.getName()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/MarkerAnnotationExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | 16 | package org.walkmod.javalang.ast.expr; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.walkmod.javalang.ast.ScopeAwareUtil; 22 | import org.walkmod.javalang.ast.SymbolDefinition; 23 | import org.walkmod.javalang.visitors.GenericVisitor; 24 | import org.walkmod.javalang.visitors.VoidVisitor; 25 | import org.walkmod.merger.MergeEngine; 26 | 27 | /** 28 | * @author Julio Vilmar Gesser 29 | */ 30 | public final class MarkerAnnotationExpr extends AnnotationExpr { 31 | 32 | public MarkerAnnotationExpr() {} 33 | 34 | public MarkerAnnotationExpr(NameExpr name) { 35 | this.name = name; 36 | } 37 | 38 | public MarkerAnnotationExpr(int beginLine, int beginColumn, int endLine, int endColumn, NameExpr name) { 39 | super(beginLine, beginColumn, endLine, endColumn); 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public R accept(GenericVisitor v, A arg) { 45 | if (!check()) { 46 | return null; 47 | } 48 | return v.visit(this, arg); 49 | } 50 | 51 | @Override 52 | public void accept(VoidVisitor v, A arg) { 53 | if (check()) { 54 | v.visit(this, arg); 55 | } 56 | } 57 | 58 | @Override 59 | public void merge(AnnotationExpr t1, MergeEngine configuration) { 60 | // Nothing 61 | } 62 | 63 | @Override 64 | public MarkerAnnotationExpr clone() throws CloneNotSupportedException { 65 | return new MarkerAnnotationExpr(clone(name)); 66 | } 67 | 68 | @Override 69 | public Map getVariableDefinitions() { 70 | return ScopeAwareUtil.getVariableDefinitions(this); 71 | } 72 | 73 | @Override 74 | public Map> getMethodDefinitions() { 75 | return ScopeAwareUtil.getMethodDefinitions(MarkerAnnotationExpr.this); 76 | } 77 | 78 | @Override 79 | public Map getTypeDefinitions() { 80 | return ScopeAwareUtil.getTypeDefinitions(MarkerAnnotationExpr.this); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/comparators/CompilationUnitComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.comparators; 16 | 17 | import java.util.Collection; 18 | import java.util.Comparator; 19 | 20 | import org.walkmod.javalang.ast.CompilationUnit; 21 | import org.walkmod.javalang.ast.PackageDeclaration; 22 | import org.walkmod.javalang.ast.body.ModifierSet; 23 | import org.walkmod.javalang.ast.body.TypeDeclaration; 24 | 25 | public class CompilationUnitComparator implements Comparator { 26 | 27 | @Override 28 | public int compare(CompilationUnit cu1, CompilationUnit cu2) { 29 | if (cu1 != null && cu2 != null) { 30 | PackageDeclaration pd1 = cu1.getPackage(); 31 | PackageDeclaration pd2 = cu2.getPackage(); 32 | boolean samePackage = true; 33 | if (pd1 != pd2) { 34 | if (pd1 != null && pd2 != null) { 35 | samePackage = pd1.getName().equals(pd2.getName()); 36 | } else { 37 | samePackage = false; 38 | } 39 | } 40 | if (samePackage) { 41 | // same reference 42 | Collection types1 = cu1.getTypes(); 43 | TypeDeclaration mainType = null; 44 | if (types1 != null) { 45 | for (TypeDeclaration td : types1) { 46 | if (ModifierSet.isPublic(td.getModifiers())) { 47 | mainType = td; 48 | } 49 | } 50 | } 51 | if (mainType != null) { 52 | Collection types2 = cu2.getTypes(); 53 | if (types2 != null) { 54 | for (TypeDeclaration td : types2) { 55 | if (td.getName().equals(mainType.getName())) { 56 | return 0; 57 | } 58 | } 59 | } 60 | } 61 | return 1; 62 | } 63 | } 64 | if (cu1 != cu2) { 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/type/PrimitiveType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.type; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.AnnotationExpr; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class PrimitiveType extends Type { 28 | 29 | public enum Primitive { 30 | 31 | Boolean, Char, Byte, Short, Int, Long, Float, Double 32 | } 33 | 34 | private Primitive type; 35 | 36 | public PrimitiveType() {} 37 | 38 | public PrimitiveType(Primitive type) { 39 | this.type = type; 40 | } 41 | 42 | public PrimitiveType(int beginLine, int beginColumn, int endLine, int endColumn, Primitive type) { 43 | super(beginLine, beginColumn, endLine, endColumn); 44 | this.type = type; 45 | } 46 | 47 | public PrimitiveType(int beginLine, int beginColumn, int endLine, int endColumn, Primitive type, 48 | List annotations) { 49 | super(beginLine, beginColumn, endLine, endColumn, annotations); 50 | this.type = type; 51 | } 52 | 53 | @Override 54 | public boolean removeChild(Node child) { 55 | return false; 56 | } 57 | 58 | @Override 59 | public R accept(GenericVisitor v, A arg) { 60 | if (!check()) { 61 | return null; 62 | } 63 | return v.visit(this, arg); 64 | } 65 | 66 | @Override 67 | public void accept(VoidVisitor v, A arg) { 68 | if (check()) { 69 | v.visit(this, arg); 70 | } 71 | } 72 | 73 | public Primitive getType() { 74 | return type; 75 | } 76 | 77 | public void setType(Primitive type) { 78 | this.type = type; 79 | } 80 | 81 | @Override 82 | public boolean replaceChildNode(Node oldChild, Node newChild) { 83 | return super.replaceChildNode(oldChild, newChild); 84 | } 85 | 86 | @Override 87 | public PrimitiveType clone() throws CloneNotSupportedException { 88 | return new PrimitiveType(type); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/VariableDeclaratorId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class VariableDeclaratorId extends Node { 28 | 29 | private String name; 30 | 31 | private int arrayCount; 32 | 33 | public VariableDeclaratorId() {} 34 | 35 | public VariableDeclaratorId(String name) { 36 | this.name = name; 37 | } 38 | 39 | public VariableDeclaratorId(int beginLine, int beginColumn, int endLine, int endColumn, String name, 40 | int arrayCount) { 41 | super(beginLine, beginColumn, endLine, endColumn); 42 | this.name = name; 43 | this.arrayCount = arrayCount; 44 | } 45 | 46 | @Override 47 | public List getChildren() { 48 | return new LinkedList(); 49 | } 50 | 51 | @Override 52 | public boolean removeChild(Node child) { 53 | return false; 54 | } 55 | 56 | @Override 57 | public R accept(GenericVisitor v, A arg) { 58 | if (!check()) { 59 | return null; 60 | } 61 | return v.visit(this, arg); 62 | } 63 | 64 | @Override 65 | public void accept(VoidVisitor v, A arg) { 66 | if (check()) { 67 | v.visit(this, arg); 68 | } 69 | } 70 | 71 | public int getArrayCount() { 72 | return arrayCount; 73 | } 74 | 75 | public String getName() { 76 | return name; 77 | } 78 | 79 | public void setArrayCount(int arrayCount) { 80 | this.arrayCount = arrayCount; 81 | } 82 | 83 | public void setName(String name) { 84 | this.name = name; 85 | } 86 | 87 | @Override 88 | public boolean replaceChildNode(Node oldChild, Node newChild) { 89 | return false; 90 | } 91 | 92 | @Override 93 | public VariableDeclaratorId clone() throws CloneNotSupportedException { 94 | return new VariableDeclaratorId(getName()); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/actions/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.actions; 16 | 17 | public abstract class Action { 18 | private int beginLine; 19 | private int beginColumn; 20 | private ActionType type; 21 | 22 | public Action(int beginLine, int beginPosition, ActionType type) { 23 | this.beginLine = beginLine; 24 | this.beginColumn = beginPosition; 25 | this.type = type; 26 | } 27 | 28 | public int getBeginLine() { 29 | return beginLine; 30 | } 31 | 32 | public void setBeginLine(int beginLine) { 33 | this.beginLine = beginLine; 34 | } 35 | 36 | public int getBeginColumn() { 37 | return beginColumn; 38 | } 39 | 40 | public void setBeginColumn(int beginPosition) { 41 | this.beginColumn = beginPosition; 42 | } 43 | 44 | public ActionType getType() { 45 | return type; 46 | } 47 | 48 | public void setType(ActionType type) { 49 | this.type = type; 50 | } 51 | 52 | public abstract int getEndLine(); 53 | 54 | public abstract int getEndColumn(); 55 | 56 | public boolean isPreviousThan(int beginLine, int beginColumn) { 57 | 58 | if (beginLine > getEndLine()) { 59 | return true; 60 | } 61 | if (beginLine == getEndLine() && beginColumn >= getEndColumn()) { 62 | return true; 63 | } 64 | return false; 65 | } 66 | 67 | public boolean contains(Action action) { 68 | 69 | if ((getBeginLine() < action.getBeginLine()) 70 | || ((getBeginLine() == action.getBeginLine()) && getBeginColumn() <= action.getBeginColumn())) { 71 | if (getEndLine() > action.getEndLine()) { 72 | return true; 73 | } else if ((getEndLine() == action.getEndLine()) && getEndColumn() >= action.getEndColumn()) { 74 | return true; 75 | } else if (getEndLine() > action.getBeginLine()) { 76 | return true; 77 | } else if (getEndLine() == action.getBeginLine() && getEndColumn() > action.getBeginColumn()) { 78 | return true; 79 | } 80 | } 81 | return false; 82 | } 83 | 84 | public boolean isEmpty() { 85 | return getBeginLine() == getEndLine() && getBeginColumn() == getEndColumn(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/QualifiedNameExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.visitors.GenericVisitor; 21 | import org.walkmod.javalang.visitors.VoidVisitor; 22 | 23 | /** 24 | * @author Julio Vilmar Gesser 25 | */ 26 | public final class QualifiedNameExpr extends NameExpr { 27 | 28 | private NameExpr qualifier; 29 | 30 | public QualifiedNameExpr() {} 31 | 32 | public QualifiedNameExpr(NameExpr scope, String name) { 33 | super(name); 34 | setQualifier(scope); 35 | } 36 | 37 | public QualifiedNameExpr(int beginLine, int beginColumn, int endLine, int endColumn, NameExpr scope, String name) { 38 | super(beginLine, beginColumn, endLine, endColumn, name); 39 | setQualifier(scope); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (qualifier == child) { 47 | qualifier = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public List getChildren() { 59 | List children = super.getChildren(); 60 | if (qualifier != null) { 61 | children.add(qualifier); 62 | } 63 | return children; 64 | } 65 | 66 | @Override 67 | public R accept(GenericVisitor v, A arg) { 68 | if (!check()) { 69 | return null; 70 | } 71 | return v.visit(this, arg); 72 | } 73 | 74 | @Override 75 | public void accept(VoidVisitor v, A arg) { 76 | if (check()) { 77 | v.visit(this, arg); 78 | } 79 | } 80 | 81 | public NameExpr getQualifier() { 82 | return qualifier; 83 | } 84 | 85 | public void setQualifier(NameExpr qualifier) { 86 | this.qualifier = qualifier; 87 | setAsParentNodeOf(qualifier); 88 | } 89 | 90 | @Override 91 | public QualifiedNameExpr clone() throws CloneNotSupportedException { 92 | return new QualifiedNameExpr(clone(getQualifier()), getName()); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/Refactorization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.walkmod.javalang.ast.expr.FieldAccessExpr; 22 | import org.walkmod.javalang.ast.expr.NameExpr; 23 | import org.walkmod.javalang.ast.expr.ThisExpr; 24 | import org.walkmod.javalang.visitors.VoidVisitorAdapter; 25 | 26 | public class Refactorization { 27 | 28 | /** 29 | * Generic method to rename a SymbolDefinition variable/parameter. 30 | * @param n variable to rename. 31 | * @param newName new name to set. 32 | * @return if the rename procedure has been applied successfully. 33 | */ 34 | public boolean refactorVariable(SymbolDefinition n, final String newName) { 35 | Map scope = n.getVariableDefinitions(); 36 | 37 | if (!scope.containsKey(newName)) { 38 | 39 | if (n.getUsages() != null) { 40 | List usages = new LinkedList(n.getUsages()); 41 | 42 | VoidVisitorAdapter visitor = new VoidVisitorAdapter() { 43 | @Override 44 | public void visit(NameExpr nexpr, Object ctx) { 45 | Map innerScope = nexpr.getVariableDefinitions(); 46 | if (innerScope.containsKey(newName)) { 47 | nexpr.getParentNode().replaceChildNode(nexpr, new FieldAccessExpr(new ThisExpr(), newName)); 48 | } else { 49 | nexpr.getParentNode().replaceChildNode(nexpr, new NameExpr(newName)); 50 | } 51 | } 52 | 53 | @Override 54 | public void visit(FieldAccessExpr nexpr, Object ctx) { 55 | nexpr.getParentNode().replaceChildNode(nexpr, 56 | new FieldAccessExpr(nexpr.getScope(), nexpr.getTypeArgs(), newName)); 57 | } 58 | }; 59 | 60 | for (SymbolReference usage : usages) { 61 | Node aux = (Node) usage; 62 | 63 | aux.accept(visitor, null); 64 | 65 | } 66 | } 67 | 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/resources/lambda.txt: -------------------------------------------------------------------------------- 1 | public class Java8Test{ 2 | 3 | /* 4 | * Tests for Java8. 5 | * These are lambda and method reference expressions semantically incorrect, 6 | * but parseable (like 1 = 1;) extracted from the jsr335-final. 7 | */ 8 | public static void main(String[] args) throws Exception{ 9 | 10 | optimizedInstructions.forEach(instr -> instr.accept(this)); 11 | 12 | Object o = s -> String::length; 13 | 14 | () -> {}; // No parameters; result is void 15 | 16 | 17 | () -> 42; // No parameters, expression body 18 | () -> null; // No parameters, expression body 19 | () -> { return 42; }; // No parameters, block body with return 20 | () -> { System.gc(); }; // No parameters, void block body 21 | 22 | () -> { 23 | if (true) return 12; 24 | else { 25 | int result = 15; 26 | for (int i = 1; i < 10; i++) 27 | result *= i; 28 | return result; 29 | } 30 | } ; // Complex block body with returns 31 | 32 | (int x) -> x+1 ; // Single declared-type parameter 33 | 34 | (int x) -> { return x+1; }; // Single declared-type parameter 35 | (x) -> x+1; // Single inferred-type parameter 36 | x -> x+1; // Parens optional for single inferred-type case 37 | 38 | (String s) -> s.length(); // Single declared-type parameter 39 | (Thread t) -> { t.start(); }; // Single declared-type parameter 40 | s -> s.length(); // Single inferred-type parameter 41 | t -> { t.start(); }; // Single inferred-type parameter 42 | 43 | (int x, int y) -> x+y; // Multiple declared-type parameters 44 | (x,y) -> x+y; // Multiple inferred-type parameters 45 | (final int x) -> x+1; // Modified declared-type parameter 46 | 47 | ()-> System::getProperty; 48 | ()-> String::length; 49 | ()-> List::size; // explicit class type args 50 | ()-> List::size; // inferred class type args 51 | ()-> int[]::clone; 52 | ()-> T::tvarMember; 53 | 54 | ()-> "abc"::length; 55 | ()-> System.out::println; 56 | ()-> foo[x]::bar; 57 | ()-> (test ? stream.map(String::trim) : stream)::toArray; 58 | ()-> super::toString; 59 | 60 | ()-> String::valueOf; // overload resolution needed 61 | ()-> Arrays::sort; // type args inferred from context 62 | 63 | ()-> Arrays::sort; // explicit type args 64 | 65 | ()-> ArrayList::new; // constructor for parameterized type 66 | ()-> ArrayList::new; // inferred class type args 67 | ()-> Foo::new; // explicit generic constructor type arguments 68 | ()-> Bar::new; // generic class, generic constructor 69 | ()-> Outer.Inner::new; // inner class constructor 70 | ()-> int[]::new; // array creation*/ 71 | Stream stream = generate((Supplier) () -> "Fail"); 72 | c = (Supplier) () -> "Fail"; 73 | } 74 | 75 | public interface B{ 76 | 77 | void accept(); 78 | //new default modifier in Java 8 just for interfaces 79 | public default void listen(){} 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/ThrowStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.Expression; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class ThrowStmt extends Statement { 28 | 29 | private Expression expr; 30 | 31 | public ThrowStmt() {} 32 | 33 | public ThrowStmt(Expression expr) { 34 | setExpr(expr); 35 | } 36 | 37 | public ThrowStmt(int beginLine, int beginColumn, int endLine, int endColumn, Expression expr) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setExpr(expr); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (expr == child) { 47 | expr = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public R accept(GenericVisitor v, A arg) { 59 | if (!check()) { 60 | return null; 61 | } 62 | return v.visit(this, arg); 63 | } 64 | 65 | @Override 66 | public void accept(VoidVisitor v, A arg) { 67 | if (check()) { 68 | v.visit(this, arg); 69 | } 70 | } 71 | 72 | @Override 73 | public List getChildren() { 74 | List children = super.getChildren(); 75 | if (expr != null) { 76 | children.add(expr); 77 | } 78 | return children; 79 | } 80 | 81 | public Expression getExpr() { 82 | return expr; 83 | } 84 | 85 | public void setExpr(Expression expr) { 86 | if (this.expr != null) { 87 | updateReferences(this.expr); 88 | } 89 | this.expr = expr; 90 | setAsParentNodeOf(expr); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | if (oldChild == expr) { 97 | setExpr((Expression) newChild); 98 | updated = true; 99 | } 100 | 101 | return updated; 102 | } 103 | 104 | @Override 105 | public ThrowStmt clone() throws CloneNotSupportedException { 106 | return new ThrowStmt(clone(expr)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/ReturnStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.Expression; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class ReturnStmt extends Statement { 28 | 29 | private Expression expr; 30 | 31 | public ReturnStmt() {} 32 | 33 | public ReturnStmt(Expression expr) { 34 | setExpr(expr); 35 | } 36 | 37 | public ReturnStmt(int beginLine, int beginColumn, int endLine, int endColumn, Expression expr) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setExpr(expr); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (expr == child) { 47 | expr = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public List getChildren() { 59 | List children = super.getChildren(); 60 | if (expr != null) { 61 | children.add(expr); 62 | } 63 | return children; 64 | } 65 | 66 | @Override 67 | public R accept(GenericVisitor v, A arg) { 68 | if (!check()) { 69 | return null; 70 | } 71 | return v.visit(this, arg); 72 | } 73 | 74 | @Override 75 | public void accept(VoidVisitor v, A arg) { 76 | if (check()) { 77 | v.visit(this, arg); 78 | } 79 | } 80 | 81 | public Expression getExpr() { 82 | return expr; 83 | } 84 | 85 | public void setExpr(Expression expr) { 86 | if (this.expr != null) { 87 | updateReferences(this.expr); 88 | } 89 | this.expr = expr; 90 | setAsParentNodeOf(expr); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | if (oldChild == expr) { 97 | setExpr((Expression) newChild); 98 | updated = true; 99 | } 100 | 101 | return updated; 102 | } 103 | 104 | @Override 105 | public ReturnStmt clone() throws CloneNotSupportedException { 106 | return new ReturnStmt(clone(expr)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/ClassExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.type.Type; 22 | import org.walkmod.javalang.visitors.GenericVisitor; 23 | import org.walkmod.javalang.visitors.VoidVisitor; 24 | 25 | /** 26 | * @author Julio Vilmar Gesser 27 | */ 28 | public final class ClassExpr extends Expression { 29 | 30 | private Type type; 31 | 32 | public ClassExpr() {} 33 | 34 | public ClassExpr(Type type) { 35 | setType(type); 36 | } 37 | 38 | public ClassExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type) { 39 | super(beginLine, beginColumn, endLine, endColumn); 40 | setType(type); 41 | } 42 | 43 | @Override 44 | public boolean removeChild(Node child) { 45 | boolean result = false; 46 | 47 | if (child != null) { 48 | if (type == child) { 49 | type = null; 50 | result = true; 51 | } 52 | } 53 | if (!result) { 54 | updateReferences(child); 55 | } 56 | return result; 57 | } 58 | 59 | @Override 60 | public List getChildren() { 61 | List children = new LinkedList(); 62 | if (type != null) { 63 | children.add(type); 64 | } 65 | return children; 66 | } 67 | 68 | @Override 69 | public R accept(GenericVisitor v, A arg) { 70 | if (!check()) { 71 | return null; 72 | } 73 | return v.visit(this, arg); 74 | } 75 | 76 | @Override 77 | public void accept(VoidVisitor v, A arg) { 78 | if (check()) { 79 | v.visit(this, arg); 80 | } 81 | } 82 | 83 | public Type getType() { 84 | return type; 85 | } 86 | 87 | public void setType(Type type) { 88 | if (this.type != null) { 89 | updateReferences(this.type); 90 | } 91 | this.type = type; 92 | setAsParentNodeOf(type); 93 | } 94 | 95 | @Override 96 | public boolean replaceChildNode(Node oldChild, Node newChild) { 97 | boolean updated = false; 98 | if (type == oldChild) { 99 | setType((Type) newChild); 100 | updated = true; 101 | } 102 | 103 | return updated; 104 | } 105 | 106 | @Override 107 | public ClassExpr clone() throws CloneNotSupportedException { 108 | return new ClassExpr(clone(getType())); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/type/IntersectionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.type; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | public class IntersectionType extends Type { 25 | 26 | private List bounds; 27 | 28 | public IntersectionType() { 29 | 30 | } 31 | 32 | public IntersectionType(List bounds) { 33 | setBounds(bounds); 34 | } 35 | 36 | public IntersectionType(int beginLine, int beginColumn, int endLine, int endColumn, List bounds) { 37 | super(beginLine, beginColumn, endLine, endColumn, null); 38 | setBounds(bounds); 39 | } 40 | 41 | @Override 42 | public boolean removeChild(Node child) { 43 | boolean result = false; 44 | if (child != null) { 45 | if (bounds != null) { 46 | if (child instanceof ReferenceType) { 47 | List boundsAux = new LinkedList(bounds); 48 | result = boundsAux.remove(child); 49 | bounds = boundsAux; 50 | } 51 | } 52 | } 53 | if (result) { 54 | updateReferences(child); 55 | } 56 | return result; 57 | } 58 | 59 | @Override 60 | public List getChildren() { 61 | List children = super.getChildren(); 62 | if (bounds != null) { 63 | children.addAll(bounds); 64 | } 65 | return children; 66 | } 67 | 68 | @Override 69 | public R accept(GenericVisitor v, A arg) { 70 | if (!check()) { 71 | return null; 72 | } 73 | return v.visit(this, arg); 74 | } 75 | 76 | @Override 77 | public void accept(VoidVisitor v, A arg) { 78 | if (check()) { 79 | v.visit(this, arg); 80 | } 81 | } 82 | 83 | public List getBounds() { 84 | return bounds; 85 | } 86 | 87 | public void setBounds(List bounds) { 88 | this.bounds = bounds; 89 | setAsParentNodeOf(bounds); 90 | } 91 | 92 | @Override 93 | public boolean replaceChildNode(Node oldChild, Node newChild) { 94 | return super.replaceChildNode(oldChild, newChild); 95 | } 96 | 97 | @Override 98 | public IntersectionType clone() throws CloneNotSupportedException { 99 | return new IntersectionType(clone(getBounds())); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/EnclosedExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class EnclosedExpr extends Expression { 28 | 29 | private Expression inner; 30 | 31 | public EnclosedExpr() {} 32 | 33 | public EnclosedExpr(Expression inner) { 34 | setInner(inner); 35 | } 36 | 37 | public EnclosedExpr(int beginLine, int beginColumn, int endLine, int endColumn, Expression inner) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setInner(inner); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (inner == child) { 47 | inner = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public List getChildren() { 59 | List children = new LinkedList(); 60 | if (inner != null) { 61 | children.add(inner); 62 | } 63 | return children; 64 | } 65 | 66 | @Override 67 | public R accept(GenericVisitor v, A arg) { 68 | if (!check()) { 69 | return null; 70 | } 71 | return v.visit(this, arg); 72 | } 73 | 74 | @Override 75 | public void accept(VoidVisitor v, A arg) { 76 | if (check()) { 77 | v.visit(this, arg); 78 | } 79 | } 80 | 81 | public Expression getInner() { 82 | return inner; 83 | } 84 | 85 | public void setInner(Expression inner) { 86 | if (this.inner != null) { 87 | updateReferences(this.inner); 88 | } 89 | this.inner = inner; 90 | setAsParentNodeOf(inner); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | 97 | if (oldChild == inner) { 98 | setInner((Expression) newChild); 99 | updated = true; 100 | } 101 | 102 | return updated; 103 | } 104 | 105 | @Override 106 | public EnclosedExpr clone() throws CloneNotSupportedException { 107 | 108 | return new EnclosedExpr(clone(inner)); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/SuperExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.visitors.GenericVisitor; 21 | import org.walkmod.javalang.visitors.VoidVisitor; 22 | 23 | /** 24 | * @author Julio Vilmar Gesser 25 | */ 26 | public final class SuperExpr extends Expression { 27 | 28 | private Expression classExpr; 29 | 30 | public SuperExpr() {} 31 | 32 | public SuperExpr(Expression classExpr) { 33 | setClassExpr(classExpr); 34 | } 35 | 36 | public SuperExpr(int beginLine, int beginColumn, int endLine, int endColumn, Expression classExpr) { 37 | super(beginLine, beginColumn, endLine, endColumn); 38 | setClassExpr(classExpr); 39 | } 40 | 41 | @Override 42 | public boolean removeChild(Node child) { 43 | boolean result = false; 44 | if (child != null) { 45 | if (classExpr == child) { 46 | classExpr = null; 47 | result = true; 48 | } 49 | } 50 | if (result) { 51 | updateReferences(child); 52 | } 53 | return result; 54 | } 55 | 56 | @Override 57 | public List getChildren() { 58 | List children = super.getChildren(); 59 | if (classExpr != null) { 60 | children.add(classExpr); 61 | } 62 | return children; 63 | } 64 | 65 | @Override 66 | public R accept(GenericVisitor v, A arg) { 67 | if (!check()) { 68 | return null; 69 | } 70 | return v.visit(this, arg); 71 | } 72 | 73 | @Override 74 | public void accept(VoidVisitor v, A arg) { 75 | if (check()) { 76 | v.visit(this, arg); 77 | } 78 | } 79 | 80 | public Expression getClassExpr() { 81 | return classExpr; 82 | } 83 | 84 | public void setClassExpr(Expression classExpr) { 85 | if (this.classExpr != null) { 86 | updateReferences(this.classExpr); 87 | } 88 | this.classExpr = classExpr; 89 | setAsParentNodeOf(classExpr); 90 | } 91 | 92 | @Override 93 | public boolean replaceChildNode(Node oldChild, Node newChild) { 94 | boolean updated = false; 95 | if (oldChild == classExpr) { 96 | setClassExpr((Expression) newChild); 97 | updated = true; 98 | } 99 | return updated; 100 | } 101 | 102 | @Override 103 | public SuperExpr clone() throws CloneNotSupportedException { 104 | return new SuperExpr(clone(classExpr)); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/ExpressionStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.ast.expr.Expression; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class ExpressionStmt extends Statement { 28 | 29 | private Expression expr; 30 | 31 | public ExpressionStmt() {} 32 | 33 | public ExpressionStmt(Expression expr) { 34 | setExpression(expr); 35 | } 36 | 37 | public ExpressionStmt(int beginLine, int beginColumn, int endLine, int endColumn, Expression expr) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setExpression(expr); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (expr == child) { 47 | expr = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public List getChildren() { 59 | List children = super.getChildren(); 60 | if (expr != null) { 61 | children.add(expr); 62 | } 63 | return children; 64 | } 65 | 66 | @Override 67 | public R accept(GenericVisitor v, A arg) { 68 | if (!check()) { 69 | return null; 70 | } 71 | return v.visit(this, arg); 72 | } 73 | 74 | @Override 75 | public void accept(VoidVisitor v, A arg) { 76 | if (check()) { 77 | v.visit(this, arg); 78 | } 79 | } 80 | 81 | public Expression getExpression() { 82 | return expr; 83 | } 84 | 85 | public void setExpression(Expression expr) { 86 | if (this.expr != null) { 87 | updateReferences(this.expr); 88 | } 89 | this.expr = expr; 90 | setAsParentNodeOf(expr); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | if (oldChild == expr) { 97 | setExpression((Expression) newChild); 98 | updated = true; 99 | } 100 | 101 | return updated; 102 | } 103 | 104 | @Override 105 | public ExpressionStmt clone() throws CloneNotSupportedException { 106 | return new ExpressionStmt(clone(expr)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/ThisExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class ThisExpr extends Expression { 28 | 29 | private Expression classExpr; 30 | 31 | public ThisExpr() {} 32 | 33 | public ThisExpr(Expression classExpr) { 34 | setClassExpr(classExpr); 35 | } 36 | 37 | public ThisExpr(int beginLine, int beginColumn, int endLine, int endColumn, Expression classExpr) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setClassExpr(classExpr); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (classExpr == child) { 47 | classExpr = null; 48 | result = true; 49 | } 50 | } 51 | if (result) { 52 | updateReferences(child); 53 | } 54 | return result; 55 | } 56 | 57 | @Override 58 | public List getChildren() { 59 | List children = new LinkedList(); 60 | if (classExpr != null) { 61 | children.add(classExpr); 62 | } 63 | return children; 64 | } 65 | 66 | @Override 67 | public R accept(GenericVisitor v, A arg) { 68 | if (!check()) { 69 | return null; 70 | } 71 | return v.visit(this, arg); 72 | } 73 | 74 | @Override 75 | public void accept(VoidVisitor v, A arg) { 76 | if (check()) { 77 | v.visit(this, arg); 78 | } 79 | } 80 | 81 | public Expression getClassExpr() { 82 | return classExpr; 83 | } 84 | 85 | public void setClassExpr(Expression classExpr) { 86 | if (this.classExpr != null) { 87 | updateReferences(this.classExpr); 88 | } 89 | this.classExpr = classExpr; 90 | setAsParentNodeOf(classExpr); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | if (oldChild == classExpr) { 97 | setClassExpr((Expression) newChild); 98 | updated = true; 99 | } 100 | return updated; 101 | } 102 | 103 | @Override 104 | public ThisExpr clone() throws CloneNotSupportedException { 105 | return new ThisExpr(clone(classExpr)); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/TypeExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.type.Type; 22 | import org.walkmod.javalang.visitors.GenericVisitor; 23 | import org.walkmod.javalang.visitors.VoidVisitor; 24 | 25 | /** 26 | * This class is just instantiated as scopes for MethodReferenceExpr nodes to encapsulate Types. 27 | * 28 | * @author Raquel Pau 29 | * 30 | */ 31 | public class TypeExpr extends Expression { 32 | 33 | private Type type; 34 | 35 | public TypeExpr() {} 36 | 37 | public TypeExpr(Type type) { 38 | setType(type); 39 | } 40 | 41 | public TypeExpr(int beginLine, int beginColumn, int endLine, int endColumn, Type type) { 42 | super(beginLine, beginColumn, endLine, endColumn); 43 | setType(type); 44 | } 45 | 46 | @Override 47 | public boolean removeChild(Node child) { 48 | boolean result = false; 49 | 50 | if (child != null) { 51 | if (child == type) { 52 | type = null; 53 | result = true; 54 | } 55 | } 56 | if (result) { 57 | updateReferences(child); 58 | } 59 | return result; 60 | } 61 | 62 | @Override 63 | public List getChildren() { 64 | List children = new LinkedList(); 65 | if (type != null) { 66 | children.add(type); 67 | } 68 | return children; 69 | } 70 | 71 | @Override 72 | public R accept(GenericVisitor v, A arg) { 73 | if (!check()) { 74 | return null; 75 | } 76 | return v.visit(this, arg); 77 | } 78 | 79 | @Override 80 | public void accept(VoidVisitor v, A arg) { 81 | if (check()) { 82 | v.visit(this, arg); 83 | } 84 | } 85 | 86 | public Type getType() { 87 | return type; 88 | } 89 | 90 | public void setType(Type type) { 91 | if (this.type != null) { 92 | updateReferences(this.type); 93 | } 94 | this.type = type; 95 | setAsParentNodeOf(type); 96 | } 97 | 98 | @Override 99 | public boolean replaceChildNode(Node oldChild, Node newChild) { 100 | boolean updated = false; 101 | if (oldChild == type) { 102 | setType((Type) newChild); 103 | updated = true; 104 | } 105 | return updated; 106 | } 107 | 108 | @Override 109 | public TypeExpr clone() throws CloneNotSupportedException { 110 | return new TypeExpr(clone(type)); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/tags/TagsParserConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | /* Generated By:JavaCC: Do not edit this line. TagsParserConstants.java */ 16 | package org.walkmod.javalang.tags; 17 | 18 | /** 19 | * Token literal values and constants. 20 | * Generated by org.javacc.parser.OtherFilesGen#start() 21 | */ 22 | public interface TagsParserConstants { 23 | 24 | /** End of File. */ 25 | int EOF = 0; 26 | /** RegularExpression Id. */ 27 | int LINKPLAIN = 1; 28 | /** RegularExpression Id. */ 29 | int LINK = 2; 30 | /** RegularExpression Id. */ 31 | int VALUE = 3; 32 | /** RegularExpression Id. */ 33 | int PARAM = 4; 34 | /** RegularExpression Id. */ 35 | int RETURN = 5; 36 | /** RegularExpression Id. */ 37 | int THROWS = 6; 38 | /** RegularExpression Id. */ 39 | int EXCEPTION = 7; 40 | /** RegularExpression Id. */ 41 | int SEE = 8; 42 | /** RegularExpression Id. */ 43 | int SERIALFIELD = 9; 44 | /** RegularExpression Id. */ 45 | int SERIALDATA = 10; 46 | /** RegularExpression Id. */ 47 | int SERIAL = 11; 48 | /** RegularExpression Id. */ 49 | int INHERITDOC = 12; 50 | /** RegularExpression Id. */ 51 | int DOCROOT = 13; 52 | /** RegularExpression Id. */ 53 | int CODE = 14; 54 | /** RegularExpression Id. */ 55 | int DEPRECATED = 15; 56 | /** RegularExpression Id. */ 57 | int AUTHOR = 16; 58 | /** RegularExpression Id. */ 59 | int LITERAL = 17; 60 | /** RegularExpression Id. */ 61 | int SINCE = 18; 62 | /** RegularExpression Id. */ 63 | int VERSION = 19; 64 | /** RegularExpression Id. */ 65 | int OPENBRACE = 20; 66 | /** RegularExpression Id. */ 67 | int CLOSEBRACE = 21; 68 | /** RegularExpression Id. */ 69 | int ASTERISK = 22; 70 | /** RegularExpression Id. */ 71 | int IDENTIFIER = 23; 72 | /** RegularExpression Id. */ 73 | int LETTER = 24; 74 | /** RegularExpression Id. */ 75 | int PART_LETTER = 25; 76 | /** RegularExpression Id. */ 77 | int NAMECHAR = 26; 78 | /** RegularExpression Id. */ 79 | int OPERATION = 27; 80 | /** RegularExpression Id. */ 81 | int WORD = 28; 82 | /** RegularExpression Id. */ 83 | int SPACE = 29; 84 | /** RegularExpression Id. */ 85 | int BEGIN = 30; 86 | 87 | /** Lexical state. */ 88 | int DEFAULT = 0; 89 | 90 | /** Literal token values. */ 91 | String[] tokenImage = {"", "\"@linkplain\"", "\"@link\"", "\"@value\"", "\"@param\"", "\"@return\"", 92 | "\"@throws\"", "\"@exception\"", "\"@see\"", "\"@serialField\"", "\"@serialData\"", "\"@serial\"", 93 | "\"@inheritDoc\"", "\"@docRoot\"", "\"@code\"", "\"@deprecated\"", "\"@author\"", "\"@literal\"", 94 | "\"@since\"", "\"@version\"", "\"{\"", "\"}\"", "\"*\"", "", "", "", 95 | "", "", "", "", "",}; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/AnnotationExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | 16 | package org.walkmod.javalang.ast.expr; 17 | 18 | import java.util.Comparator; 19 | import java.util.LinkedList; 20 | import java.util.List; 21 | 22 | import org.walkmod.javalang.ast.Node; 23 | import org.walkmod.javalang.ast.SymbolDefinition; 24 | import org.walkmod.javalang.ast.SymbolReference; 25 | import org.walkmod.javalang.comparators.AnnotationExprComparator; 26 | import org.walkmod.merger.Mergeable; 27 | 28 | /** 29 | * @author Julio Vilmar Gesser 30 | */ 31 | public abstract class AnnotationExpr extends Expression implements Mergeable, SymbolReference { 32 | 33 | protected NameExpr name; 34 | 35 | private SymbolDefinition symbolDefinition; 36 | 37 | public AnnotationExpr() {} 38 | 39 | public AnnotationExpr(int beginLine, int beginColumn, int endLine, int endColumn) { 40 | super(beginLine, beginColumn, endLine, endColumn); 41 | } 42 | 43 | @Override 44 | public List getChildren() { 45 | List children = new LinkedList(); 46 | if (name != null) { 47 | children.add(name); 48 | } 49 | return children; 50 | } 51 | 52 | @Override 53 | public boolean removeChild(Node child) { 54 | boolean result = false; 55 | if (child != null) { 56 | if (name == child) { 57 | name = null; 58 | result = true; 59 | } 60 | } 61 | if (result) { 62 | updateReferences(child); 63 | } 64 | return result; 65 | } 66 | 67 | public NameExpr getName() { 68 | return name; 69 | } 70 | 71 | public void setName(NameExpr name) { 72 | if (this.name != null) { 73 | updateReferences(this.name); 74 | } 75 | this.name = name; 76 | setAsParentNodeOf(name); 77 | } 78 | 79 | @Override 80 | public Comparator getIdentityComparator() { 81 | return new AnnotationExprComparator(); 82 | } 83 | 84 | @Override 85 | public String getPrettySource(char indentationChar, int indentationLevel, int indentationSize) { 86 | String text = super.getPrettySource(indentationChar, 0, 0); 87 | text += " "; 88 | 89 | return text; 90 | } 91 | 92 | @Override 93 | public SymbolDefinition getSymbolDefinition() { 94 | return symbolDefinition; 95 | } 96 | 97 | @Override 98 | public void setSymbolDefinition(SymbolDefinition symbolDefinition) { 99 | this.symbolDefinition = symbolDefinition; 100 | } 101 | 102 | @Override 103 | public boolean replaceChildNode(Node oldChild, Node newChild) { 104 | if (name == oldChild) { 105 | setName((NameExpr) newChild); 106 | return true; 107 | } 108 | return false; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/stmt/LabeledStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.stmt; 16 | 17 | import java.util.List; 18 | 19 | import org.walkmod.javalang.ast.Node; 20 | import org.walkmod.javalang.visitors.GenericVisitor; 21 | import org.walkmod.javalang.visitors.VoidVisitor; 22 | 23 | /** 24 | * @author Julio Vilmar Gesser 25 | */ 26 | public final class LabeledStmt extends Statement { 27 | 28 | private String label; 29 | 30 | private Statement stmt; 31 | 32 | public LabeledStmt() {} 33 | 34 | public LabeledStmt(String label, Statement stmt) { 35 | this.label = label; 36 | setStmt(stmt); 37 | } 38 | 39 | public LabeledStmt(int beginLine, int beginColumn, int endLine, int endColumn, String label, Statement stmt) { 40 | super(beginLine, beginColumn, endLine, endColumn); 41 | this.label = label; 42 | setStmt(stmt); 43 | } 44 | 45 | @Override 46 | public boolean removeChild(Node child) { 47 | boolean result = false; 48 | if (child != null) { 49 | if (stmt == child) { 50 | stmt = null; 51 | result = true; 52 | } 53 | } 54 | if (result) { 55 | updateReferences(child); 56 | } 57 | return result; 58 | } 59 | 60 | @Override 61 | public List getChildren() { 62 | List children = super.getChildren(); 63 | if (stmt != null) { 64 | children.add(stmt); 65 | } 66 | return children; 67 | } 68 | 69 | @Override 70 | public R accept(GenericVisitor v, A arg) { 71 | if (!check()) { 72 | return null; 73 | } 74 | return v.visit(this, arg); 75 | } 76 | 77 | @Override 78 | public void accept(VoidVisitor v, A arg) { 79 | if (check()) { 80 | v.visit(this, arg); 81 | } 82 | } 83 | 84 | public String getLabel() { 85 | return label; 86 | } 87 | 88 | public Statement getStmt() { 89 | return stmt; 90 | } 91 | 92 | public void setLabel(String label) { 93 | this.label = label; 94 | } 95 | 96 | public void setStmt(Statement stmt) { 97 | if (this.stmt != null) { 98 | updateReferences(this.stmt); 99 | } 100 | this.stmt = stmt; 101 | setAsParentNodeOf(stmt); 102 | } 103 | 104 | @Override 105 | public boolean replaceChildNode(Node oldChild, Node newChild) { 106 | boolean updated = false; 107 | if (oldChild == stmt) { 108 | setStmt((Statement) newChild); 109 | updated = true; 110 | } 111 | 112 | return updated; 113 | } 114 | 115 | @Override 116 | public LabeledStmt clone() throws CloneNotSupportedException { 117 | return new LabeledStmt(label, clone(stmt)); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/body/MultiTypeParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.body; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.expr.AnnotationExpr; 22 | import org.walkmod.javalang.ast.type.Type; 23 | import org.walkmod.javalang.visitors.GenericVisitor; 24 | import org.walkmod.javalang.visitors.VoidVisitor; 25 | 26 | public class MultiTypeParameter extends BaseParameter { 27 | 28 | private List types; 29 | 30 | public MultiTypeParameter() {} 31 | 32 | public MultiTypeParameter(int modifiers, List annotations, List types, 33 | VariableDeclaratorId id) { 34 | super(modifiers, annotations, id); 35 | setTypes(types); 36 | } 37 | 38 | public MultiTypeParameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, 39 | List annotations, List types, VariableDeclaratorId id) { 40 | super(beginLine, beginColumn, endLine, endColumn, modifiers, annotations, id); 41 | setTypes(types); 42 | } 43 | 44 | @Override 45 | public List getChildren() { 46 | List children = super.getChildren(); 47 | if (types != null) { 48 | children.addAll(types); 49 | } 50 | return children; 51 | } 52 | 53 | @Override 54 | public boolean removeChild(Node child) { 55 | boolean result = false; 56 | if (child != null) { 57 | result = super.removeChild(child); 58 | if (!result) { 59 | if (child instanceof Type) { 60 | if (types != null) { 61 | List typesAux = new LinkedList(types); 62 | result = typesAux.remove(child); 63 | types = typesAux; 64 | } 65 | } 66 | } 67 | } 68 | if (result) { 69 | updateReferences(child); 70 | } 71 | return result; 72 | } 73 | 74 | @Override 75 | public R accept(GenericVisitor v, A arg) { 76 | if (!check()) { 77 | return null; 78 | } 79 | return v.visit(this, arg); 80 | } 81 | 82 | @Override 83 | public void accept(VoidVisitor v, A arg) { 84 | if (check()) { 85 | v.visit(this, arg); 86 | } 87 | } 88 | 89 | public List getTypes() { 90 | return types; 91 | } 92 | 93 | public void setTypes(List types) { 94 | this.types = types; 95 | setAsParentNodeOf(types); 96 | } 97 | 98 | @Override 99 | public MultiTypeParameter clone() throws CloneNotSupportedException { 100 | return new MultiTypeParameter(getModifiers(), clone(getAnnotations()), clone(getTypes()), clone(getId())); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/NameExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.walkmod.javalang.ast.Node; 22 | import org.walkmod.javalang.ast.ScopeAwareUtil; 23 | import org.walkmod.javalang.ast.SymbolDefinition; 24 | import org.walkmod.javalang.ast.SymbolReference; 25 | import org.walkmod.javalang.visitors.GenericVisitor; 26 | import org.walkmod.javalang.visitors.VoidVisitor; 27 | 28 | /** 29 | * @author Julio Vilmar Gesser 30 | */ 31 | public class NameExpr extends Expression implements SymbolReference { 32 | 33 | private String name; 34 | 35 | private SymbolDefinition symbolDefinition; 36 | 37 | public NameExpr() {} 38 | 39 | public NameExpr(String name) { 40 | this.name = name; 41 | } 42 | 43 | public NameExpr(int beginLine, int beginColumn, int endLine, int endColumn, String name) { 44 | super(beginLine, beginColumn, endLine, endColumn); 45 | this.name = name; 46 | } 47 | 48 | @Override 49 | public boolean removeChild(Node child) { 50 | return false; 51 | } 52 | 53 | @Override 54 | public List getChildren() { 55 | return new LinkedList(); 56 | } 57 | 58 | @Override 59 | public R accept(GenericVisitor v, A arg) { 60 | if (!check()) { 61 | return null; 62 | } 63 | return v.visit(this, arg); 64 | } 65 | 66 | @Override 67 | public void accept(VoidVisitor v, A arg) { 68 | if (check()) { 69 | v.visit(this, arg); 70 | } 71 | } 72 | 73 | public final String getName() { 74 | return name; 75 | } 76 | 77 | public final void setName(String name) { 78 | this.name = name; 79 | } 80 | 81 | @Override 82 | public SymbolDefinition getSymbolDefinition() { 83 | return symbolDefinition; 84 | } 85 | 86 | @Override 87 | public void setSymbolDefinition(SymbolDefinition symbolDefinition) { 88 | this.symbolDefinition = symbolDefinition; 89 | } 90 | 91 | @Override 92 | public boolean replaceChildNode(Node oldChild, Node newChild) { 93 | return false; 94 | } 95 | 96 | @Override 97 | public NameExpr clone() throws CloneNotSupportedException { 98 | return new NameExpr(name); 99 | } 100 | 101 | @Override 102 | public Map getVariableDefinitions() { 103 | return ScopeAwareUtil.getVariableDefinitions(this); 104 | } 105 | 106 | @Override 107 | public Map> getMethodDefinitions() { 108 | return ScopeAwareUtil.getMethodDefinitions(NameExpr.this); 109 | } 110 | 111 | @Override 112 | public Map getTypeDefinitions() { 113 | return ScopeAwareUtil.getTypeDefinitions(NameExpr.this); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/ArrayInitializerExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class ArrayInitializerExpr extends Expression { 28 | 29 | private List values; 30 | 31 | public ArrayInitializerExpr() {} 32 | 33 | public ArrayInitializerExpr(List values) { 34 | this.values = values; 35 | } 36 | 37 | public ArrayInitializerExpr(int beginLine, int beginColumn, int endLine, int endColumn, List values) { 38 | super(beginLine, beginColumn, endLine, endColumn); 39 | setValues(values); 40 | } 41 | 42 | @Override 43 | public boolean removeChild(Node child) { 44 | boolean result = false; 45 | if (child != null) { 46 | if (values != null) { 47 | if (child instanceof Expression) { 48 | List valuesAux = new LinkedList(); 49 | result = valuesAux.remove(child); 50 | values = valuesAux; 51 | } 52 | } 53 | } 54 | if (result) { 55 | updateReferences(child); 56 | } 57 | return result; 58 | } 59 | 60 | @Override 61 | public List getChildren() { 62 | List children = new LinkedList(); 63 | if (values != null) { 64 | children.addAll(values); 65 | } 66 | return children; 67 | } 68 | 69 | @Override 70 | public R accept(GenericVisitor v, A arg) { 71 | if (!check()) { 72 | return null; 73 | } 74 | return v.visit(this, arg); 75 | } 76 | 77 | @Override 78 | public void accept(VoidVisitor v, A arg) { 79 | if (check()) { 80 | v.visit(this, arg); 81 | } 82 | } 83 | 84 | public List getValues() { 85 | return values; 86 | } 87 | 88 | public void setValues(List values) { 89 | this.values = values; 90 | setAsParentNodeOf(values); 91 | } 92 | 93 | @Override 94 | public boolean replaceChildNode(Node oldChild, Node newChild) { 95 | boolean updated = false; 96 | if (values != null) { 97 | List auxValues = new LinkedList(values); 98 | updated = replaceChildNodeInList(oldChild, newChild, auxValues); 99 | values = auxValues; 100 | } 101 | return updated; 102 | 103 | } 104 | 105 | @Override 106 | public ArrayInitializerExpr clone() throws CloneNotSupportedException { 107 | 108 | return new ArrayInitializerExpr(clone(values)); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/MemberValuePair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.visitors.GenericVisitor; 22 | import org.walkmod.javalang.visitors.VoidVisitor; 23 | 24 | /** 25 | * @author Julio Vilmar Gesser 26 | */ 27 | public final class MemberValuePair extends Node { 28 | 29 | private String name; 30 | 31 | private Expression value; 32 | 33 | public MemberValuePair() {} 34 | 35 | public MemberValuePair(String name, Expression value) { 36 | this.name = name; 37 | setValue(value); 38 | } 39 | 40 | public MemberValuePair(int beginLine, int beginColumn, int endLine, int endColumn, String name, Expression value) { 41 | super(beginLine, beginColumn, endLine, endColumn); 42 | this.name = name; 43 | setValue(value); 44 | } 45 | 46 | @Override 47 | public boolean removeChild(Node child) { 48 | boolean result = false; 49 | 50 | if (child != null) { 51 | if (value == child) { 52 | value = null; 53 | result = true; 54 | } 55 | } 56 | if (result) { 57 | updateReferences(child); 58 | } 59 | return result; 60 | } 61 | 62 | @Override 63 | public List getChildren() { 64 | List children = new LinkedList(); 65 | if (value != null) { 66 | children.add(value); 67 | } 68 | return children; 69 | } 70 | 71 | @Override 72 | public R accept(GenericVisitor v, A arg) { 73 | if (!check()) { 74 | return null; 75 | } 76 | return v.visit(this, arg); 77 | } 78 | 79 | @Override 80 | public void accept(VoidVisitor v, A arg) { 81 | if (check()) { 82 | v.visit(this, arg); 83 | } 84 | } 85 | 86 | public String getName() { 87 | return name; 88 | } 89 | 90 | public Expression getValue() { 91 | return value; 92 | } 93 | 94 | public void setName(String name) { 95 | this.name = name; 96 | } 97 | 98 | public void setValue(Expression value) { 99 | if (this.value != null) { 100 | updateReferences(this.value); 101 | } 102 | this.value = value; 103 | setAsParentNodeOf(value); 104 | } 105 | 106 | @Override 107 | public boolean replaceChildNode(Node oldChild, Node newChild) { 108 | boolean updated = false; 109 | 110 | if (oldChild == value) { 111 | setValue((Expression) newChild); 112 | updated = true; 113 | } 114 | 115 | return updated; 116 | } 117 | 118 | @Override 119 | public MemberValuePair clone() throws CloneNotSupportedException { 120 | return new MemberValuePair(new String(name), clone(value)); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/org/walkmod/javalang/ast/expr/SingleMemberAnnotationExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Raquel Pau and Albert Coroleu. 3 | * 4 | * Walkmod is free software: you can redistribute it and/or modify it under the terms of the GNU 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * Walkmod is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 | * General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with Walkmod. If 13 | * not, see . 14 | */ 15 | package org.walkmod.javalang.ast.expr; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | import org.walkmod.javalang.ast.Node; 21 | import org.walkmod.javalang.ast.ScopeAwareUtil; 22 | import org.walkmod.javalang.ast.SymbolDefinition; 23 | import org.walkmod.javalang.visitors.GenericVisitor; 24 | import org.walkmod.javalang.visitors.VoidVisitor; 25 | import org.walkmod.merger.MergeEngine; 26 | 27 | /** 28 | * @author Julio Vilmar Gesser 29 | */ 30 | public final class SingleMemberAnnotationExpr extends AnnotationExpr { 31 | 32 | private Expression memberValue; 33 | 34 | public SingleMemberAnnotationExpr() {} 35 | 36 | public SingleMemberAnnotationExpr(NameExpr name, Expression memberValue) { 37 | setName(name); 38 | setMemberValue(memberValue); 39 | } 40 | 41 | public SingleMemberAnnotationExpr(int beginLine, int beginColumn, int endLine, int endColumn, NameExpr name, 42 | Expression memberValue) { 43 | super(beginLine, beginColumn, endLine, endColumn); 44 | setName(name); 45 | setMemberValue(memberValue); 46 | } 47 | 48 | @Override 49 | public List getChildren() { 50 | List children = super.getChildren(); 51 | if (memberValue != null) { 52 | children.add(memberValue); 53 | } 54 | return children; 55 | } 56 | 57 | @Override 58 | public R accept(GenericVisitor v, A arg) { 59 | if (!check()) { 60 | return null; 61 | } 62 | return v.visit(this, arg); 63 | } 64 | 65 | @Override 66 | public void accept(VoidVisitor v, A arg) { 67 | if (check()) { 68 | v.visit(this, arg); 69 | } 70 | } 71 | 72 | public Expression getMemberValue() { 73 | return memberValue; 74 | } 75 | 76 | public void setMemberValue(Expression memberValue) { 77 | this.memberValue = memberValue; 78 | setAsParentNodeOf(memberValue); 79 | } 80 | 81 | @Override 82 | public void merge(AnnotationExpr t1, MergeEngine configuration) { 83 | // nothing 84 | 85 | } 86 | 87 | @Override 88 | public SingleMemberAnnotationExpr clone() throws CloneNotSupportedException { 89 | 90 | return new SingleMemberAnnotationExpr(clone(name), clone(memberValue)); 91 | } 92 | 93 | @Override 94 | public Map getVariableDefinitions() { 95 | return ScopeAwareUtil.getVariableDefinitions(this); 96 | } 97 | 98 | @Override 99 | public Map> getMethodDefinitions() { 100 | return ScopeAwareUtil.getMethodDefinitions(SingleMemberAnnotationExpr.this); 101 | } 102 | 103 | @Override 104 | public Map getTypeDefinitions() { 105 | return ScopeAwareUtil.getTypeDefinitions(SingleMemberAnnotationExpr.this); 106 | } 107 | 108 | } 109 | --------------------------------------------------------------------------------