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


Java ExternalAnnotationsManager.annotateExternally方法代码示例

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


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

示例1: updateContract

import com.intellij.codeInsight.ExternalAnnotationsManager; //导入方法依赖的package包/类
private static void updateContract(PsiMethod method, String contract, boolean pure)
{
	Project project = method.getProject();
	ExternalAnnotationsManager manager = ExternalAnnotationsManager.getInstance(project);
	manager.deannotate(method, ControlFlowAnalyzer.ORG_JETBRAINS_ANNOTATIONS_CONTRACT);
	PsiAnnotation mockAnno = InferredAnnotationsManagerImpl.createContractAnnotation(project, pure, contract);
	if(mockAnno != null)
	{
		try
		{
			manager.annotateExternally(method, ControlFlowAnalyzer.ORG_JETBRAINS_ANNOTATIONS_CONTRACT, method.getContainingFile(), mockAnno.getParameterList().getAttributes());
		}
		catch(ExternalAnnotationsManager.CanceledConfigurationException ignored)
		{
		}
	}
	DaemonCodeAnalyzer.getInstance(project).restart();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:EditContractIntention.java

示例2: invoke

import com.intellij.codeInsight.ExternalAnnotationsManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project,
                   @NotNull PsiFile file,
                   @NotNull PsiElement startElement,
                   @NotNull PsiElement endElement) {
  final PsiModifierListOwner myModifierListOwner = (PsiModifierListOwner)startElement;

  final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
  final PsiModifierList modifierList = myModifierListOwner.getModifierList();
  LOG.assertTrue(modifierList != null, myModifierListOwner + " ("+myModifierListOwner.getClass()+")");
  if (modifierList.findAnnotation(myAnnotation) != null) return;
  final ExternalAnnotationsManager.AnnotationPlace annotationAnnotationPlace = annotationsManager.chooseAnnotationsPlace(myModifierListOwner);
  if (annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.NOWHERE) return;
  if (annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.EXTERNAL) {
    for (String fqn : myAnnotationsToRemove) {
      annotationsManager.deannotate(myModifierListOwner, fqn);
    }
    annotationsManager.annotateExternally(myModifierListOwner, myAnnotation, file, myPairs);
  }
  else {
    final PsiFile containingFile = myModifierListOwner.getContainingFile();
    if (!FileModificationService.getInstance().preparePsiElementForWrite(containingFile)) return;
    removePhysicalAnnotations(myModifierListOwner, myAnnotationsToRemove);

    PsiAnnotation inserted = addPhysicalAnnotation(myAnnotation, myPairs, modifierList);
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted);
    if (containingFile != file) {
      UndoUtil.markPsiFileForUndo(file);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:AddAnnotationPsiFix.java

示例3: annotate

import com.intellij.codeInsight.ExternalAnnotationsManager; //导入方法依赖的package包/类
private static void annotate(PsiModifierListOwner modifierListOwner,
                             String annotationName,
                             PsiNameValuePair[] attributes,
                             PsiElement context) {
  final Project project = context.getProject();
  final ExternalAnnotationsManager annotationsManager =
    ExternalAnnotationsManager.getInstance(project);
  final PsiModifierList modifierList =
    modifierListOwner.getModifierList();
  if (modifierList == null) {
    return;
  }
  if (modifierList.findAnnotation(annotationName) != null) return;
  final ExternalAnnotationsManager.AnnotationPlace
    annotationAnnotationPlace =
    annotationsManager.chooseAnnotationsPlace(modifierListOwner);
  if (annotationAnnotationPlace ==
      ExternalAnnotationsManager.AnnotationPlace.NOWHERE) {
    return;
  }
  final PsiFile fromFile = context.getContainingFile();
  if (annotationAnnotationPlace ==
      ExternalAnnotationsManager.AnnotationPlace.EXTERNAL) {
    annotationsManager.annotateExternally(modifierListOwner,
                                          annotationName, fromFile, attributes);
  }
  else {
    final PsiFile containingFile =
      modifierListOwner.getContainingFile();
    if (!FileModificationService.getInstance().preparePsiElementForWrite(containingFile)) {
      return;
    }
    final PsiAnnotation inserted =
      modifierList.addAnnotation(annotationName);
    for (PsiNameValuePair pair : attributes) {
      inserted.setDeclaredAttributeValue(pair.getName(),
                                         pair.getValue());
    }
    final JavaCodeStyleManager codeStyleManager =
      JavaCodeStyleManager.getInstance(project);
    codeStyleManager.shortenClassReferences(inserted);
    if (containingFile != fromFile) {
      UndoUtil.markPsiFileForUndo(fromFile);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:47,代码来源:AnnotateOverriddenMethodsIntention.java

示例4: invoke

import com.intellij.codeInsight.ExternalAnnotationsManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement)
{
	final PsiModifierListOwner myModifierListOwner = (PsiModifierListOwner) startElement;

	final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
	final PsiModifierList modifierList = myModifierListOwner.getModifierList();
	if(modifierList == null || modifierList.findAnnotation(myAnnotation) != null)
	{
		return;
	}
	PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(myAnnotation, myModifierListOwner.getResolveScope());
	final ExternalAnnotationsManager.AnnotationPlace annotationAnnotationPlace;
	if(aClass != null && aClass.getManager().isInProject(aClass) && AnnotationsHighlightUtil.getRetentionPolicy(aClass) == RetentionPolicy.RUNTIME)
	{
		annotationAnnotationPlace = ExternalAnnotationsManager.AnnotationPlace.IN_CODE;
	}
	else
	{
		annotationAnnotationPlace = annotationsManager.chooseAnnotationsPlace(myModifierListOwner);
	}
	if(annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.NOWHERE)
	{
		return;
	}
	if(annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.EXTERNAL)
	{
		for(String fqn : myAnnotationsToRemove)
		{
			annotationsManager.deannotate(myModifierListOwner, fqn);
		}
		try
		{
			annotationsManager.annotateExternally(myModifierListOwner, myAnnotation, file, myPairs);
		}
		catch(ExternalAnnotationsManager.CanceledConfigurationException ignored)
		{
		}
	}
	else
	{
		final PsiFile containingFile = myModifierListOwner.getContainingFile();
		WriteCommandAction.runWriteCommandAction(project, null, null, () ->
		{
			removePhysicalAnnotations(myModifierListOwner, myAnnotationsToRemove);

			PsiAnnotation inserted = addPhysicalAnnotation(myAnnotation, myPairs, modifierList);
			JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted);
		}, containingFile);

		if(containingFile != file)
		{
			UndoUtil.markPsiFileForUndo(file);
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:57,代码来源:AddAnnotationPsiFix.java


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