本文整理汇总了Java中com.intellij.codeInspection.LocalQuickFix类的典型用法代码示例。如果您正苦于以下问题:Java LocalQuickFix类的具体用法?Java LocalQuickFix怎么用?Java LocalQuickFix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalQuickFix类属于com.intellij.codeInspection包,在下文中一共展示了LocalQuickFix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProblemDescriptorWithQuickFixes
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
private void createProblemDescriptorWithQuickFixes(PsiModifierListOwner owner,
InspectionManager manager,
Collection<ProblemDescriptor> problemDescriptors,
PsiElement element) {
if (element.isPhysical()) {
LocalQuickFix[] localQuickFixes = createQuickFixes(owner, isRemoveRedundantAnnotations());
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
element,
MISSING_NULLABLE_NONNULL_ANNOTATION,
localQuickFixes,
GENERIC_ERROR_OR_WARNING,
true,
false);
problemDescriptors.add(problemDescriptor);
}
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:17,代码来源:NullabilityAnnotationsInspection.java
示例2: buildVisitor
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@Override
public LuaElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new LuaElementVisitor() {
public void visitFunctionDef(LuaFunctionDefinitionStatement func) {
super.visitFunctionDef(func);
final int limit = getLimit();
final CyclomaticComplexityVisitor visitor = new CyclomaticComplexityVisitor();
final LuaBlock body = func.getBlock();
if (body == null) {
return;
}
body.accept(visitor);
final int complexity = visitor.getComplexity();
if (complexity <= limit) {
return;
}
holder.registerProblem(func.getIdentifier(), buildErrorString(complexity, limit), LocalQuickFix.EMPTY_ARRAY);
}
};
}
示例3: buildVisitor
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new LuaElementVisitor() {
public void visitFunctionDef(LuaFunctionDefinitionStatement def) {
super.visitFunctionDef(def);
if (def.getImpliedSelf() == null) return;
for (LuaLocal local : def.getBlock().getLocals()) {
if (local.getText().equals("self") && !local.equals(def.getImpliedSelf()))
holder.registerProblem(local, "Identifier hides implicit self", LocalQuickFix.EMPTY_ARRAY);
}
}
};
}
示例4: buildVisitor
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new LuaElementVisitor() {
@Override
public void visitCompoundIdentifier(LuaCompoundIdentifier e) {
super.visitCompoundIdentifier(e);
LuaExpression symbol = e.getRightSymbol();
if (symbol instanceof LuaLiteralExpression) {
if (symbol.getLuaType() == LuaPrimitiveType.NUMBER && symbol.getText().equals("0"))
holder.registerProblem(e, "Use of element 0", LocalQuickFix.EMPTY_ARRAY);
}
}
};
}
示例5: buildVisitor
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new LuaElementVisitor() {
List<String> validGlobals = new ArrayList<String>();
public void visitDeclarationExpression(LuaDeclarationExpression var) {
super.visitDeclarationExpression(var);
if (var instanceof LuaGlobal && !StringUtil.isEmpty(var.getName())) {
LuaBlock block = PsiTreeUtil.getParentOfType(var, LuaBlock.class);
if (block == null) return;
if (block instanceof LuaPsiFile) {
validGlobals.add(var.getName());
return;
}
if (!validGlobals.contains(var.getName()))
holder.registerProblem(var, "Suspicious global creation ("+var.getName()+")", LocalQuickFix.EMPTY_ARRAY);
}
}
};
}
示例6: createAddToSpecialAnnotationsListQuickFix
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
public static LocalQuickFix createAddToSpecialAnnotationsListQuickFix(@NotNull final String text,
@NotNull final String family,
@NotNull final List<String> targetList,
@NotNull final String qualifiedName,
final PsiElement context) {
return new LocalQuickFix() {
@Override
@NotNull
public String getName() {
return text;
}
@Override
@NotNull
public String getFamilyName() {
return family;
}
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
doQuickFixInternal(project, targetList, qualifiedName);
}
};
}
示例7: visitCatchClause
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@Override
public void visitCatchClause(GrCatchClause catchClause) {
super.visitCatchClause(catchClause);
final GrOpenBlock block = catchClause.getBody();
if (block == null) {
return;
}
final GrParameter parameter = catchClause.getParameter();
if (parameter == null) {
return;
}
if (GrExceptionUtil.ignore(parameter)) return;
final CatchParameterUsedVisitor visitor = new CatchParameterUsedVisitor(parameter);
block.accept(visitor);
if (!visitor.isUsed()) {
final PsiElement nameIdentifier = parameter.getNameIdentifierGroovy();
registerError(nameIdentifier, "Unused catch parameter '#ref' #loc", new LocalQuickFix[]{QuickFixFactory.getInstance().createRenameElementFix(parameter, "ignored")},
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
示例8: doTest
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
public void doTest() {
myFixture.configureByFile(getTestName(false) + ".groovy");
final int offset = myFixture.getEditor().getCaretModel().getOffset();
final PsiElement atCaret = myFixture.getFile().findElementAt(offset);
final GrRangeExpression range = PsiTreeUtil.getParentOfType(atCaret, GrRangeExpression.class);
final GroovyRangeTypeCheckInspection inspection = new GroovyRangeTypeCheckInspection();
final GroovyFix fix = inspection.buildFix(range);
LocalQuickFix[] fixes = {fix};
final ProblemDescriptor descriptor = InspectionManager.getInstance(getProject()).createProblemDescriptor(range, "bla-bla", false, fixes, ProblemHighlightType.WEAK_WARNING);
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
fix.applyFix(myFixture.getProject(), descriptor);
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
}
});
myFixture.checkResultByFile(getTestName(false) + "_after.groovy");
}
示例9: buildVisitor
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(GrReferenceExpression referenceExpression) {
super.visitReferenceExpression(referenceExpression);
if (!PsiUtil.isLValue(referenceExpression)) return;
final PsiElement resolved = referenceExpression.resolve();
if (!PsiUtil.isLocalVariable(resolved)) return;
final PsiType checked = GrReassignedLocalVarsChecker.getReassignedVarType(referenceExpression, false);
if (checked == null) return;
final GrControlFlowOwner varFlowOwner = ControlFlowUtils.findControlFlowOwner(resolved);
final GrControlFlowOwner refFlorOwner = ControlFlowUtils.findControlFlowOwner(referenceExpression);
if (isOtherScopeAndType(referenceExpression, checked, varFlowOwner, refFlorOwner)) {
String flowDescription = getFlowDescription(refFlorOwner);
final String message = GroovyInspectionBundle
.message("local.var.0.is.reassigned", ((GrNamedElement)resolved).getName(), flowDescription);
registerError(referenceExpression, message, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:GrReassignedInClosureLocalVarInspection.java
示例10: addProblems
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
private static void addProblems(DomElement element, MavenDomProjectModel model, DomElementAnnotationHolder holder,
MavenProjectProblem.ProblemType... types) {
MavenProject mavenProject = MavenDomUtil.findProject(model);
if (mavenProject != null) {
for (MavenProjectProblem each : mavenProject.getProblems()) {
MavenProjectProblem.ProblemType type = each.getType();
if (!Arrays.asList(types).contains(type)) continue;
VirtualFile problemFile = LocalFileSystem.getInstance().findFileByPath(each.getPath());
LocalQuickFix[] fixes = LocalQuickFix.EMPTY_ARRAY;
if (problemFile != null && !Comparing.equal(mavenProject.getFile(), problemFile)) {
fixes = new LocalQuickFix[]{new OpenProblemFileFix(problemFile)};
}
holder.createProblem(element, HighlightSeverity.ERROR, each.getDescription(), fixes);
}
}
}
示例11: visitPyCallExpression
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@Override
public void visitPyCallExpression(final PyCallExpression node) {
PyClass klass = PsiTreeUtil.getParentOfType(node, PyClass.class);
if (klass != null && !klass.isNewStyleClass(null)) {
final List<PyClassLikeType> types = klass.getSuperClassTypes(myTypeEvalContext);
for (PyClassLikeType type : types) {
if (type == null) return;
final String qName = type.getClassQName();
if (qName != null && qName.contains("PyQt")) return;
if (!(type instanceof PyClassType)) return;
}
List<LocalQuickFix> quickFixes = Lists.<LocalQuickFix>newArrayList(new PyConvertToNewStyleQuickFix());
if (!types.isEmpty()) {
quickFixes.add(new PyChangeBaseClassQuickFix());
}
if (PyUtil.isSuperCall(node)) {
final PyExpression callee = node.getCallee();
if (callee != null) {
registerProblem(callee, "Old-style class contains call for super method", ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
null, quickFixes.toArray(quickFixes.toArray(new LocalQuickFix[quickFixes.size()])));
}
}
}
}
示例12: DomElementProblemDescriptorImpl
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
public DomElementProblemDescriptorImpl(@NotNull final DomElement domElement,
final String message,
final HighlightSeverity type,
@Nullable final TextRange textRange,
ProblemHighlightType highlightType,
@NotNull LocalQuickFix... fixes) {
myDomElement = domElement;
final XmlElement element = domElement.getXmlElement();
if (element != null && !ApplicationManager.getApplication().isUnitTestMode()) {
//LOG.assertTrue(element.isPhysical(), "Problems may not be created for non-physical DOM elements");
}
mySeverity = type;
myMessage = message;
myFixes = ArrayUtil.contains(null, fixes) ? ContainerUtil.mapNotNull(fixes, FunctionUtil.<LocalQuickFix>id(), LocalQuickFix.EMPTY_ARRAY) : fixes;
if (textRange != null) {
final PsiElement psiElement = getPsiElement();
LOG.assertTrue(psiElement != null, "Problems with explicit text range can't be created for DOM elements without underlying XML element");
assert psiElement.isValid();
myPair = Pair.create(textRange, psiElement);
}
myHighlightType = highlightType;
}
示例13: createFix
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
public static LocalQuickFix[] createFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) {
ImplementOrExtendFix fix = null;
if (compClass.isInterface() && compClass.getImplementsList() != null) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
} else if (!compClass.isInterface()) {
final PsiReferenceList extendsList = checkedClass.getExtendsList();
if (extendsList != null) {
if (extendsList.getReferenceElements().length == 0) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
} else if (extendsList.getReferenceElements().length == 1) {
// check for explicit "extends Object" case
final PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(),
checkedClass.getResolveScope());
if (extendsList.getReferencedTypes()[0].equals(javaLangObject)) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
}
}
}
}
return fix != null ? new LocalQuickFix[]{fix} : LocalQuickFix.EMPTY_ARRAY;
}
示例14: registerError
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@Override
protected void registerError(@NotNull PsiElement location,
@NotNull String description,
@Nullable LocalQuickFix[] fixes,
ProblemHighlightType highlightType) {
if (PsiUtil.isCompileStatic(location)) {
// filter all errors here, error will be highlighted by annotator
if (highlightType != ProblemHighlightType.GENERIC_ERROR) {
super.registerError(location, description, fixes, highlightType);
}
}
else {
if (highlightType == ProblemHighlightType.GENERIC_ERROR) {
// if this visitor works within non-static context we will highlight all errors as warnings
super.registerError(location, description, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
else {
// if this visitor works within static context errors will be highlighted as errors by annotator, warnings will be highlighted as warnings here
super.registerError(location, description, fixes, highlightType);
}
}
}
示例15: annotate
import com.intellij.codeInspection.LocalQuickFix; //导入依赖的package包/类
@Override
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
for (String attributeName : myAttributeNames) {
if (tag.getAttribute(attributeName) != null) {
return;
}
}
if (!isClosedTag(tag)) return;
PsiElement tagNameElement = getTagNameElement(tag);
if (tagNameElement == null) return;
LocalQuickFix[] fixes = new LocalQuickFix[myAttributeNames.length];
for (int i = 0; i < myAttributeNames.length; i++) {
fixes[i] = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, myAttributeNames[i]);
}
holder.registerProblem(tagNameElement, "Tag should have one of following attributes: " + StringUtil.join(myAttributeNames, ", "),
myProblemHighlightType,
fixes);
}