use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.
the class SuppressParameterFix method createSuppression.
@Override
protected void createSuppression(@NotNull Project project, @NotNull PsiElement element, @NotNull PsiElement cont) throws IncorrectOperationException {
PsiModifierListOwner container = (PsiModifierListOwner) cont;
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
final String id = SuppressFix.getID(container, myAlternativeID);
JavaSuppressionUtil.addSuppressAnnotation(project, container, container, id != null ? id : myID);
}
}
use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.
the class VisibilityListener method perform.
/**
* to be performed in write action
*/
public void perform(final PsiVariable variable) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
final Document document = myEditor.getDocument();
LOG.assertTrue(variable != null);
final PsiModifierList modifierList = variable.getModifierList();
LOG.assertTrue(modifierList != null);
int textOffset = modifierList.getTextOffset();
final String modifierListText = modifierList.getText();
int length = PsiModifier.PUBLIC.length();
int idx = modifierListText.indexOf(PsiModifier.PUBLIC);
if (idx == -1) {
idx = modifierListText.indexOf(PsiModifier.PROTECTED);
length = PsiModifier.PROTECTED.length();
}
if (idx == -1) {
idx = modifierListText.indexOf(PsiModifier.PRIVATE);
length = PsiModifier.PRIVATE.length();
}
String visibility = getVisibility();
if (visibility == PsiModifier.PACKAGE_LOCAL) {
visibility = "";
}
final boolean wasPackageLocal = idx == -1;
final boolean isPackageLocal = visibility.isEmpty();
final int startOffset = textOffset + (wasPackageLocal ? 0 : idx);
final int endOffset;
if (wasPackageLocal) {
endOffset = startOffset;
} else {
endOffset = textOffset + length + (isPackageLocal ? 1 : 0);
}
final String finalVisibility = visibility + (wasPackageLocal ? " " : "");
Runnable runnable = () -> document.replaceString(startOffset, endOffset, finalVisibility);
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
if (lookup != null) {
lookup.performGuardedChange(runnable);
} else {
runnable.run();
}
}
use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.
the class FieldAnnotationChecker method checkApplicability.
@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)) {
return false;
} else {
GrVariableDeclaration declaration = (GrVariableDeclaration) ownerToUse;
if (declaration.getVariables().length != 1 || !PsiUtil.isLocalVariable(declaration.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;
}
use of com.intellij.psi.PsiModifierList in project android by JetBrains.
the class AndroidLintAnimatorKeepInspection method getQuickFixes.
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
return new AndroidLintQuickFix[] { new AndroidLintQuickFix() {
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
if (!ObjectAnimatorDetector.isAddKeepErrorMessage(message, TextFormat.RAW)) {
return;
}
PsiModifierListOwner container = PsiTreeUtil.getParentOfType(startElement, PsiModifierListOwner.class);
if (container == null) {
return;
}
if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) {
return;
}
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(container, KEEP_ANNOTATION);
if (annotation == null) {
Project project = startElement.getProject();
new AddAnnotationFix(KEEP_ANNOTATION, container).invoke(project, null, container.getContainingFile());
}
}
}
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
return true;
}
@NotNull
@Override
public String getName() {
return "Annotate with @Keep";
}
} };
}
use of com.intellij.psi.PsiModifierList in project smali by JesusFreke.
the class SmalideaClassDef method getAccessFlags.
@Override
public int getAccessFlags() {
PsiModifierList modifierList = psiClass.getModifierList();
int flags = 0;
if (modifierList == null) {
return flags;
}
if (modifierList.hasModifierProperty("public")) {
flags |= AccessFlags.PUBLIC.getValue();
}
if (modifierList.hasModifierProperty("final")) {
flags |= AccessFlags.FINAL.getValue();
}
if (modifierList.hasModifierProperty("abstract")) {
flags |= AccessFlags.ABSTRACT.getValue();
}
if (psiClass.isInterface()) {
flags |= AccessFlags.INTERFACE.getValue();
}
if (psiClass.isEnum()) {
flags |= AccessFlags.ENUM.getValue();
}
if (psiClass.isAnnotationType()) {
flags |= AccessFlags.ANNOTATION.getValue();
}
return flags;
}
Aggregations