本文整理汇总了Java中com.intellij.psi.PsiAnnotation类的典型用法代码示例。如果您正苦于以下问题:Java PsiAnnotation类的具体用法?Java PsiAnnotation怎么用?Java PsiAnnotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiAnnotation类属于com.intellij.psi包,在下文中一共展示了PsiAnnotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPsiElement
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@Override
public PsiAnnotation getPsiElement() {
PsiAnnotation annotation = SoftReference.dereference(myParsedFromRepository);
if (annotation != null) {
return annotation;
}
final String text = getText();
try {
PsiJavaParserFacade facade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
annotation = facade.createAnnotationFromText(text, getPsi());
myParsedFromRepository = new SoftReference<PsiAnnotation>(annotation);
return annotation;
}
catch (IncorrectOperationException e) {
LOG.error("Bad annotation in repository!", e);
return null;
}
}
示例2: getResolutionFrom
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@Nullable
Resolution getResolutionFrom(PsiField field) {
PsiAnnotation annotation = scenarioStateProvider.getJGivenAnnotationOn(field);
if (annotation == null) {
return null;
}
PsiExpression annotationValue = annotationValueProvider.getAnnotationValue(annotation, FIELD_RESOLUTION);
return Optional.ofNullable(annotationValue)
.map(PsiElement::getText)
.map(t -> {
for (Resolution resolution : Resolution.values()) {
if (resolution != Resolution.AUTO && t.contains(resolution.name())) {
return resolution;
}
}
return getResolutionForFieldType(field);
}).orElse(getResolutionForFieldType(field));
}
示例3: addAnnotationToPackageInfo
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
private void addAnnotationToPackageInfo(Project project, PsiJavaFile packageInfoFile) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(packageInfoFile)) {
return;
}
PsiPackageStatement packageStatement = packageInfoFile.getPackageStatement();
if (packageStatement == null) {
return;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + annotationForTypeQualifierFqn,
packageInfoFile.getContext());
PsiElement addedAnnotation = packageInfoFile.addBefore(annotation, packageStatement);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedAnnotation);
removeRedundantAnnotationsInPackage(project, packageInfoFile.getContainingDirectory().getFiles(), annotation);
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例4: targetTypesForDefault
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@Nullable
private static Set<PsiAnnotation.TargetType> targetTypesForDefault(PsiAnnotation annotation) {
PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
PsiElement declaration = element == null ? null : element.resolve();
if (!(declaration instanceof PsiClass)) {
return Collections.emptySet();
}
PsiClass classDeclaration = (PsiClass) declaration;
PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
if (tqDefault == null) {
return Collections.emptySet();
}
return extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例5: findAnnotations
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
if (overridesSuper(element)) {
return Collections.emptyList();
}
List<String> annotations = new ArrayList<>();
Project project = element.getProject();
PsiModifierList modifierList = element.getModifierList();
List<String> nullabilityAnnotations = nullable
? NullableNotNullManager.getInstance(project).getNullables()
: NullableNotNullManager.getInstance(project).getNotNulls();
for (String notNullAnnotationFqn : nullabilityAnnotations) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
annotations.add(annotation.getQualifiedName());
}
}
return annotations;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:22,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例6: isNullabilityAnnotationForTypeQualifierDefault
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
private static boolean isNullabilityAnnotationForTypeQualifierDefault(PsiAnnotation annotation,
boolean nullable,
PsiAnnotation.TargetType[] targetTypes) {
PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
PsiElement declaration = element == null ? null : element.resolve();
if (!(declaration instanceof PsiClass)) {
return false;
}
String fqn = nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL;
PsiClass classDeclaration = (PsiClass) declaration;
if (!AnnotationUtil.isAnnotated(classDeclaration, fqn, false, true)) {
return false;
}
PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
if (tqDefault == null) {
return false;
}
Set<PsiAnnotation.TargetType> required = extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
return required != null
&& (required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(targetTypes)));
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:25,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例7: visitClass
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@Override
public void visitClass(UClass uClass) {
//only check interface
if(!uClass.isInterface()){
return;
}
Set<PropInfo> infos = getPropInfoWithSupers(uClass);
if(infos.isEmpty()){
return;
}
//check method is relative of any field
for(UMethod method: uClass.getMethods()){
PsiModifierList list = method.getModifierList();
PsiAnnotation pa_keep = list.findAnnotation(NAME_KEEP);
PsiAnnotation pa_impl = list.findAnnotation(NAME_IMPL_METHOD);
if (pa_keep == null && pa_impl == null) {
if(!hasPropInfo(infos, method.getName())){
report(method);
}
}
}
}
示例8: find
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
public static PsiElement find( PsiModifierListOwner resolve, ManifoldPsiClass facade )
{
PsiModifierList modifierList = resolve.getModifierList();
if( modifierList == null )
{
return null;
}
PsiAnnotation[] annotations = modifierList.getAnnotations();
if( annotations.length > 0 &&
Objects.equals( annotations[0].getQualifiedName(), SourcePosition.class.getName() ) )
{
return findTargetFeature( annotations[0], facade );
}
if( !facade.getRawFiles().isEmpty() &&
DarkJavaTypeManifold.FILE_EXTENSIONS.stream()
.anyMatch( ext -> ext.equalsIgnoreCase( facade.getRawFiles().get( 0 ).getVirtualFile().getExtension() ) ) )
{
// DarkJava is Java
return facade.getRawFiles().get( 0 ).findElementAt( resolve.getTextOffset() );
}
return null;
}
示例9: errrantThisOrExtension
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
private void errrantThisOrExtension( PsiElement element, AnnotationHolder holder )
{
if( element instanceof PsiModifierList )
{
PsiModifierList mods = (PsiModifierList)element;
PsiAnnotation annotation;
if( (annotation = mods.findAnnotation( Extension.class.getName() )) != null ||
(annotation = mods.findAnnotation( This.class.getName() )) != null)
{
TextRange range = new TextRange( annotation.getTextRange().getStartOffset(),
annotation.getTextRange().getEndOffset() );
//noinspection ConstantConditions
holder.createErrorAnnotation( range, ExtIssueMsg.MSG_NOT_IN_EXTENSION_CLASS.get( ClassUtil.extractClassName( annotation.getQualifiedName() ) ) );
}
}
}
示例10: isStructuralType
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
private boolean isStructuralType( PsiTypeElement typeElem )
{
if( typeElem != null )
{
PsiClass psiClass = PsiUtil.resolveClassInType( typeElem.getType() );
if( psiClass == null )
{
return false;
}
PsiAnnotation structuralAnno = psiClass.getModifierList() == null
? null
: psiClass.getModifierList().findAnnotation( "manifold.ext.api.Structural" );
if( structuralAnno != null )
{
return true;
}
}
return false;
}
示例11: isJavaElementForType
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
private static boolean isJavaElementForType( PsiModifierListOwner modifierListOwner, PsiClass psiClass )
{
PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( TypeReference.class.getName() );
if( annotation != null )
{
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for( PsiNameValuePair pair : attributes )
{
String fqn = pair.getLiteralValue();
if( psiClass.getQualifiedName().contains( fqn ) )
{
return true;
}
}
}
return false;
}
示例12: findAnnotation
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
static PsiAnnotation findAnnotation(PsiElement element, String annotationName) {
if (element instanceof PsiModifierListOwner) {
PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
PsiModifierList modifierList = listOwner.getModifierList();
if (modifierList != null) {
for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
if (annotationName.equals(psiAnnotation.getQualifiedName())) {
return psiAnnotation;
}
}
}
}
return null;
}
示例13: isAvailable
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file) {
final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
final PsiModifierListOwner owner = getAnnotationOwner(leaf);
if (owner != null && isSourceCode(owner)) {
boolean hasSrcInferredAnnotation = ContainerUtil.or(findSignatureNonCodeAnnotations(owner, true), new Condition<PsiAnnotation>() {
@Override
public boolean value(PsiAnnotation annotation) {
return AnnotationUtil.isInferredAnnotation(annotation);
}
});
if (hasSrcInferredAnnotation) {
setText((CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS ? "Hide" : "Show") + " annotations inferred from source code");
return true;
}
}
return false;
}
示例14: render
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@NotNull
public static Result render(@Nullable ResourceIdResolver resolver,
@NotNull PsiAnnotation annotation,
int value) {
String qualifiedName = getQualifiedName(annotation);
if (qualifiedName == null) {
return renderUnknown(null, value);
}
if (SupportAnnotationDetector.COLOR_INT_ANNOTATION.equals(qualifiedName)) {
return renderColorInt(value);
}
else if (qualifiedName.endsWith(SupportAnnotationDetector.RES_SUFFIX)) {
return renderResourceRefAnnotation(resolver, value, qualifiedName);
}
else if (qualifiedName.equals(SdkConstants.INT_DEF_ANNOTATION)) {
return renderIntDefAnnotation(annotation, value);
}
return renderUnknown(qualifiedName, value);
}
示例15: renderIntDefAnnotation
import com.intellij.psi.PsiAnnotation; //导入依赖的package包/类
@NotNull
private static Result renderIntDefAnnotation(@NotNull final PsiAnnotation annotation, final int value) {
final AtomicReference<AndroidResolveHelper.IntDefResolution> valuesRef = Atomics.newReference();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
valuesRef.set(AndroidResolveHelper.resolveIntDef(annotation));
}
});
AndroidResolveHelper.IntDefResolution intDef = valuesRef.get();
if (intDef.valuesMap == null) {
renderUnknown("IntDef", value);
}
return new Result(String.format(Locale.US, "0x%1$08x {%2$s}", value, renderIntDef(value, intDef)), null);
}