本文整理了Java中org.eclipse.jdt.core.dom.Annotation.setTypeName()
方法的一些代码示例,展示了Annotation.setTypeName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.setTypeName()
方法的具体详情如下:
包路径:org.eclipse.jdt.core.dom.Annotation
类名称:Annotation
方法名:setTypeName
[英]Sets the annotation type name of this annotation.
[中]设置此批注的批注类型名称。
代码示例来源:origin: forge/roaster
@Override
public AnnotationSource<O> setName(final String className)
{
annotation.setTypeName(ast.newName(className));
return this;
}
代码示例来源:origin: org.jboss.forge/roaster-jdt
@Override
public AnnotationSource<O> setName(final String className)
{
annotation.setTypeName(ast.newName(className));
return this;
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
protected void setTypeNameForAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation compilerAnnotation, Annotation annotation) {
TypeReference typeReference = compilerAnnotation.type;
if (typeReference instanceof QualifiedTypeReference) {
QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) typeReference;
char[][] tokens = qualifiedTypeReference.tokens;
long[] positions = qualifiedTypeReference.sourcePositions;
// QualifiedName
annotation.setTypeName(setQualifiedNameNameAndSourceRanges(tokens, positions, typeReference));
} else {
SingleTypeReference singleTypeReference = (SingleTypeReference) typeReference;
final SimpleName name = new SimpleName(this.ast);
name.internalSetIdentifier(new String(singleTypeReference.token));
int start = singleTypeReference.sourceStart;
int end = singleTypeReference.sourceEnd;
name.setSourceRange(start, end - start + 1);
name.index = 1;
annotation.setTypeName(name);
if (this.resolveBindings) {
recordNodes(name, typeReference);
}
}
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
protected void setTypeNameForAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation compilerAnnotation, Annotation annotation) {
TypeReference typeReference = compilerAnnotation.type;
if (typeReference instanceof QualifiedTypeReference) {
QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) typeReference;
char[][] tokens = qualifiedTypeReference.tokens;
long[] positions = qualifiedTypeReference.sourcePositions;
// QualifiedName
annotation.setTypeName(setQualifiedNameNameAndSourceRanges(tokens, positions, typeReference));
} else {
SingleTypeReference singleTypeReference = (SingleTypeReference) typeReference;
final SimpleName name = new SimpleName(this.ast);
name.internalSetIdentifier(new String(singleTypeReference.token));
int start = singleTypeReference.sourceStart;
int end = singleTypeReference.sourceEnd;
name.setSourceRange(start, end - start + 1);
name.index = 1;
annotation.setTypeName(name);
if (this.resolveBindings) {
recordNodes(name, typeReference);
}
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
private void addNullAnnotation(ASTNode varDecl, ChildListPropertyDescriptor modifiers2Property, ASTRewrite rewrite, String nonNullType, AST ast) {
ListRewrite listRewrite= rewrite.getListRewrite(varDecl, modifiers2Property);
Annotation newAnnotation= ast.newMarkerAnnotation();
newAnnotation.setTypeName(ast.newName(nonNullType));
listRewrite.insertLast(newAnnotation, null); // null annotation is last modifier, directly preceding the type
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
private void addNullAnnotation(ASTNode varDecl, ChildListPropertyDescriptor modifiers2Property, ASTRewrite rewrite, String nonNullType, AST ast) {
ListRewrite listRewrite= rewrite.getListRewrite(varDecl, modifiers2Property);
Annotation newAnnotation= ast.newMarkerAnnotation();
newAnnotation.setTypeName(ast.newName(nonNullType));
listRewrite.insertLast(newAnnotation, null); // null annotation is last modifier, directly preceding the type
}
}
代码示例来源:origin: cbeust/testng-eclipse
/**
* @return a NormalAnnotation if the annotation to create has attributes or a
* MarkerAnnotation otherwise.
*/
private Annotation createAnnotation(AST ast, String name, Map<String, Boolean> attributes) {
Annotation result = null;
NormalAnnotation normalAnnotation = null;
if (attributes != null && attributes.size() > 0) {
normalAnnotation = ast.newNormalAnnotation();
result = normalAnnotation;
} else {
result = ast.newMarkerAnnotation();
}
result.setTypeName(ast.newName(name));
if (attributes != null) {
for (Entry<String, Boolean> a : attributes.entrySet()) {
MemberValuePair mvp = ast.newMemberValuePair();
mvp.setName(ast.newSimpleName(a.getKey()));
mvp.setValue(ast.newBooleanLiteral(a.getValue()));
normalAnnotation.values().add(mvp);
}
}
return result;
}
代码示例来源:origin: org.eclipse/org.eclipse.jpt.core
/**
* Add the appropriate import statement, then shorten the annotation's
* name before adding it to the declaration.
*/
protected void addAnnotationAndImport(ModifiedDeclaration declaration, Annotation annotation) {
declaration.addImport(this.annotationName);
annotation.setTypeName(declaration.getAST().newName(this.shortAnnotationName()));
this.addAnnotation(declaration, annotation);
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
public void rewriteAST(CompilationUnitRewrite cuRewrite, List textEditGroups) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
Annotation newAnnotation= ast.newMarkerAnnotation();
newAnnotation.setTypeName(ast.newSimpleName(fAnnotation));
TextEditGroup group= createTextEditGroup(Messages.format(FixMessages.Java50Fix_AddMissingAnnotation_description, fAnnotation));
textEditGroups.add(group);
listRewrite.insertFirst(newAnnotation, group);
}
}
代码示例来源:origin: ajermakovics/eclipse-jmockit
public static void addAnnotation(final String annotation,
final IJavaProject project, final ASTRewrite rewrite, final MethodDeclaration decl,
final IMethodBinding binding)
{
String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (!binding.getDeclaringClass().isInterface()
|| !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
{
final Annotation marker= rewrite.getAST().newMarkerAnnotation();
marker.setTypeName(rewrite.getAST().newSimpleName(annotation)); //$NON-NLS-1$
rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
Annotation newAnnotation= ast.newMarkerAnnotation();
newAnnotation.setTypeName(ast.newSimpleName(fAnnotation));
TextEditGroup group= createTextEditGroup(Messages.format(FixMessages.Java50Fix_AddMissingAnnotation_description, BasicElementLabels.getJavaElementName(fAnnotation)), cuRewrite);
listRewrite.insertFirst(newAnnotation, group);
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
Annotation newAnnotation= ast.newMarkerAnnotation();
newAnnotation.setTypeName(ast.newSimpleName(fAnnotation));
TextEditGroup group= createTextEditGroup(Messages.format(FixMessages.Java50Fix_AddMissingAnnotation_description, BasicElementLabels.getJavaElementName(fAnnotation)), cuRewrite);
listRewrite.insertFirst(newAnnotation, group);
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation
public static void createOverrideAnnotation(ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration decl, TextEditGroup group) {
if (findAnnotation("java.lang.Override", decl.modifiers()) != null) { //$NON-NLS-1$
return; // No need to add duplicate annotation
}
AST ast= rewrite.getAST();
ASTNode root= decl.getRoot();
ImportRewriteContext context= null;
if (root instanceof CompilationUnit) {
context= new ContextSensitiveImportRewriteContext((CompilationUnit) root, decl.getStartPosition(), imports);
}
Annotation marker= ast.newMarkerAnnotation();
marker.setTypeName(ast.newName(imports.addImport("java.lang.Override", context))); //$NON-NLS-1$
rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, group);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
public static void createOverrideAnnotation(ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration decl, TextEditGroup group) {
if (findAnnotation("java.lang.Override", decl.modifiers()) != null) { //$NON-NLS-1$
return; // No need to add duplicate annotation
}
AST ast= rewrite.getAST();
ASTNode root= decl.getRoot();
ImportRewriteContext context= null;
if (root instanceof CompilationUnit) {
context= new ContextSensitiveImportRewriteContext((CompilationUnit) root, decl.getStartPosition(), imports);
}
Annotation marker= ast.newMarkerAnnotation();
marker.setTypeName(ast.newName(imports.addImport("java.lang.Override", context))); //$NON-NLS-1$
rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, group);
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
public static void addOverrideAnnotation(ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
String version= binding.getJavaElement().getJavaProject().getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (!binding.getDeclaringClass().isInterface() || !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6)) {
final Annotation marker= rewrite.getAST().newMarkerAnnotation();
marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$
rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fArgument, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
if (!checkExisting(fArgument.modifiers(), listRewrite, group))
return;
Annotation newAnnotation= ast.newMarkerAnnotation();
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
String resolvableName= importRewrite.addImport(fAnnotationToAdd);
newAnnotation.setTypeName(ast.newName(resolvableName));
listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the type
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= getAnnotationListRewrite(fArgument.getType(), cuRewrite, fArgument, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
if (!checkExisting(listRewrite, group))
return;
if (!fRequireExplicitAnnotation) {
if (hasNonNullDefault(fArgument, fArgument.resolveBinding(), fParameterRank, DefaultLocation.PARAMETER))
return; // should be safe, as in this case checkExisting() should've already produced a change (remove existing annotation).
}
Annotation newAnnotation= ast.newMarkerAnnotation();
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
String resolvableName= importRewrite.addImport(fAnnotationToAdd);
newAnnotation.setTypeName(ast.newName(resolvableName));
listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the type
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= getAnnotationListRewrite(fBodyDeclaration.getReturnType2(), cuRewrite,
fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
if (!checkExisting(listRewrite, group))
return;
if (!fRequireExplicitAnnotation) {
if (hasNonNullDefault(fBodyDeclaration, fBodyDeclaration.resolveBinding(), /*parameterRank*/-1, DefaultLocation.RETURN_TYPE))
return; // should be safe, as in this case checkExisting() should've already produced a change (remove existing annotation).
}
Annotation newAnnotation= ast.newMarkerAnnotation();
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
String resolvableName= importRewrite.addImport(fAnnotationToAdd);
newAnnotation.setTypeName(ast.newName(resolvableName));
listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the return type
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty());
TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
if (!checkExisting(fBodyDeclaration.modifiers(), listRewrite, group))
return;
if (hasNonNullDefault(fBodyDeclaration.resolveBinding()))
return; // should be safe, as in this case checkExisting() should've already produced a change (remove existing annotation).
Annotation newAnnotation= ast.newMarkerAnnotation();
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
String resolvableName= importRewrite.addImport(fAnnotationToAdd);
newAnnotation.setTypeName(ast.newName(resolvableName));
listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the return type
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
if (fProblem.getProblemId() == IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
ASTNode selectedNode= fCompilationUnit.getPackage();
if (selectedNode instanceof PackageDeclaration) {
String nonNullByDefaultAnnotationname= NullAnnotationsFix.getNonNullByDefaultAnnotationName(fCompilationUnit.getJavaElement(), true);
String label= Messages.format(FixMessages.NullAnnotationsRewriteOperations_add_missing_default_nullness_annotation, new String[] { nonNullByDefaultAnnotationname });
TextEditGroup group= createTextEditGroup(label, cuRewrite);
ASTRewrite astRewrite= cuRewrite.getASTRewrite();
PackageDeclaration packageDeclaration= (PackageDeclaration) selectedNode;
AST ast= cuRewrite.getRoot().getAST();
ListRewrite listRewrite= astRewrite.getListRewrite(packageDeclaration, PackageDeclaration.ANNOTATIONS_PROPERTY);
Annotation newAnnotation= ast.newMarkerAnnotation();
// NOTE: to be consistent with completion proposals, don't use import in package-info.java
String annotationToAdd= NullAnnotationsFix.getNonNullByDefaultAnnotationName(fCompilationUnit.getJavaElement(), false);
newAnnotation.setTypeName(ast.newName(annotationToAdd));
listRewrite.insertLast(newAnnotation, group);
return;
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!