use of com.intellij.codeInspection.LocalQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoImportReference method getQuickFixes.
@Override
public LocalQuickFix[] getQuickFixes() {
if (GoPackageUtil.isBuiltinPackage(resolve())) {
return new LocalQuickFix[] { new GoDeleteImportQuickFix() };
}
List<LocalQuickFix> result = ContainerUtil.newArrayList();
FileReferenceSet fileReferenceSet = getFileReferenceSet();
if (fileReferenceSet instanceof GoImportReferenceSet && !((GoImportReferenceSet) fileReferenceSet).isRelativeImport() && !fileReferenceSet.isAbsolutePathReference()) {
result.add(new GoGetPackageFix(fileReferenceSet.getPathString()));
}
String fileNameToCreate = getFileNameToCreate();
for (PsiFileSystemItem context : getContexts()) {
if (context instanceof PsiDirectory) {
try {
((PsiDirectory) context).checkCreateSubdirectory(fileNameToCreate);
String targetPath = context.getVirtualFile().getPath();
result.add(new CreateFileFix(true, fileNameToCreate, (PsiDirectory) context) {
@NotNull
@Override
public String getText() {
return "Create Directory " + fileNameToCreate + " at " + targetPath;
}
});
} catch (IncorrectOperationException ignore) {
}
}
}
return result.toArray(new LocalQuickFix[result.size()]);
}
use of com.intellij.codeInspection.LocalQuickFix in project android by JetBrains.
the class ResourceReferenceConverter method getQuickFixes.
@Override
public LocalQuickFix[] getQuickFixes(ConvertContext context) {
AndroidFacet facet = AndroidFacet.getInstance(context);
if (facet != null) {
final DomElement domElement = context.getInvocationElement();
if (domElement instanceof GenericDomValue) {
final String value = ((GenericDomValue) domElement).getStringValue();
if (value != null) {
ResourceValue resourceValue = ResourceValue.parse(value, false, myWithPrefix, true);
if (resourceValue != null) {
String aPackage = resourceValue.getNamespace();
ResourceType resType = resourceValue.getType();
if (resType == null && myResourceTypes.size() == 1) {
resType = myResourceTypes.iterator().next();
}
final String resourceName = resourceValue.getResourceName();
if (aPackage == null && resType != null && resourceName != null && AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) {
final List<LocalQuickFix> fixes = new ArrayList<>();
ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resType);
if (folderType != null) {
fixes.add(new CreateFileResourceQuickFix(facet, folderType, resourceName, context.getFile(), false));
}
if (VALUE_RESOURCE_TYPES.contains(resType) && resType != ResourceType.LAYOUT) {
// layouts: aliases only
fixes.add(new CreateValueResourceQuickFix(facet, resType, resourceName, context.getFile(), false));
}
return fixes.toArray(new LocalQuickFix[fixes.size()]);
}
}
}
}
}
return LocalQuickFix.EMPTY_ARRAY;
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.
the class FlexUnitMethodReturnTypeInspection method visitPotentialTestMethod.
protected void visitPotentialTestMethod(JSFunction method, ProblemsHolder holder, FlexUnitSupport support) {
if (FlexUnitSupport.getCustomRunner((JSClass) method.getParent()) != null)
return;
if (method.getKind() != JSFunction.FunctionKind.SIMPLE)
return;
if (support.isFlexUnit1Subclass((JSClass) method.getParent()) || support.isFlunitSubclass((JSClass) method.getParent())) {
return;
}
final JSType returnType = method.getReturnType();
if (returnType != null && !(returnType instanceof JSVoidType)) {
final ASTNode nameIdentifier = method.findNameIdentifier();
if (nameIdentifier != null) {
LocalQuickFix[] fix = canFix(method) ? new LocalQuickFix[] { new ChangeTypeFix(method, "void", "javascript.fix.set.method.return.type") } : LocalQuickFix.EMPTY_ARRAY;
holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("flexunit.inspection.testmethodreturntype.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class AntResolveInspection method checkReferences.
private static void checkReferences(final XmlElement xmlElement, @NonNls final DomElementAnnotationHolder holder, DomElement domElement) {
if (xmlElement == null) {
return;
}
Set<PsiReference> processed = null;
// to be initialized lazily
Collection<PropertiesFile> propertyFiles = null;
for (final PsiReference ref : xmlElement.getReferences()) {
if (!(ref instanceof AntDomReference)) {
continue;
}
final AntDomReference antDomRef = (AntDomReference) ref;
if (antDomRef.shouldBeSkippedByAnnotator()) {
continue;
}
if (processed != null && processed.contains(ref)) {
continue;
}
if (!isResolvable(ref)) {
final List<LocalQuickFix> quickFixList = new SmartList<>();
quickFixList.add(new AntChangeContextLocalFix());
if (ref instanceof AntDomPropertyReference) {
final String canonicalText = ref.getCanonicalText();
quickFixList.add(new AntCreatePropertyFix(canonicalText, null));
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
if (propertyFiles == null) {
propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement);
}
for (PropertiesFile propertyFile : propertyFiles) {
quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile));
}
}
} else if (ref instanceof AntDomTargetReference) {
quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
}
holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])));
if (ref instanceof AntDomFileReference) {
if (processed == null) {
processed = new HashSet<>();
}
ContainerUtil.addAll(processed, ((AntDomFileReference) ref).getFileReferenceSet().getAllReferences());
}
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class ComponentNotRegisteredInspection method checkClass.
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
PsiFile psiFile = checkedClass.getContainingFile();
PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
if (checkedClass.getQualifiedName() != null && classIdentifier != null && psiFile != null && psiFile.getVirtualFile() != null && !checkedClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (PsiUtil.isInnerClass(checkedClass)) {
// don't check inner classes (make this an option?)
return null;
}
PsiManager psiManager = checkedClass.getManager();
GlobalSearchScope scope = checkedClass.getResolveScope();
if (CHECK_ACTIONS) {
PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
if (actionClass == null) {
// stop if action class cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(actionClass, true)) {
if (IGNORE_NON_PUBLIC && !checkedClass.hasModifierProperty(PsiModifier.PUBLIC)) {
return null;
}
if (!isActionRegistered(checkedClass) && canFix(checkedClass)) {
LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message("new.menu.action.text")), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
return new ProblemDescriptor[] { problem };
} else {
// action IS registered, stop here
return null;
}
}
}
ComponentType[] types = ComponentType.values();
for (ComponentType type : types) {
PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
if (compClass == null) {
// stop if component classes cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(compClass, true)) {
if (RegistrationCheckerUtil.getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) {
LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message(type.myPropertyKey)), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
return new ProblemDescriptor[] { problem };
} else {
// component IS registered, stop here
return null;
}
}
}
}
return null;
}
Aggregations