本文整理汇总了Java中com.intellij.codeInsight.ExternalAnnotationsManager类的典型用法代码示例。如果您正苦于以下问题:Java ExternalAnnotationsManager类的具体用法?Java ExternalAnnotationsManager怎么用?Java ExternalAnnotationsManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExternalAnnotationsManager类属于com.intellij.codeInsight包,在下文中一共展示了ExternalAnnotationsManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateAnnotations
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private static void generateAnnotations(@NonNls @NotNull StringBuilder buffer,
@NotNull PsiModifierListOwner owner,
boolean generateLink,
boolean splitAnnotations,
boolean useShortNames) {
final PsiModifierList ownerModifierList = owner.getModifierList();
if (ownerModifierList == null) return;
generateAnnotations(buffer, owner, ownerModifierList.getAnnotations(), false, generateLink, splitAnnotations, useShortNames);
PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotations(owner);
if (externalAnnotations == null) {
externalAnnotations = new PsiAnnotation[]{};
}
PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(owner.getProject()).findInferredAnnotations(owner);
externalAnnotations = ArrayUtil.mergeArrays(externalAnnotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY);
generateAnnotations(buffer, owner, externalAnnotations, true, generateLink, splitAnnotations, useShortNames);
}
示例2: isAvailable
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
myAnnotationName = null;
PsiModifierListOwner listOwner = getContainer(editor, file);
if (listOwner != null) {
final ExternalAnnotationsManager externalAnnotationsManager = ExternalAnnotationsManager.getInstance(project);
final PsiAnnotation[] annotations = externalAnnotationsManager.findExternalAnnotations(listOwner);
if (annotations != null && annotations.length > 0) {
if (annotations.length == 1) {
myAnnotationName = annotations[0].getQualifiedName();
}
final List<PsiFile> files = externalAnnotationsManager.findExternalAnnotationsFiles(listOwner);
if (files == null || files.isEmpty()) return false;
final VirtualFile virtualFile = files.get(0).getVirtualFile();
return virtualFile != null && (virtualFile.isWritable() || virtualFile.isInLocalFileSystem());
}
}
return false;
}
示例3: deannotate
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private void deannotate(final PsiAnnotation annotation,
final Project project,
final PsiFile file,
final ExternalAnnotationsManager annotationsManager,
final PsiModifierListOwner listOwner) {
new WriteCommandAction(project, getText()) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
final VirtualFile virtualFile = file.getVirtualFile();
String qualifiedName = annotation.getQualifiedName();
LOG.assertTrue(qualifiedName != null);
if (annotationsManager.deannotate(listOwner, qualifiedName) && virtualFile != null && virtualFile.isInLocalFileSystem()) {
UndoUtil.markPsiFileForUndo(file);
}
}
}.execute();
}
示例4: isAvailable
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
PsiModifierListOwner listOwner = getContainer(editor, file);
if (listOwner != null) {
final ExternalAnnotationsManager externalAnnotationsManager = ExternalAnnotationsManager.getInstance(project);
final PsiAnnotation[] annotations = externalAnnotationsManager.findExternalAnnotations(listOwner);
if (annotations != null && annotations.length > 0) {
if (annotations.length == 1) {
myAnnotationName = annotations[0].getQualifiedName();
}
final List<PsiFile> files = externalAnnotationsManager.findExternalAnnotationsFiles(listOwner);
if (files == null || files.isEmpty()) return false;
final VirtualFile virtualFile = files.get(0).getVirtualFile();
return virtualFile != null && (virtualFile.isWritable() || virtualFile.isInLocalFileSystem());
}
}
return false;
}
示例5: deannotate
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private void deannotate(final PsiAnnotation annotation,
final Project project,
final PsiFile file,
final ExternalAnnotationsManager annotationsManager,
final PsiModifierListOwner listOwner) {
new WriteCommandAction(project, getText()) {
@Override
protected void run(final Result result) throws Throwable {
final VirtualFile virtualFile = file.getVirtualFile();
String qualifiedName = annotation.getQualifiedName();
LOG.assertTrue(qualifiedName != null);
if (annotationsManager.deannotate(listOwner, qualifiedName) && virtualFile != null && virtualFile.isInLocalFileSystem()) {
UndoUtil.markPsiFileForUndo(file);
}
}
}.execute();
}
示例6: 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();
}
示例7: generateAnnotations
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private static void generateAnnotations(@NotNull StringBuilder buffer, @NotNull PsiModifierListOwner owner, boolean generateLink, boolean splitAnnotations, boolean useShortNames)
{
final PsiModifierList ownerModifierList = owner.getModifierList();
if(ownerModifierList == null)
{
return;
}
generateAnnotations(buffer, owner, ownerModifierList.getAnnotations(), false, generateLink, splitAnnotations, useShortNames);
PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotations(owner);
if(externalAnnotations == null)
{
externalAnnotations = PsiAnnotation.EMPTY_ARRAY;
}
PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(owner.getProject()).findInferredAnnotations(owner);
externalAnnotations = ArrayUtil.mergeArrays(externalAnnotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY);
generateAnnotations(buffer, owner, externalAnnotations, true, generateLink, splitAnnotations, useShortNames);
}
示例8: applyFix
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
if (myAnnotation.isPhysical()) {
try {
if (!FileModificationService.getInstance().preparePsiElementForWrite(myAnnotation)) return;
myAnnotation.delete();
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
} else if (myListOwner != null) {
ExternalAnnotationsManager.getInstance(project).deannotate(myListOwner, myAnnotation.getQualifiedName());
}
}
示例9: 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);
}
}
}
示例10: invoke
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiModifierListOwner listOwner = getContainer(editor, file);
LOG.assertTrue(listOwner != null);
final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
final PsiAnnotation[] externalAnnotations = annotationsManager.findExternalAnnotations(listOwner);
LOG.assertTrue(externalAnnotations != null && externalAnnotations.length > 0);
if (externalAnnotations.length == 1) {
deannotate(externalAnnotations[0], project, file, annotationsManager, listOwner);
return;
}
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PsiAnnotation>(CodeInsightBundle.message("deannotate.intention.chooser.title"), externalAnnotations) {
@Override
public PopupStep onChosen(final PsiAnnotation selectedValue, final boolean finalChoice) {
deannotate(selectedValue, project, file, annotationsManager, listOwner);
return PopupStep.FINAL_CHOICE;
}
@Override
@NotNull
public String getTextFor(final PsiAnnotation value) {
final String qualifiedName = value.getQualifiedName();
LOG.assertTrue(qualifiedName != null);
return qualifiedName;
}
}).showInBestPositionFor(editor);
}
示例11: applyFix
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
if (myAnnotation.isPhysical()) {
try {
if (!FileModificationService.getInstance().preparePsiElementForWrite(myAnnotation)) return;
myAnnotation.delete();
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
} else {
ExternalAnnotationsManager.getInstance(project).deannotate(myListOwner, myAnnotation.getQualifiedName());
}
}
示例12: exportMethodAnnotations
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private void exportMethodAnnotations(PsiMethod method) {
// @Contract
PsiAnnotation inferredContractAnnotation = findInferredAnnotation(method, ORG_JETBRAINS_ANNOTATIONS_CONTRACT);
if (inferredContractAnnotation != null) {
PsiNameValuePair[] attributes = inferredContractAnnotation.getParameterList().getAttributes();
ExternalAnnotationsManager.getInstance(myModule.getProject()).annotateExternally(method, ORG_JETBRAINS_ANNOTATIONS_CONTRACT, method.getContainingFile(), attributes);
}
{
// @NotNull method
PsiAnnotation inferredNotNullMethodAnnotation = findInferredAnnotation(method, AnnotationUtil.NOT_NULL);
if (inferredNotNullMethodAnnotation != null) {
ExternalAnnotationsManager.getInstance(myModule.getProject()).annotateExternally(method, AnnotationUtil.NOT_NULL, method.getContainingFile(), null);
}
}
{
// @Nullable method
PsiAnnotation inferredNullableMethodAnnotation = findInferredAnnotation(method, AnnotationUtil.NULLABLE);
if (inferredNullableMethodAnnotation != null) {
ExternalAnnotationsManager.getInstance(myModule.getProject()).annotateExternally(method, AnnotationUtil.NULLABLE, method.getContainingFile(), null);
}
}
for (PsiParameter parameter : method.getParameterList().getParameters()) {
{
// @NotNull parameter
PsiAnnotation inferredNotNull = findInferredAnnotation(parameter, AnnotationUtil.NOT_NULL);
if (inferredNotNull != null) {
ExternalAnnotationsManager.getInstance(myModule.getProject()).annotateExternally(parameter, AnnotationUtil.NOT_NULL, method.getContainingFile(), null);
}
}
{
// @Nullable parameter
PsiAnnotation inferredNullable = findInferredAnnotation(parameter, AnnotationUtil.NULLABLE);
if (inferredNullable != null) {
ExternalAnnotationsManager.getInstance(myModule.getProject()).annotateExternally(parameter, AnnotationUtil.NULLABLE, method.getContainingFile(), null);
}
}
}
}
示例13: findExternalAnnotation
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Nullable
private PsiAnnotation findExternalAnnotation(PsiModifierListOwner owner, String fqn) {
return ExternalAnnotationsManager.getInstance(myModule.getProject()).findExternalAnnotation(owner, fqn);
}
示例14: isFileAccepted
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
@Override
protected boolean isFileAccepted(VirtualFile virtualFile) {
return super.isFileAccepted(virtualFile) && virtualFile.getName().equals(ExternalAnnotationsManager.ANNOTATIONS_XML);
}
示例15: generateAnnotations
import com.intellij.codeInsight.ExternalAnnotationsManager; //导入依赖的package包/类
private static void generateAnnotations(@NonNls StringBuilder buffer, PsiModifierListOwner owner) {
final PsiModifierList ownerModifierList = owner.getModifierList();
if (ownerModifierList == null) return;
PsiAnnotation[] annotations = ownerModifierList.getAnnotations();
final PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotations(owner);
if (externalAnnotations != null) {
annotations = ArrayUtil.mergeArrays(annotations, externalAnnotations, PsiAnnotation.ARRAY_FACTORY);
}
PsiManager manager = owner.getManager();
for (PsiAnnotation annotation : annotations) {
final PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
if (nameReferenceElement == null) continue;
final PsiElement resolved = nameReferenceElement.resolve();
if (resolved instanceof PsiClass) {
final PsiClass annotationType = (PsiClass)resolved;
if (AnnotationUtil.isAnnotated(annotationType, "java.lang.annotation.Documented", false)) {
final PsiClassType type = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(annotationType, PsiSubstitutor.EMPTY);
buffer.append("@");
generateType(buffer, type, owner);
final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
if (attributes.length > 0) {
boolean first = true;
buffer.append("(");
for (PsiNameValuePair pair : attributes) {
if (!first) buffer.append(" ");
first = false;
final String name = pair.getName();
if (name != null) {
buffer.append(name);
buffer.append(" = ");
}
final PsiAnnotationMemberValue value = pair.getValue();
if (value != null) {
buffer.append(value.getText());
}
}
buffer.append(")");
}
buffer.append(" ");
}
} else {
buffer.append("<font color=red>");
buffer.append(annotation.getText());
buffer.append("</font>");
buffer.append(" ");
}
}
}