当前位置: 首页>>代码示例>>Java>>正文


Java Annotation.setTypeName方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.Annotation.setTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java Annotation.setTypeName方法的具体用法?Java Annotation.setTypeName怎么用?Java Annotation.setTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.Annotation的用法示例。


在下文中一共展示了Annotation.setTypeName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addOverrideAnnotation

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverrideAnnotation(
    IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
  if (binding.getDeclaringClass().isInterface()) {
    String version = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
      return; // not allowed in 1.5
    if (JavaCore.DISABLED.equals(
        project.getOption(
            JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION,
            true))) return; // user doesn't want to use 1.6 style
  }

  Annotation marker = rewrite.getAST().newMarkerAnnotation();
  marker.setTypeName(rewrite.getAST().newSimpleName("Override")); // $NON-NLS-1$
  rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:StubUtility2.java

示例2: rewriteAST

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
/** {@inheritDoc} */
@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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:Java50Fix.java

示例3: rewriteAST

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
@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
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:NullAnnotationsRewriteOperations.java

示例4: createMethodComments

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
/**
 * Creates the method annotations and comments of the extracted methods in
 * the source type.
 *
 * @param sourceRewrite
 *            the source compilation unit rewrite
 * @param replacements
 *            the set of variable binding keys of formal parameters which
 *            must be replaced
 * @throws CoreException
 *             if an error occurs
 */
protected final void createMethodComments(final CompilationUnitRewrite sourceRewrite, final Set<String> replacements) throws CoreException {
	Assert.isNotNull(sourceRewrite);
	Assert.isNotNull(replacements);
	if (fMembers.length > 0 && (fAnnotations || fComments)) {
		IJavaProject project= fSubType.getJavaProject();
		boolean annotations= fAnnotations && !JavaModelUtil.isVersionLessThan(project.getOption(JavaCore.COMPILER_SOURCE, true), JavaCore.VERSION_1_6);
		boolean javadoc= project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true).equals(JavaCore.ENABLED);
		IMember member= null;
		for (int index= 0; index < fMembers.length; index++) {
			member= fMembers[index];
			if (member instanceof IMethod) {
				MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, sourceRewrite.getRoot());
				if (annotations) {
					ASTRewrite rewrite= sourceRewrite.getASTRewrite();
					AST ast= rewrite.getAST();
					Annotation marker= ast.newMarkerAnnotation();
					marker.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$
					rewrite.getListRewrite(declaration, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
				}
				if (fComments)
					createMethodComment(sourceRewrite, declaration, replacements, javadoc);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:38,代码来源:ExtractInterfaceProcessor.java

示例5: visitAnnotation

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
/**
 * Processes the annotation to replace its name by FQN
 * 
 * @param node
 * @return
 */
private boolean visitAnnotation(Annotation node) {
	if (node.getTypeName().isSimpleName()) {
		ITypeBinding resolvedBinding = node.resolveTypeBinding();
		if (resolvedBinding != null) {
			String qualifiedName = null;

			if (resolvedBinding.isParameterizedType()) {
				ITypeBinding erasure = resolvedBinding.getErasure();
				if (erasure != null && !erasure.isRecovered()) {
					qualifiedName = erasure.getQualifiedName();
				}
			} else if (!resolvedBinding.isRecovered()) {
				qualifiedName = resolvedBinding.getQualifiedName();
			}
			if (qualifiedName != null) {
				node.setTypeName(node.getAST().newName(qualifiedName));
				this.modified = true;
			}
		}
	}
	return true;
}
 
开发者ID:awltech,项目名称:eclipse-optimus,代码行数:29,代码来源:ImportsRemovalVisitor.java

示例6: createOverrideAnnotation

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:15,代码来源:StubUtility2.java

示例7: addOverridingDeprecatedMethodProposal

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverridingDeprecatedMethodProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

  ICompilationUnit cu = context.getCompilationUnit();

  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof MethodDeclaration)) {
    return;
  }
  boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());
  MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
  AST ast = methodDecl.getAST();
  ASTRewrite rewrite = ASTRewrite.create(ast);
  if (is50OrHigher) {
    Annotation annot = ast.newMarkerAnnotation();
    annot.setTypeName(ast.newName("Deprecated")); // $NON-NLS-1$
    rewrite
        .getListRewrite(methodDecl, methodDecl.getModifiersProperty())
        .insertFirst(annot, null);
  }
  Javadoc javadoc = methodDecl.getJavadoc();
  if (javadoc != null || !is50OrHigher) {
    if (!is50OrHigher) {
      javadoc = ast.newJavadoc();
      rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
    }
    TagElement newTag = ast.newTagElement();
    newTag.setTagName(TagElement.TAG_DEPRECATED);
    JavadocTagsSubProcessor.insertTag(
        rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
  }

  String label =
      CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
  Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
  ASTRewriteCorrectionProposal proposal =
      new ASTRewriteCorrectionProposal(
          label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image);
  proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:che,代码行数:41,代码来源:ModifierCorrectionSubProcessor.java

示例8: addOverrideAnnotation

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
	if (binding.getDeclaringClass().isInterface()) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
			return; // not allowed in 1.5
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
			return; // user doesn't want to use 1.6 style
	}
	
	Annotation marker= rewrite.getAST().newMarkerAnnotation();
	marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$
	rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:StubUtility2.java

示例9: rewriteAST

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:Java50Fix.java

示例10: rewriteAST

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
@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
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:NullAnnotationsRewriteOperations.java

示例11: addOverridingDeprecatedMethodProposal

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

		ICompilationUnit cu= context.getCompilationUnit();

		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
		if (!(selectedNode instanceof MethodDeclaration)) {
			return;
		}
		boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());
		MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
		AST ast= methodDecl.getAST();
		ASTRewrite rewrite= ASTRewrite.create(ast);
		if (is50OrHigher) {
			Annotation annot= ast.newMarkerAnnotation();
			annot.setTypeName(ast.newName("Deprecated")); //$NON-NLS-1$
			rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null);
		}
		Javadoc javadoc= methodDecl.getJavadoc();
		if (javadoc != null || !is50OrHigher) {
			if (!is50OrHigher) {
				javadoc= ast.newJavadoc();
				rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
			}
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_DEPRECATED);
			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
		}

		String label= CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image);
		proposals.add(proposal);
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:ModifierCorrectionSubProcessor.java

示例12: addOverrideAnnotation

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, 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("Override")); //$NON-NLS-1$
		rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:9,代码来源:StubUtility2.java

示例13: addOverridingDeprecatedMethodProposal

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

		ICompilationUnit cu= context.getCompilationUnit();

		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
		if (!(selectedNode instanceof MethodDeclaration)) {
			return;
		}
		boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());
		MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
		AST ast= methodDecl.getAST();
		ASTRewrite rewrite= ASTRewrite.create(ast);
		if (is50OrHigher) {
			Annotation annot= ast.newMarkerAnnotation();
			annot.setTypeName(ast.newName("Deprecated")); //$NON-NLS-1$
			rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null);
		}
		Javadoc javadoc= methodDecl.getJavadoc();
		if (javadoc != null || !is50OrHigher) {
			if (!is50OrHigher) {
				javadoc= ast.newJavadoc();
				rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
			}
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_DEPRECATED);
			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
		}

		String label= CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 15, image);
		proposals.add(proposal);
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:34,代码来源:ModifierCorrectionSubProcessor.java

示例14: rewriteAST

import org.eclipse.jdt.core.dom.Annotation; //导入方法依赖的package包/类
@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;
	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
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:14,代码来源:NullRewriteOperations.java


注:本文中的org.eclipse.jdt.core.dom.Annotation.setTypeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。