Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.language.psi;

import com.intellij.java.language.jvm.annotation.JvmAnnotationArrayValue;
import com.intellij.java.language.jvm.annotation.JvmAnnotationAttributeValue;
import consulo.util.collection.ContainerUtil;
import jakarta.annotation.Nonnull;

import java.util.List;

class PsiAnnotationArrayValue extends PsiAnnotationAttributeValue<PsiArrayInitializerMemberValue> implements JvmAnnotationArrayValue {
PsiAnnotationArrayValue(@Nonnull PsiArrayInitializerMemberValue value) {
super(value);
}

@Nonnull
@Override
public List<JvmAnnotationAttributeValue> getValues() {
return ContainerUtil.map(myElement.getInitializers(), PsiJvmConversionHelper::getAnnotationAttributeValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.language.psi;

import com.intellij.java.language.jvm.annotation.JvmAnnotationAttributeValue;
import jakarta.annotation.Nonnull;

abstract class PsiAnnotationAttributeValue<T extends PsiAnnotationMemberValue> implements JvmAnnotationAttributeValue {
protected final T myElement;

protected PsiAnnotationAttributeValue(@Nonnull T value) {
myElement = value;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.language.psi;

import com.intellij.java.language.jvm.JvmClass;
import com.intellij.java.language.jvm.annotation.JvmAnnotationClassValue;
import consulo.annotation.access.RequiredReadAction;
import consulo.language.psi.PsiElement;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

class PsiAnnotationClassValue extends PsiAnnotationAttributeValue<PsiClassObjectAccessExpression> implements JvmAnnotationClassValue {
PsiAnnotationClassValue(@Nonnull PsiClassObjectAccessExpression value) {
super(value);
}

private PsiJavaCodeReferenceElement getReferenceElement() {
return myElement.getOperand().getInnermostComponentReferenceElement();
}

@Nullable
@Override
public String getQualifiedName() {
PsiJavaCodeReferenceElement referenceElement = getReferenceElement();
return referenceElement == null ? null : referenceElement.getQualifiedName();
}

@Nullable
@Override
@RequiredReadAction
public JvmClass getClazz() {
PsiJavaCodeReferenceElement referenceElement = getReferenceElement();
if (referenceElement == null) {
return null;
}
PsiElement resolved = referenceElement.resolve();
return resolved instanceof JvmClass jvmClass ? jvmClass : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.language.psi;

import com.intellij.java.language.jvm.annotation.JvmAnnotationConstantValue;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

class PsiAnnotationConstantValue extends PsiAnnotationAttributeValue<PsiExpression> implements JvmAnnotationConstantValue {
PsiAnnotationConstantValue(@Nonnull PsiExpression value) {
super(value);
}

@Nullable
@Override
public Object getConstantValue() {
PsiConstantEvaluationHelper evaluationHelper = JavaPsiFacade.getInstance(myElement.getProject()).getConstantEvaluationHelper();
return evaluationHelper.computeConstantExpression(myElement);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.language.psi;

import com.intellij.java.language.jvm.JvmEnumField;
import com.intellij.java.language.jvm.annotation.JvmAnnotationEnumFieldValue;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

class PsiAnnotationEnumFieldValue extends PsiAnnotationAttributeValue<PsiReferenceExpression> implements JvmAnnotationEnumFieldValue {
private final JvmEnumField myEnumField;

PsiAnnotationEnumFieldValue(@Nonnull PsiReferenceExpression value, @Nonnull JvmEnumField field) {
super(value);
myEnumField = field;
}

@Nullable
@Override
public JvmEnumField getField() {
return myEnumField;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
* @author ven
*/
public interface PsiAnnotationMemberValue extends PsiElement {
/**
* The empty array of PSI annotation member values which can be reused to avoid unnecessary allocations.
*/
PsiAnnotationMemberValue[] EMPTY_ARRAY = new PsiAnnotationMemberValue[0];
/**
* The empty array of PSI annotation member values which can be reused to avoid unnecessary allocations.
*/
PsiAnnotationMemberValue[] EMPTY_ARRAY = new PsiAnnotationMemberValue[0];

ArrayFactory<PsiAnnotationMemberValue> ARRAY_FACTORY = new ArrayFactory<PsiAnnotationMemberValue>() {
@Nonnull
@Override
public PsiAnnotationMemberValue[] create(final int count) {
return count == 0 ? EMPTY_ARRAY : new PsiAnnotationMemberValue[count];
}
};
ArrayFactory<PsiAnnotationMemberValue> ARRAY_FACTORY = new ArrayFactory<>() {
@Nonnull
@Override
public PsiAnnotationMemberValue[] create(int count) {
return count == 0 ? EMPTY_ARRAY : new PsiAnnotationMemberValue[count];
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
* @author ven
*/
public interface PsiAnnotationMethod extends PsiMethod {
/**
* The empty array of PSI annotation methods which can be reused to avoid unnecessary allocations.
*/
PsiAnnotationMethod[] EMPTY_ARRAY = new PsiAnnotationMethod[0];
/**
* The empty array of PSI annotation methods which can be reused to avoid unnecessary allocations.
*/
PsiAnnotationMethod[] EMPTY_ARRAY = new PsiAnnotationMethod[0];

/**
* Returns the default value of the annotation element defined by the method.
*
* @return the default value of the element, or null if no default value is specified.
*/
@Nullable
PsiAnnotationMemberValue getDefaultValue();
/**
* Returns the default value of the annotation element defined by the method.
*
* @return the default value of the element, or null if no default value is specified.
*/
@Nullable
PsiAnnotationMemberValue getDefaultValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,59 @@
*/
package com.intellij.java.language.psi;

import org.jetbrains.annotations.NonNls;
import jakarta.annotation.Nonnull;

import jakarta.annotation.Nullable;

/**
* @author cdr
*/
public interface PsiAnnotationOwner
{
/**
* Returns the list of annotations syntactically contained in the element.
*
* @return the list of annotations.
*/
@Nonnull
PsiAnnotation[] getAnnotations();
public interface PsiAnnotationOwner {
/**
* Returns the list of annotations syntactically contained in the element.
*
* @return the list of annotations.
*/
@Nonnull
PsiAnnotation[] getAnnotations();

/**
* @return the list of annotations which are applicable to this owner
* (e.g. type annotations on method belong to its type element, not the method).
*/
@Nonnull
PsiAnnotation[] getApplicableAnnotations();
/**
* @return the list of annotations which are applicable to this owner
* (e.g. type annotations on method belong to its type element, not the method).
*/
@Nonnull
PsiAnnotation[] getApplicableAnnotations();

/**
* Searches the owner for an annotation with the specified fully qualified name
* and returns {@code true} if it is found.
* <p/>
* This method is preferable over {@link #findAnnotation}
* since implementations are free not to instantiate the {@link PsiAnnotation}.
*
* @param qualifiedName the fully qualified name of the annotation to find
* @return {@code true} is such annotation is found, otherwise {@code false}
*/
default boolean hasAnnotation(@Nonnull @NonNls String qualifiedName)
{
//noinspection SSBasedInspection
return findAnnotation(qualifiedName) != null;
}
/**
* Searches the owner for an annotation with the specified fully qualified name
* and returns {@code true} if it is found.
* <p/>
* This method is preferable over {@link #findAnnotation}
* since implementations are free not to instantiate the {@link PsiAnnotation}.
*
* @param qualifiedName the fully qualified name of the annotation to find
* @return {@code true} is such annotation is found, otherwise {@code false}
*/
default boolean hasAnnotation(@Nonnull String qualifiedName) {
//noinspection SSBasedInspection
return findAnnotation(qualifiedName) != null;
}

/**
* Searches the owner for an annotation with the specified fully qualified name
* and returns one if it is found.
*
* @param qualifiedName the fully qualified name of the annotation to find.
* @return the annotation instance, or null if no such annotation is found.
*/
@Nullable
PsiAnnotation findAnnotation(@Nonnull @NonNls String qualifiedName);
/**
* Searches the owner for an annotation with the specified fully qualified name
* and returns one if it is found.
*
* @param qualifiedName the fully qualified name of the annotation to find.
* @return the annotation instance, or null if no such annotation is found.
*/
@Nullable
PsiAnnotation findAnnotation(@Nonnull String qualifiedName);

/**
* Adds a new annotation to this owner. The annotation class name will be shortened. No attributes will be defined.
*
* @param qualifiedName qualifiedName
* @return newly added annotation
*/
@Nonnull
PsiAnnotation addAnnotation(@Nonnull @NonNls String qualifiedName);
/**
* Adds a new annotation to this owner. The annotation class name will be shortened. No attributes will be defined.
*
* @param qualifiedName qualifiedName
* @return newly added annotation
*/
@Nonnull
PsiAnnotation addAnnotation(@Nonnull String qualifiedName);
}
Loading
Loading