Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off JavaParser static interface to QuickJavaParser class
- Loading branch information
Showing
155 changed files
with
2,339 additions
and
1,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 89 additions & 89 deletions
178
.../java/com/github/javaparser/generator/core/visitor/NoCommentHashCodeVisitorGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,89 +1,89 @@ | |||
/* | /* | ||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser. | * Copyright (C) 2007-2010 Júlio Vilmar Gesser. | ||
* Copyright (C) 2011, 2013-2016 The JavaParser Team. | * Copyright (C) 2011, 2013-2016 The JavaParser Team. | ||
* | * | ||
* This file is part of JavaParser. | * This file is part of JavaParser. | ||
* | * | ||
* JavaParser can be used either under the terms of | * JavaParser can be used either under the terms of | ||
* a) the GNU Lesser General Public License as published by | * a) the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | * the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | * (at your option) any later version. | ||
* b) the terms of the Apache License | * b) the terms of the Apache License | ||
* | * | ||
* You should have received a copy of both licenses in LICENCE.LGPL and | * You should have received a copy of both licenses in LICENCE.LGPL and | ||
* LICENCE.APACHE. Please refer to those files for details. | * LICENCE.APACHE. Please refer to those files for details. | ||
* | * | ||
* JavaParser is distributed in the hope that it will be useful, | * JavaParser is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | * GNU Lesser General Public License for more details. | ||
*/ | */ | ||
|
|
||
package com.github.javaparser.generator.core.visitor; | package com.github.javaparser.generator.core.visitor; | ||
|
|
||
import static com.github.javaparser.JavaParser.parseStatement; | import java.util.List; | ||
|
|
||
import java.util.List; | import com.github.javaparser.ast.CompilationUnit; | ||
|
import com.github.javaparser.ast.body.MethodDeclaration; | ||
import com.github.javaparser.ast.CompilationUnit; | import com.github.javaparser.ast.stmt.BlockStmt; | ||
import com.github.javaparser.ast.body.MethodDeclaration; | import com.github.javaparser.generator.VisitorGenerator; | ||
import com.github.javaparser.ast.stmt.BlockStmt; | import com.github.javaparser.metamodel.BaseNodeMetaModel; | ||
import com.github.javaparser.generator.VisitorGenerator; | import com.github.javaparser.metamodel.JavaParserMetaModel; | ||
import com.github.javaparser.metamodel.BaseNodeMetaModel; | import com.github.javaparser.metamodel.PropertyMetaModel; | ||
import com.github.javaparser.metamodel.JavaParserMetaModel; | import com.github.javaparser.utils.SeparatedItemStringBuilder; | ||
import com.github.javaparser.metamodel.PropertyMetaModel; | import com.github.javaparser.utils.SourceRoot; | ||
import com.github.javaparser.utils.SeparatedItemStringBuilder; |
|
||
import com.github.javaparser.utils.SourceRoot; | import static com.github.javaparser.QuickJavaParser.parseStatement; | ||
|
|
||
public class NoCommentHashCodeVisitorGenerator extends VisitorGenerator { | public class NoCommentHashCodeVisitorGenerator extends VisitorGenerator { | ||
|
|
||
public NoCommentHashCodeVisitorGenerator(SourceRoot sourceRoot) { | public NoCommentHashCodeVisitorGenerator(SourceRoot sourceRoot) { | ||
super(sourceRoot, "com.github.javaparser.ast.visitor", "NoCommentHashCodeVisitor", "Integer", "Void", true); | super(sourceRoot, "com.github.javaparser.ast.visitor", "NoCommentHashCodeVisitor", "Integer", "Void", true); | ||
} | } | ||
|
|
||
@Override | @Override | ||
protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration visitMethod, | protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration visitMethod, | ||
CompilationUnit compilationUnit) { | CompilationUnit compilationUnit) { | ||
visitMethod.getParameters().forEach(p -> p.setFinal(true)); | visitMethod.getParameters().forEach(p -> p.setFinal(true)); | ||
|
|
||
final BlockStmt body = visitMethod.getBody().get(); | final BlockStmt body = visitMethod.getBody().get(); | ||
body.getStatements().clear(); | body.getStatements().clear(); | ||
|
|
||
final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("return ", "* 31 +", ";"); | final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("return ", "* 31 +", ";"); | ||
final List<PropertyMetaModel> propertyMetaModels = node.getAllPropertyMetaModels(); | final List<PropertyMetaModel> propertyMetaModels = node.getAllPropertyMetaModels(); | ||
if (node.equals(JavaParserMetaModel.lineCommentMetaModel) | if (node.equals(JavaParserMetaModel.lineCommentMetaModel) | ||
|| node.equals(JavaParserMetaModel.blockCommentMetaModel) | || node.equals(JavaParserMetaModel.blockCommentMetaModel) | ||
|| node.equals(JavaParserMetaModel.javadocCommentMetaModel) || propertyMetaModels.isEmpty()) { | || node.equals(JavaParserMetaModel.javadocCommentMetaModel) || propertyMetaModels.isEmpty()) { | ||
builder.append("0"); | builder.append("0"); | ||
} else { | } else { | ||
for (PropertyMetaModel field : propertyMetaModels) { | for (PropertyMetaModel field : propertyMetaModels) { | ||
final String getter = field.getGetterMethodName() + "()"; | final String getter = field.getGetterMethodName() + "()"; | ||
if (field.equals(JavaParserMetaModel.nodeMetaModel.commentPropertyMetaModel)) { | if (field.equals(JavaParserMetaModel.nodeMetaModel.commentPropertyMetaModel)) { | ||
if (propertyMetaModels.size() == 1) { | if (propertyMetaModels.size() == 1) { | ||
builder.append("0"); | builder.append("0"); | ||
break; | break; | ||
} else | } else | ||
continue; | continue; | ||
} | } | ||
// Is this field another AST node? Visit it. | // Is this field another AST node? Visit it. | ||
if (field.getNodeReference().isPresent()) { | if (field.getNodeReference().isPresent()) { | ||
if (field.isOptional()) { | if (field.isOptional()) { | ||
builder.append("(n.%s.isPresent()? n.%s.get().accept(this, arg):0)", getter, getter); | builder.append("(n.%s.isPresent()? n.%s.get().accept(this, arg):0)", getter, getter); | ||
} else { | } else { | ||
builder.append("(n.%s.accept(this, arg))", getter); | builder.append("(n.%s.accept(this, arg))", getter); | ||
} | } | ||
} else { | } else { | ||
Class<?> type = field.getType(); | Class<?> type = field.getType(); | ||
if (type.equals(boolean.class)) { | if (type.equals(boolean.class)) { | ||
builder.append("(n.%s?1:0)", getter); | builder.append("(n.%s?1:0)", getter); | ||
} else if (type.equals(int.class)) { | } else if (type.equals(int.class)) { | ||
builder.append("n.%s", getter); | builder.append("n.%s", getter); | ||
} else { | } else { | ||
builder.append("(n.%s.hashCode())", getter); | builder.append("(n.%s.hashCode())", getter); | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
body.addStatement(parseStatement(builder.toString())); | body.addStatement(parseStatement(builder.toString())); | ||
} | } | ||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.