本文整理汇总了Java中com.intellij.codeInsight.ExternalAnnotationsManager.AnnotationPlace方法的典型用法代码示例。如果您正苦于以下问题:Java ExternalAnnotationsManager.AnnotationPlace方法的具体用法?Java ExternalAnnotationsManager.AnnotationPlace怎么用?Java ExternalAnnotationsManager.AnnotationPlace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.ExternalAnnotationsManager
的用法示例。
在下文中一共展示了ExternalAnnotationsManager.AnnotationPlace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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);
}
}
}
示例3: 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);
}
}
}