本文整理汇总了Java中com.intellij.psi.PsiModifierList类的典型用法代码示例。如果您正苦于以下问题:Java PsiModifierList类的具体用法?Java PsiModifierList怎么用?Java PsiModifierList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiModifierList类属于com.intellij.psi包,在下文中一共展示了PsiModifierList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAnnotations
import com.intellij.psi.PsiModifierList; //导入依赖的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
示例2: visitClass
import com.intellij.psi.PsiModifierList; //导入依赖的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);
}
}
}
}
示例3: find
import com.intellij.psi.PsiModifierList; //导入依赖的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;
}
示例4: errrantThisOrExtension
import com.intellij.psi.PsiModifierList; //导入依赖的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() ) ) );
}
}
}
示例5: findAnnotation
import com.intellij.psi.PsiModifierList; //导入依赖的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;
}
示例6: showDialog
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
@Override
protected String showDialog() {
Project project = getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
Module module = myModuleSelector.getModule();
if (module == null) {
Messages.showErrorDialog(project, ExecutionBundle.message("module.not.specified.error.text"), CommonBundle.getErrorTitle());
return null;
}
GlobalSearchScope scope =
myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
PsiClass initialSelection = facade.findClass(getText(), scope);
TreeClassChooser chooser = createTreeClassChooser(project, scope, initialSelection, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
if (aClass.isInterface()) return false;
final PsiModifierList modifierList = aClass.getModifierList();
return modifierList == null || !modifierList.hasModifierProperty(PsiModifier.ABSTRACT);
}
});
if (chooser == null) return null;
chooser.showDialog();
PsiClass selClass = chooser.getSelected();
return selClass != null ? selClass.getQualifiedName() : null;
}
示例7: doFix
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiMethod method = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethod.class);
if (method != null) {
final PsiModifierList modifierList = method.getModifierList();
if (!modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
}
if (!modifierList.hasModifierProperty(PsiModifier.STATIC)) {
modifierList.setModifierProperty(PsiModifier.STATIC, true);
}
if (method.getReturnType() != PsiType.VOID) {
ChangeSignatureProcessor csp =
new ChangeSignatureProcessor(project, method, false, PsiModifier.PUBLIC, method.getName(), PsiType.VOID,
new ParameterInfoImpl[0]);
csp.run();
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:BeforeClassOrAfterClassIsPublicStaticVoidNoArgInspection.java
示例8: doFix
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final Iterable<String> ids;
if (psiElement instanceof PsiAnnotation) {
ids = JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation((PsiModifierList)psiElement.getParent());
}
else {
final String suppressedIds = JavaSuppressionUtil.getSuppressedInspectionIdsIn(psiElement);
if (suppressedIds == null) {
return;
}
ids = StringUtil.tokenize(suppressedIds, ",");
}
for (String id : ids) {
if (!myAllowedSuppressions.contains(id)) {
myAllowedSuppressions.add(id);
}
}
saveProfile(project);
}
示例9: visitAnnotation
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
@Override
public void visitAnnotation(GrAnnotation annotation) {
super.visitAnnotation(annotation);
PsiElement parent = annotation.getParent().getParent();
if (parent == null || !(parent instanceof GrTypeDefinition)) return;
if (SINGLETON.equals(annotation.getQualifiedName())) {
GrTypeDefinition typeDefinition = (GrTypeDefinition)parent;
PsiMethod[] methods = typeDefinition.getMethods();
for (PsiMethod method : methods) {
if (method.isConstructor()) {
PsiModifierList modifierList = method.getModifierList();
if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
registerClassError(typeDefinition);
}
}
}
}
}
示例10: checkApplicability
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
final String qname = annotation.getQualifiedName();
if (!GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD.equals(qname)) return false;
checkScriptField(holder, annotation);
PsiElement annoParent = annotation.getParent();
PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
if (!(ownerToUse instanceof GrVariableDeclaration) ||
!PsiUtil.isLocalVariable(((GrVariableDeclaration)ownerToUse).getVariables()[0])) {
return false;
}
if (!GrAnnotationImpl.isAnnotationApplicableTo(annotation, PsiAnnotation.TargetType.LOCAL_VARIABLE)) {
GrCodeReferenceElement ref = annotation.getClassReference();
String target = JavaErrorMessages.message("annotation.target.LOCAL_VARIABLE");
String description = JavaErrorMessages.message("annotation.not.applicable", ref.getText(), target);
holder.createErrorAnnotation(ref, description);
}
return true;
}
示例11: writeModifiers
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
public static boolean writeModifiers(StringBuilder builder, PsiModifierList modifierList, String[] modifiers, boolean writeAnnotations) {
boolean wasAddedModifiers = false;
if (writeAnnotations && modifierList instanceof GrModifierList) {
GrAnnotation[] annotations = ((GrModifierList)modifierList).getAnnotations();
AnnotationGenerator annotationGenerator = new AnnotationGenerator(builder, new ExpressionContext(modifierList.getProject(), GroovyFile.EMPTY_ARRAY));
wasAddedModifiers = annotations.length > 0;
for (GrAnnotation annotation : annotations) {
annotation.accept(annotationGenerator);
builder.append(' ');
}
}
for (String modifierType : modifiers) {
if (modifierList.hasModifierProperty(modifierType)) {
builder.append(modifierType);
builder.append(' ');
wasAddedModifiers = true;
}
}
return wasAddedModifiers;
}
示例12: writeClassModifiers
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
public static void writeClassModifiers(StringBuilder text,
@Nullable PsiModifierList modifierList,
boolean isInterface,
boolean isEnum,
boolean toplevel,
boolean generateAnnotations) {
if (modifierList == null) {
text.append("public ");
return;
}
List<String> allowedModifiers = new ArrayList<String>();
allowedModifiers.add(PsiModifier.PUBLIC);
if (!isEnum) allowedModifiers.add(PsiModifier.FINAL);
if (!toplevel) {
allowedModifiers.addAll(Arrays.asList(PsiModifier.PROTECTED, PsiModifier.PRIVATE, PsiModifier.STATIC));
}
if (!isInterface && !isEnum) {
allowedModifiers.add(PsiModifier.ABSTRACT);
}
writeModifiers(text, modifierList, ArrayUtil.toStringArray(allowedModifiers), generateAnnotations);
}
示例13: hasParameterName
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
private boolean hasParameterName(PsiParameter psiParameter) {
PsiModifierList modifierList = psiParameter.getModifierList();
if (modifierList == null) {
return false;
}
PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named");
if (annotation != null) {
return true;
}
annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED);
if (annotation != null) {
return true;
}
return false;
}
示例14: isPublicNullaryConstructor
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
/** Checks if the supplied method is a public constructor with no parameters. */
public static boolean isPublicNullaryConstructor(PsiMethod method) {
if (!method.isConstructor()) {
return false;
}
if (method.getParameterList().getParametersCount() > 0) {
return false;
}
PsiModifierList modifierList = method.getModifierList();
if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
return true;
}
return false;
}
示例15: initializePsiMethod
import com.intellij.psi.PsiModifierList; //导入依赖的package包/类
private void initializePsiMethod(String methodName, String httpMethodValue, String pathValue) {
PsiAnnotationMemberValue mockAnnotationMemberValue1 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue1.getText()).thenReturn(httpMethodValue);
PsiAnnotationMemberValue mockAnnotationMemberValue2 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue2.getText()).thenReturn(pathValue);
PsiAnnotation mockAnnotation = mock(PsiAnnotation.class);
when(mockAnnotation.getQualifiedName())
.thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API_METHOD);
when(mockAnnotation.findAttributeValue("httpMethod")).thenReturn(mockAnnotationMemberValue1);
when(mockAnnotation.findAttributeValue("path")).thenReturn(mockAnnotationMemberValue2);
PsiAnnotation[] mockAnnotationsArray = {mockAnnotation};
PsiModifierList mockModifierList = mock(PsiModifierList.class);
when(mockModifierList.getAnnotations()).thenReturn(mockAnnotationsArray);
mockPsiMethod = mock(PsiMethod.class);
when(mockPsiMethod.getModifierList()).thenReturn(mockModifierList);
when(mockPsiMethod.getName()).thenReturn(methodName);
when(mockPsiMethod.getContainingClass()).thenReturn(mockPsiClass);
PsiParameterList mockParameterList = mock(PsiParameterList.class);
when(mockParameterList.getParameters()).thenReturn(new PsiParameter[0]);
when(mockPsiMethod.getParameterList()).thenReturn(mockParameterList);
}