List of usage examples for org.eclipse.jdt.core.dom PackageDeclaration setJavadoc
public void setJavadoc(Javadoc docComment)
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGenerator.java
License:Apache License
/** * Generate comment for the compilation unit. * /*w w w . ja va2 s . co m*/ * @param ast * the JDT Java AST * @param packageDeclaration * the package declaration where we want to insert the javadoc * @param comment * comments */ @SuppressWarnings("unchecked") public void generatePackageJavadoc(AST ast, PackageDeclaration packageDeclaration, String... comment) { Javadoc javadoc = ast.newJavadoc(); for (String actualComment : comment) { TagElement tagElement = ast.newTagElement(); tagElement.setTagName(actualComment); javadoc.tags().add(tagElement); } packageDeclaration.setJavadoc(javadoc); }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public void convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, PackageDeclaration packageDeclaration) { switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: return;// w w w .j a va 2s .co m } if (packageDeclaration.getJavadoc() == null) { if (javadoc != null) { if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) { this.commentMapper = new DefaultCommentMapper(this.commentsTable); } Comment comment = this.commentMapper.getComment(javadoc.sourceStart); if (comment != null && comment.isDocComment() && comment.getParent() == null) { Javadoc docComment = (Javadoc) comment; if (this.resolveBindings) { recordNodes(docComment, javadoc); // resolve member and method references binding Iterator tags = docComment.tags().listIterator(); while (tags.hasNext()) { recordNodes(javadoc, (TagElement) tags.next()); } } packageDeclaration.setJavadoc(docComment); } } } }
From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java
License:LGPL
@SuppressWarnings({ "unchecked", "rawtypes" })
private IStrategoAppl constructASTNode(IStrategoConstructor ctr, IStrategoTerm[] kids) {
int index = ctorNameToIndex(ctr);
switch (index) {
case ANNOTATION_TYPE_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isExtendedModifierList(kids[1])
|| !isSimpleName(kids[2]) || !isBodyDeclarationList(kids[3]))
return null;
AnnotationTypeDeclaration x = ast.newAnnotationTypeDeclaration();
if (isNone(kids[0]))
x.setJavadoc(null);/*from w w w. jav a 2 s .co m*/
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asExtendedModifierList(kids[1]));
x.setName(asSimpleName(kids[2]));
x.bodyDeclarations().addAll(asBodyDeclarationList(kids[3]));
return wrap(x);
}
case ANNOTATION_TYPE_MEMBER_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isModifierList(kids[1]) || !isType(kids[2])
|| !isSimpleName(kids[3]) || (!isExpression(kids[4]) && !isNone(kids[4])))
return null;
AnnotationTypeMemberDeclaration x = ast.newAnnotationTypeMemberDeclaration();
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asModifierList(kids[1]));
x.setType(asType(kids[2]));
x.setName(asSimpleName(kids[3]));
if (isNone(kids[4]))
x.setDefault(null);
else
x.setDefault(asExpression(kids[4]));
return wrap(x);
}
case ANONYMOUS_CLASS_DECLARATION: {
if (!isBodyDeclarationList(kids[0]))
return null;
AnonymousClassDeclaration x = ast.newAnonymousClassDeclaration();
x.bodyDeclarations().addAll(asBodyDeclarationList(kids[0]));
return wrap(x);
}
case ARRAY_ACCESS: {
if (!isExpression(kids[0]) || !isExpression(kids[1]))
return null;
ArrayAccess x = ast.newArrayAccess();
x.setArray(asExpression(kids[0]));
x.setIndex(asExpression(kids[1]));
return wrap(x);
}
case ARRAY_CREATION: {
if (!isArrayType(kids[0]) || !isExpressionList(kids[1])
|| (!isArrayInitializer(kids[2]) && !isNone(kids[2])))
return null;
ArrayCreation x = ast.newArrayCreation();
x.setType(asArrayType(kids[0]));
x.dimensions().addAll(asExpressionList(kids[1]));
if (isNone(kids[2]))
x.setInitializer(null);
else
x.setInitializer(asArrayInitializer(kids[2]));
return wrap(x);
}
case ARRAY_INITIALIZER: {
if (!isExpressionList(kids[0]))
return null;
ArrayInitializer x = ast.newArrayInitializer();
x.expressions().addAll(asExpressionList(kids[0]));
return wrap(x);
}
case ARRAY_TYPE: {
if (!isType(kids[0]) || !isInt(kids[1]) || !isType(kids[2]))
return null;
ArrayType x = ast.newArrayType(asType(kids[2]), asInt(kids[1]));
x.setComponentType(asType(kids[0]));
return wrap(x);
}
case ASSERT_STATEMENT: {
if (!isExpression(kids[0]) || !(isExpression(kids[1]) || isNone(kids[1])))
return null;
AssertStatement x = ast.newAssertStatement();
x.setExpression(asExpression(kids[0]));
if (isNone(kids[1]))
x.setMessage(null);
else
x.setMessage(asExpression(kids[1]));
return wrap(x);
}
case ASSIGNMENT: {
if (!isAssignmentOperator(kids[0]) || !isExpression(kids[1]) || !isExpression(kids[2]))
return null;
Assignment x = ast.newAssignment();
x.setOperator(asAssignmentOperator(kids[0]));
x.setLeftHandSide(asExpression(kids[1]));
x.setRightHandSide(asExpression(kids[2]));
return wrap(x);
}
case ASSIGNMENT_OPERATOR: {
if (!isString(kids[0]))
return null;
return wrap(Assignment.Operator.toOperator(asString(kids[0])));
}
case BLOCK: {
if (!isStatementList(kids[0]))
return null;
Block x = ast.newBlock();
x.statements().addAll(asStatementList(kids[0]));
return wrap(x);
}
case BLOCK_COMMENT: {
BlockComment x = ast.newBlockComment();
return wrap(x);
}
case BOOLEAN_LITERAL: {
if (!isInt(kids[0]))
return null;
return wrap(ast.newBooleanLiteral(asInt(kids[0]) == 1));
}
case BOOLEAN_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.BOOLEAN));
}
case BREAK_STATEMENT: {
if (!isSimpleName(kids[0]) && !isNone(kids[0]))
return null;
BreakStatement x = ast.newBreakStatement();
if (isNone(kids[0]))
x.setLabel(null);
else
x.setLabel(asSimpleName(kids[0]));
return wrap(x);
}
case BYTE_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.BYTE));
}
case CAST_EXPRESSION: {
if (!isType(kids[0]) || !isExpression(kids[1]))
return null;
CastExpression x = ast.newCastExpression();
x.setType(asType(kids[0]));
x.setExpression(asExpression(kids[1]));
return wrap(x);
}
case CATCH_CLAUSE: {
if (!isSingleVariableDeclaration(kids[0]) || !isBlock(kids[1]))
return null;
CatchClause x = ast.newCatchClause();
x.setException(asSingleVariableDeclaration(kids[0]));
x.setBody(asBlock(kids[1]));
return wrap(x);
}
case CHARACTER_LITERAL: {
if (!isInt(kids[0]))
return null;
CharacterLiteral x = ast.newCharacterLiteral();
x.setCharValue((char) asInt(kids[0]));
return wrap(x);
}
case CLASS_INSTANCE_CREATION: {
if ((!isExpression(kids[0]) && !isNone(kids[0])) || !isType(kids[1])
|| (!isAnonymousClassDeclaration(kids[2]) && !isNone(kids[2])) || !isExpressionList(kids[3]))
return null;
ClassInstanceCreation x = ast.newClassInstanceCreation();
if (isNone(kids[0]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[0]));
x.setType(asType(kids[1]));
if (isNone(kids[2]))
x.setAnonymousClassDeclaration(null);
else
x.setAnonymousClassDeclaration(asAnonymousClassDeclaration(kids[2]));
x.arguments().addAll(asExpressionList(kids[3]));
return wrap(x);
}
case COMPILATION_UNIT: {
if ((!isPackageDeclaration(kids[0]) && !isNone(kids[0])) || !isImportDeclarationList(kids[1])
|| !isAbstractTypeDeclarationList(kids[2]))
return null;
CompilationUnit x = ast.newCompilationUnit();
if (isNone(kids[0]))
x.setPackage(null);
else
x.setPackage(asPackageDeclaration(kids[0]));
x.imports().addAll(asImportDeclarationList(kids[1]));
x.types().addAll(asAbstractTypeDeclarationList(kids[2]));
return wrap(x);
}
case CONDITIONAL_EXPRESSION: {
if (!isExpression(kids[0]) || !isExpression(kids[1]) || !isExpression(kids[2]))
return null;
ConditionalExpression x = ast.newConditionalExpression();
x.setExpression(asExpression(kids[0]));
x.setThenExpression(asExpression(kids[1]));
x.setElseExpression(asExpression(kids[2]));
return wrap(x);
}
case CONSTRUCTOR_INVOCATION: {
if (!isExpressionList(kids[0]))
return null;
ConstructorInvocation x = ast.newConstructorInvocation();
x.arguments().addAll(asExpressionList(kids[0]));
return wrap(x);
}
case CONTINUE_STATEMENT: {
if (!isSimpleName(kids[0]) && !isNone(kids[0]))
return null;
ContinueStatement x = ast.newContinueStatement();
if (isNone(kids[0]))
x.setLabel(null);
else
x.setLabel(asSimpleName(kids[0]));
return wrap(x);
}
case DO_STATEMENT: {
DoStatement x = ast.newDoStatement();
x.setExpression(asExpression(kids[0]));
x.setBody(asStatement(kids[1]));
return wrap(x);
}
case DOUBLE_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.DOUBLE));
}
case EMPTY_STATEMENT: {
return wrap(ast.newEmptyStatement());
}
case ENHANCED_FOR_STATEMENT: {
if (!isSingleVariableDeclaration(kids[0]) || !isExpression(kids[1]) || !isStatement(kids[2]))
return null;
EnhancedForStatement x = ast.newEnhancedForStatement();
x.setParameter(asSingleVariableDeclaration(kids[0]));
x.setExpression(asExpression(kids[1]));
x.setBody(asStatement(kids[2]));
return wrap(x);
}
case ENUM_CONSTANT_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isModifierList(kids[1]) || !isSimpleName(kids[2])
|| !isExpressionList(kids[3]) || !isAnonymousClassDeclaration(kids[4]))
return null;
EnumConstantDeclaration x = ast.newEnumConstantDeclaration();
if (isNone(kids[0]))
x.setJavadoc(null);
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asModifierList(kids[1]));
x.setName(asSimpleName(kids[2]));
x.arguments().addAll(asExpressionList(kids[3]));
x.setAnonymousClassDeclaration(asAnonymousClassDeclaration(kids[4]));
return wrap(x);
}
case ENUM_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isModifierList(kids[1]) || !isSimpleName(kids[2])
|| !isTypeList(kids[3]) || !isEnumConstantDeclarationList(kids[4])
|| !isBodyDeclarationList(kids[5]))
return null;
EnumDeclaration x = ast.newEnumDeclaration();
if (isNone(kids[0]))
x.setJavadoc(null);
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asModifierList(kids[1]));
x.setName(asSimpleName(kids[2]));
x.superInterfaceTypes().addAll(asTypeList(kids[3]));
x.enumConstants().addAll(asEnumConstantDeclarationList(kids[4]));
x.bodyDeclarations().addAll(asBodyDeclarationList(kids[5]));
return wrap(x);
}
case EXPRESSION_STATEMENT: {
if (!isExpression(kids[0]))
return null;
return wrap(ast.newExpressionStatement(asExpression(kids[0])));
}
case FIELD_ACCESS: {
if (!isExpression(kids[0]) || !isSimpleName(kids[1]))
return null;
FieldAccess x = ast.newFieldAccess();
x.setExpression(asExpression(kids[0]));
x.setName(asSimpleName(kids[1]));
return wrap(x);
}
case FIELD_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isModifierList(kids[1]) || !isType(kids[2])
|| !isNonEmptyVariableDeclarationFragmentList(kids[3]))
return null;
List y = asFragmentList(kids[3]);
FieldDeclaration x = ast.newFieldDeclaration((VariableDeclarationFragment) y.remove(0));
if (isNone(kids[0]))
x.setJavadoc(null);
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asModifierList(kids[1]));
x.setType(asType(kids[2]));
x.fragments().addAll(y);
return wrap(x);
}
case FLOAT_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.FLOAT));
}
case FOR_STATEMENT: {
if (!isExpressionList(kids[0]) || (!isExpression(kids[1]) && !isNone(kids[1]))
|| !isExpressionList(kids[2]) || !isStatement(kids[3]))
return null;
ForStatement x = ast.newForStatement();
x.initializers().addAll(asExpressionList(kids[0]));
if (isNone(kids[1]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[1]));
x.updaters().addAll(asExpressionList(kids[2]));
x.setBody(asStatement(kids[3]));
return wrap(x);
}
case IF_STATEMENT: {
if (!isExpression(kids[0]) || !isStatement(kids[1]) || (!isStatement(kids[2]) && !isNone(kids[2])))
return null;
IfStatement x = ast.newIfStatement();
x.setExpression(asExpression(kids[0]));
x.setThenStatement(asStatement(kids[1]));
if (isNone(kids[2]))
x.setElseStatement(null);
else
x.setElseStatement(asStatement(kids[2]));
return wrap(x);
}
case IMPORT_DECLARATION: {
if (!isName(kids[0]) && !isInt(kids[1]) && !isInt(kids[2]))
return null;
ImportDeclaration x = ast.newImportDeclaration();
x.setName(asName(kids[0]));
x.setStatic(((IStrategoInt) kids[1]).intValue() > 0);
x.setOnDemand(((IStrategoInt) kids[2]).intValue() > 0);
return wrap(x);
}
case INFIX_EXPRESSION: {
if (!isOperator(kids[0]) || !isExpression(kids[1]) || !isExpression(kids[2])
|| !isExpressionList(kids[3]))
return null;
InfixExpression x = ast.newInfixExpression();
x.setOperator(asOperator(kids[0]));
x.setLeftOperand(asExpression(kids[1]));
x.setRightOperand(asExpression(kids[2]));
x.extendedOperands().addAll(asExpressionList(kids[3]));
return wrap(x);
}
case INITIALIZER: {
if (!isBlock(kids[0]))
return null;
Initializer x = ast.newInitializer();
x.setBody(asBlock(kids[0]));
return wrap(x);
}
case INSTANCEOF_EXPRESSION: {
if (!isExpression(kids[0]) || !isType(kids[1]))
return null;
InstanceofExpression x = ast.newInstanceofExpression();
x.setLeftOperand(asExpression(kids[0]));
x.setRightOperand(asType(kids[1]));
return wrap(x);
}
case INT_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.INT));
}
case JAVADOC: {
if (!isTagElementList(kids[0]))
return null;
Javadoc x = ast.newJavadoc();
x.tags().addAll(asTagElementList(kids[0]));
return wrap(x);
}
case LABELED_STATEMENT: {
if (!isSimpleName(kids[0]) || !isStatement(kids[1]))
return null;
LabeledStatement x = ast.newLabeledStatement();
x.setLabel(asSimpleName(kids[0]));
x.setBody(asStatement(kids[1]));
return wrap(x);
}
case LINE_COMMENT: {
LineComment x = ast.newLineComment();
return wrap(x);
}
case LONG_TYPE: {
return wrap(ast.newPrimitiveType(PrimitiveType.INT));
}
case MARKER_ANNOTATION: {
if (!isName(kids[0]))
return null;
MarkerAnnotation x = ast.newMarkerAnnotation();
x.setTypeName(asName(kids[0]));
return wrap(x);
}
case MEMBER_REF: {
if (!isSimpleName(kids[0]) || !isName(kids[1]))
return null;
MemberRef x = ast.newMemberRef();
x.setName(asSimpleName(kids[0]));
x.setQualifier(asName(kids[1]));
return wrap(x);
}
case MEMBER_VALUE_PAIR: {
if (!isSimpleName(kids[0]) || !isExpression(kids[1]))
return null;
MemberValuePair x = ast.newMemberValuePair();
x.setName(asSimpleName(kids[0]));
x.setValue(asExpression(kids[1]));
return wrap(x);
}
case METHOD_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isExtendedModifierList(kids[1])
|| (!isType(kids[2]) && !isNone(kids[2])) || !isTypeParameterList(kids[3])
|| !isSimpleName(kids[4]) || !isSingleVariableDeclarationList(kids[5]) || !isNameList(kids[6])
|| (!isBlock(kids[7]) && !isNone(kids[7])))
return null;
MethodDeclaration x = ast.newMethodDeclaration();
if (isNone(kids[0]))
x.setJavadoc(null);
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asExtendedModifierList(kids[1]));
if (isNone(kids[2])) {
x.setReturnType2(null);
x.setConstructor(true);
} else
x.setReturnType2(asType(kids[2]));
x.typeParameters().addAll(asTypeParameterList(kids[3]));
x.setName(asSimpleName(kids[4]));
x.parameters().addAll(asSingleVariableDeclarationList(kids[5]));
x.thrownExceptions().addAll(asNameList(kids[6]));
if (isNone(kids[7]))
x.setBody(null);
else
x.setBody(asBlock(kids[7]));
return wrap(x);
}
case METHOD_INVOCATION: {
if ((!isExpression(kids[0]) && !isNone(kids[0])) || !isSimpleName(kids[1]) || !isTypeList(kids[2])
|| !isExpressionList(kids[3]))
return null;
MethodInvocation x = ast.newMethodInvocation();
if (isNone(kids[0]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[0]));
x.setName(asSimpleName(kids[1]));
x.typeArguments().addAll(asTypeList(kids[2]));
x.arguments().addAll(asExpressionList(kids[3]));
return wrap(x);
}
case METHOD_REF: {
if (!isSimpleName(kids[0]) || !isName(kids[1]) || !isMethodRefParameterList(kids[2]))
return null;
MethodRef x = ast.newMethodRef();
x.setName(asSimpleName(kids[0]));
x.setQualifier(asName(kids[1]));
x.parameters().addAll(asMethodRefParameterList(kids[2]));
return wrap(x);
}
case METHOD_REF_PARAMETER: {
if (!isType(kids[0]) || !(isSimpleName(kids[1]) || isNone(kids[1])))
return null;
MethodRefParameter x = ast.newMethodRefParameter();
x.setType(asType(kids[0]));
if (isNone(kids[1]))
x.setName(null);
else
x.setName(asSimpleName(kids[1]));
return wrap(x);
}
case MODIFIER: {
if (!isModifierKeyword(kids[0]))
return null;
return wrap(ast.newModifier(asModifierKeyword(kids[0])));
}
case MODIFIER_KEYWORD: {
if (!isInt(kids[0]))
return null;
return wrap(Modifier.ModifierKeyword.fromFlagValue(asInt(kids[0])));
}
case NONE:
return None.INSTANCE;
case NORMAL_ANNOTATION: {
if (!isName(kids[0]) || !isMemberValuePairList(kids[1]))
return null;
NormalAnnotation x = ast.newNormalAnnotation();
x.setTypeName(asName(kids[0]));
x.values().addAll(asMemberValuePairList(kids[1]));
return wrap(x);
}
case NULL_LITERAL: {
return wrap(ast.newNullLiteral());
}
case NUMBER_LITERAL: {
if (!isString(kids[0]))
return null;
return wrap(ast.newNumberLiteral(asString(kids[0])));
}
case PACKAGE_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isAnnotations(kids[1]) || !isName(kids[2]))
return null;
PackageDeclaration pd = ast.newPackageDeclaration();
if (isNone(kids[0]))
pd.setJavadoc(null);
else
pd.setJavadoc(getJavadoc(kids[0]));
pd.annotations().addAll(getAnnotations(kids[1]));
pd.setName(asName(kids[2]));
return wrap(pd);
}
case PARAMETERIZED_TYPE: {
if (!isType(kids[0]) || !isTypeList(kids[1]))
return null;
ParameterizedType x = ast.newParameterizedType(asType(kids[0]));
x.typeArguments().addAll(asTypeList(kids[1]));
return wrap(x);
}
case PARENTHESIZED_EXPRESSION: {
if (!isExpression(kids[0]))
return null;
ParenthesizedExpression x = ast.newParenthesizedExpression();
x.setExpression(asExpression(kids[0]));
return wrap(x);
}
case POSTFIX_EXPRESSION: {
if (!isPostfixOperator(kids[0]) || !isExpression(kids[1]))
return null;
PostfixExpression x = ast.newPostfixExpression();
x.setOperator(asPostfixOperator(kids[0]));
x.setOperand(asExpression(kids[1]));
return wrap(x);
}
case POSTFIX_EXPRESSION_OPERATOR: {
if (!isString(kids[0]))
return null;
return wrap(PostfixExpression.Operator.toOperator(asString(kids[0])));
}
case PREFIX_EXPRESSION: {
if (!isPrefixOperator(kids[0]) || !isExpression(kids[1]))
return null;
PrefixExpression x = ast.newPrefixExpression();
x.setOperator(asPrefixOperator(kids[0]));
x.setOperand(asExpression(kids[1]));
return wrap(x);
}
case PREFIX_EXPRESSION_OPERATOR: {
if (!isString(kids[0]))
return null;
return wrap(PrefixExpression.Operator.toOperator(asString(kids[0])));
}
case PRIMITIVE_TYPE: {
if (!isString(kids[0]))
return null;
return wrap(ast.newPrimitiveType(asTypeCode(kids[0])));
}
case QUALIFIED_NAME: {
if (!isName(kids[0]) || !isSimpleName(kids[1]))
return null;
return wrap(ast.newQualifiedName(asName(kids[0]), asSimpleName(kids[1])));
}
case QUALIFIED_TYPE: {
if (!isType(kids[0]) || !isSimpleName(kids[1]))
return null;
return wrap(ast.newQualifiedType(asType(kids[0]), asSimpleName(kids[1])));
}
case RETURN_STATEMENT: {
if (!(isExpression(kids[0]) || isNone(kids[0])))
return null;
ReturnStatement x = ast.newReturnStatement();
if (isNone(kids[0]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[0]));
return wrap(x);
}
case SIMPLE_NAME: {
if (!isString(kids[0]))
return null;
return wrap(ast.newSimpleName(asString(kids[0])));
}
case SIMPLE_TYPE: {
if (!isName(kids[0]))
return null;
return wrap(ast.newSimpleType(asName(kids[0])));
}
case SINGLE_MEMBER_ANNOTATION: {
if (!isName(kids[0]) || !isExpression(kids[1]))
return null;
SingleMemberAnnotation x = ast.newSingleMemberAnnotation();
x.setTypeName(asName(kids[0]));
x.setValue(asExpression(kids[1]));
return wrap(x);
}
case SINGLE_VARIABLE_DECLARATION: {
if (!isModifierList(kids[0]) || !isType(kids[1]) || !isName(kids[2]) || !isInt(kids[3])
|| (!isExpression(kids[4]) && !isNone(kids[4])))
return null;
SingleVariableDeclaration x = ast.newSingleVariableDeclaration();
x.modifiers().addAll(asModifierList(kids[0]));
x.setType(asType(kids[1]));
x.setName(asSimpleName(kids[2]));
x.setExtraDimensions(asInt(kids[3]));
if (isNone(kids[4]))
x.setInitializer(null);
else
x.setInitializer(asExpression(kids[4]));
return wrap(x);
}
case STRING_LITERAL: {
if (!isString(kids[0]))
return null;
StringLiteral x = ast.newStringLiteral();
x.setLiteralValue(asString(kids[0]));
return wrap(x);
}
case SUPER_CONSTRUCTOR_INVOCATION: {
if ((!isExpression(kids[0]) && !isNone(kids[0])) || !isTypeList(kids[1]) || !isExpressionList(kids[2]))
return null;
SuperConstructorInvocation x = ast.newSuperConstructorInvocation();
if (isNone(kids[0]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[0]));
x.typeArguments().addAll(asTypeList(kids[1]));
x.arguments().addAll(asExpressionList(kids[2]));
return wrap(x);
}
case SUPER_FIELD_ACCESS: {
if ((!isName(kids[0]) && !isNone(kids[0])) || !isSimpleName(kids[1]))
return null;
SuperFieldAccess x = ast.newSuperFieldAccess();
if (isNone(kids[0]))
x.setQualifier(null);
else
x.setQualifier(asName(kids[0]));
x.setName(asSimpleName(kids[1]));
return wrap(x);
}
case SUPER_METHOD_INVOCATION: {
if ((!isName(kids[0]) && !isNone(kids[0])) || !isTypeList(kids[1]) || !isSimpleName(kids[2])
|| !isExpressionList(kids[3]))
return null;
SuperMethodInvocation x = ast.newSuperMethodInvocation();
if (isNone(kids[0]))
x.setQualifier(null);
else
x.setQualifier(asName(kids[0]));
x.typeArguments().addAll(asTypeList(kids[1]));
x.setName(asSimpleName(kids[2]));
x.arguments().addAll(asExpressionList(kids[3]));
return wrap(x);
}
case SWITCH_CASE: {
if (!isExpression(kids[0]) && !isNone(kids[0]))
return null;
SwitchCase x = ast.newSwitchCase();
if (isNone(kids[0]))
x.setExpression(null);
else
x.setExpression(asExpression(kids[0]));
return wrap(x);
}
case SWITCH_STATEMENT: {
if (!isExpression(kids[0]) || !isStatementList(kids[1]))
return null;
SwitchStatement x = ast.newSwitchStatement();
x.setExpression(asExpression(kids[0]));
x.statements().addAll(asStatementList(kids[1]));
return wrap(x);
}
case SYNCHRONIZED_STATEMENT: {
if (!isExpression(kids[0]) || !isBlock(kids[1]))
return null;
SynchronizedStatement x = ast.newSynchronizedStatement();
x.setExpression(asExpression(kids[0]));
x.setBody(asBlock(kids[1]));
return wrap(x);
}
case TAG_ELEMENT: {
if ((!isString(kids[0]) && !isNone(kids[0])) || !isASTNodeList(kids[1]))
return null;
TagElement x = ast.newTagElement();
if (isNone(kids[0]))
x.setTagName(null);
else
x.setTagName(asString(kids[0]));
x.fragments().addAll(asASTNodeList(kids[1]));
return wrap(x);
}
case TEXT_ELEMENT: {
if (!isString(kids[0]))
return null;
TextElement x = ast.newTextElement();
x.setText(asString(kids[0]));
return wrap(x);
}
case THIS_EXPRESSION: {
if (!isName(kids[0]) && !isNone(kids[0]))
return null;
ThisExpression x = ast.newThisExpression();
if (isNone(kids[0]))
x.setQualifier(null);
else
x.setQualifier(asName(kids[0]));
return wrap(x);
}
case THROW_STATEMENT: {
if (!isExpression(kids[0]))
return null;
ThrowStatement x = ast.newThrowStatement();
x.setExpression(asExpression(kids[0]));
return wrap(x);
}
case TRY_STATEMENT: {
if (!isBlock(kids[0]) || !isCatchClauseList(kids[1]) || (!isBlock(kids[2]) && !isNone(kids[2])))
return null;
TryStatement x = ast.newTryStatement();
x.setBody(asBlock(kids[0]));
x.catchClauses().addAll(asCatchClauseList(kids[1]));
if (isNone(kids[2]))
x.setFinally(null);
else
x.setFinally(asBlock(kids[2]));
return wrap(x);
}
case TYPE_DECLARATION: {
if ((!isJavadoc(kids[0]) && !isNone(kids[0])) || !isModifierList(kids[1]) || !isSimpleName(kids[2])
|| !isTypeParameterList(kids[3]) || (!isType(kids[4]) && !isNone(kids[4]))
|| !isTypeList(kids[5]) || !isBodyDeclarationList(kids[6]) || !isInt(kids[7]))
return null;
TypeDeclaration x = ast.newTypeDeclaration();
if (isNone(kids[0]))
x.setJavadoc(null);
else
x.setJavadoc(asJavadoc(kids[0]));
x.modifiers().addAll(asModifierList(kids[1]));
x.setName(asSimpleName(kids[2]));
x.typeParameters().addAll(asTypeParameterList(kids[3]));
if (isNone(kids[4]))
x.setSuperclassType(null);
else
x.setSuperclassType(asType(kids[4]));
x.superInterfaceTypes().addAll(asTypeList(kids[5]));
x.bodyDeclarations().addAll(asBodyDeclarationList(kids[6]));
x.setInterface(asInt(kids[7]) == 1);
return wrap(x);
}
case TYPE_DECLARATION_STATEMENT: {
if (!isTypeDecl(kids[0]))
return null;
return wrap(ast.newTypeDeclarationStatement(asTypeDecl(kids[0])));
}
case TYPE_LITERAL: {
if (!isType(kids[0]))
return null;
TypeLiteral x = ast.newTypeLiteral();
x.setType(asType(kids[0]));
return wrap(x);
}
case TYPE_PARAMETER: {
if (!isSimpleName(kids[0]) || !isTypeList(kids[1]))
return null;
TypeParameter x = ast.newTypeParameter();
x.setName(asSimpleName(kids[0]));
x.typeBounds().addAll(asTypeList(kids[1]));
return wrap(x);
}
case VARIABLE_DECLARATION_EXPRESSION: {
if (!isModifierList(kids[0]) || !isType(kids[1]) || !isNonEmptyVariableDeclarationFragmentList(kids[2]))
return null;
List y = asFragmentList(kids[2]);
VariableDeclarationExpression x = ast
.newVariableDeclarationExpression((VariableDeclarationFragment) y.remove(0));
x.modifiers().addAll(asModifierList(kids[0]));
x.setType(asType(kids[1]));
x.fragments().addAll(y);
return wrap(x);
}
case VARIABLE_DECLARATION_FRAGMENT: {
if (!isSimpleName(kids[0]) || !isInt(kids[1]) || (!isExpression(kids[2]) && !isNone(kids[2])))
return null;
VariableDeclarationFragment x = ast.newVariableDeclarationFragment();
x.setName(asSimpleName(kids[0]));
x.setExtraDimensions(asInt(kids[1]));
if (isNone(kids[2]))
x.setInitializer(null);
else
x.setInitializer(asExpression(kids[2]));
return wrap(x);
}
case VARIABLE_DECLARATION_STATEMENT: {
if (!isModifierList(kids[0]) || !isType(kids[1]) || !isNonEmptyVariableDeclarationFragmentList(kids[2]))
return null;
List y = asFragmentList(kids[2]);
VariableDeclarationStatement x = ast
.newVariableDeclarationStatement((VariableDeclarationFragment) y.remove(0));
x.modifiers().addAll(asModifierList(kids[0]));
x.setType(asType(kids[1]));
x.fragments().addAll(y);
return wrap(x);
}
case WHILE_STATEMENT: {
if (!isExpression(kids[0]) || !isStatement(kids[1]))
return null;
WhileStatement x = ast.newWhileStatement();
x.setExpression(asExpression(kids[0]));
x.setBody(asStatement(kids[1]));
return wrap(x);
}
case WILDCARD_TYPE: {
if (!isType(kids[0]) && !isNone(kids[0]))
return null;
WildcardType x = ast.newWildcardType();
if (isNone(kids[0]))
x.setBound(null);
else
x.setBound(asType(kids[0]));
return wrap(x);
}
default:
return null;
}
}
From source file:org.whole.lang.java.util.JDTTransformerVisitor.java
License:Open Source License
public boolean visit(PackageDeclaration node) { org.whole.lang.java.model.PackageDeclaration packageDeclaration = lf.createPackageDeclaration(); acceptChild(node.getName());/*from ww w . j a v a2s . com*/ packageDeclaration.setName(name); if (acceptChild(commentsMapper.getPackageJavadoc())) packageDeclaration.setJavadoc(javadoc); cu.setPackage(packageDeclaration); return false; }