當前位置: 首頁>>代碼示例>>Java>>正文


Java ProblemDescriptor類代碼示例

本文整理匯總了Java中com.intellij.codeInspection.ProblemDescriptor的典型用法代碼示例。如果您正苦於以下問題:Java ProblemDescriptor類的具體用法?Java ProblemDescriptor怎麽用?Java ProblemDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProblemDescriptor類屬於com.intellij.codeInspection包,在下文中一共展示了ProblemDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement expression = descriptor.getPsiElement();
    if (expression instanceof ArrayHashElement) {
        PsiElement next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (null != next && PhpTokenTypes.opCOMMA == next.getNode().getElementType()) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }

        expression.delete();
    }
}
 
開發者ID:kalessil,項目名稱:yii2inspections,代碼行數:21,代碼來源:UnusedTranslationsInspector.java

示例2: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {

    PsiElement psiElement = descriptor.getPsiElement();
    if (DumbService.isDumb(project)) {
        showIsInDumpModeMessage(project, psiElement);
        return;
    }

    if (psiElement instanceof ClassReference) {
        ClassReference classReference = (ClassReference) psiElement;
        String fqn = classReference.getFQN();
        if (fqn != null) {
            String replacementFQN = LegacyClassesForIDEIndex.findReplacementClass(project, fqn);
            if (replacementFQN != null) {
                try {
                    classReference.replace(PhpPsiElementFactory.createClassReference(project, replacementFQN));
                } catch (IncorrectOperationException e) {
                    showErrorMessage(project, "Could not replace class reference", psiElement);
                }
            }
        }
    }
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:25,代碼來源:LegacyClassesForIdeQuickFix.java

示例3: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
/**
 * Called to apply the fix.
 *
 * @param project    {@link Project}
 * @param descriptor problem reported by the tool which provided this quick fix action
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement psiElement = descriptor.getPsiElement();
    if (psiElement instanceof StringLiteralExpression) {
        StringLiteralExpression stringElement = (StringLiteralExpression) psiElement;
        String contents = stringElement.getContents();

        String fileName = TranslationUtil.extractResourceFilenameFromTranslationString(contents);
        String key = TranslationUtil.extractTranslationKeyTranslationString(contents);
        if (fileName != null) {
            PsiElement[] elementsForKey = ResourcePathIndex.findElementsForKey(project, fileName);
            if (elementsForKey.length > 0) {
                // TranslationUtil.add();
            }
        }
    }
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:24,代碼來源:CreateMissingTranslationQuickFix.java

示例4: createProblemDescriptorWithQuickFixes

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的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

示例5: validateOneRule

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
protected void validateOneRule(
    @NotNull final XmlRule rule,
    @NotNull final ValidateContext context,
    @NotNull final Collection<? super ProblemDescriptor> output
) throws XPathExpressionException {
    final XPathService xPathService = ServiceManager.getService(XPathService.class);

    final NodeList selection = xPathService.computeNodeSet(rule.getSelectionXPath(), context.getDocument());
    for (int i = 0; i < selection.getLength(); i++) {
        final Node nextSelected = selection.item(i);
        boolean passed = xPathService.computeBoolean(rule.getTestXPath(), nextSelected);
        if (rule.isFailOnTestQuery()) {
            passed = !passed;
        }
        if (!passed) {
            output.add(this.createProblem(context, nextSelected, rule));
        }
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:20,代碼來源:XmlRuleInspection.java

示例6: createProblem

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
protected ProblemDescriptor createProblem(
    @NotNull final ValidateContext context,
    @NotNull final Node problemNode,
    @NotNull final XmlRule rule
) {
    final PsiElement problemPsi = context.mapNodeToPsi(problemNode);
    final ProblemHighlightType highlightType = this.computePriority(rule);

    return context.getManager().createProblemDescriptor(
        problemPsi,
        rule.getDescription(),
        true,
        highlightType,
        context.isOnTheFly()
    );
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:17,代碼來源:XmlRuleInspection.java

示例7: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    try {
        PsiElement element = descriptor.getPsiElement();
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element);
        if (quotePosition != -1) {
            quotePositions.add(quotePosition);
        }
        PsiElement endSeparatorElement = CsvIntentionHelper.findQuotePositionsUntilSeparator(element, quotePositions);
        if (endSeparatorElement == null) {
            quotePositions.add(document.getTextLength());
        } else {
            quotePositions.add(endSeparatorElement.getTextOffset());
        }
        String text = CsvIntentionHelper.addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:24,代碼來源:CsvValidationInspection.java

示例8: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
  final PyFunction function = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PyFunction.class);
  if (function == null) return;
  final PyClass cls = function.getContainingClass();
  assert cls != null;
  final String functionName = function.getName();
  final String complementaryName = PyNames.NEW.equals(functionName) ? PyNames.INIT : PyNames.NEW;
  final TypeEvalContext context = TypeEvalContext.userInitiated(project, descriptor.getEndElement().getContainingFile());
  final PyFunction complementaryMethod = myOverridenMethod ? (PyFunction)PySuperMethodsSearch.search(function, context).findFirst()
                                                           : cls.findMethodByName(complementaryName, true);

  assert complementaryMethod != null;
  final PyMethodDescriptor methodDescriptor = new PyMethodDescriptor(function) {
    @Override
    public List<PyParameterInfo> getParameters() {
      final List<PyParameterInfo> parameterInfos = super.getParameters();
      final int paramLength = function.getParameterList().getParameters().length;
      final int complementaryParamLength = complementaryMethod.getParameterList().getParameters().length;
      if (complementaryParamLength > paramLength)
        parameterInfos.add(new PyParameterInfo(-1, "**kwargs", "", false));
      return parameterInfos;
    }
  };
  final PyChangeSignatureDialog dialog = new PyChangeSignatureDialog(project, methodDescriptor);
  dialog.show();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:PyChangeSignatureQuickFix.java

示例9: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)
  throws IncorrectOperationException {
  final PsiBinaryExpression expression =
    (PsiBinaryExpression)descriptor.getPsiElement();
  final PsiExpression lhs = expression.getLOperand();
  final PsiExpression rhs = expression.getROperand();
  final String newExpressionText;
  if (lhs instanceof PsiMethodCallExpression) {
    final PsiMethodCallExpression callExpression =
      (PsiMethodCallExpression)lhs;
    newExpressionText =
      createContainsExpressionText(callExpression, false,
                                   expression.getOperationTokenType());
  }
  else {
    final PsiMethodCallExpression callExpression =
      (PsiMethodCallExpression)rhs;
    assert callExpression != null;
    newExpressionText =
      createContainsExpressionText(callExpression, true,
                                   expression.getOperationTokenType());
  }
  PsiReplacementUtil.replaceExpression(expression, newExpressionText);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:ListIndexOfReplaceableByContainsInspection.java

示例10: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiClass)) {
    return;
  }
  final PsiClass aClass = (PsiClass)parent;
  for (PsiMethod constructor : aClass.getConstructors()) {
    constructor.delete();
  }
  final List<PsiKeyword> keywords = PsiTreeUtil.getChildrenOfTypeAsList(aClass, PsiKeyword.class);
  if (keywords.isEmpty()) {
    return;
  }
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final PsiStatement statement = factory.createStatementFromText(";", element);
  final PsiElement token = statement.getChildren()[0];
  aClass.addAfter(token, aClass.getLBrace());
  final PsiKeyword newKeyword = factory.createKeyword(PsiKeyword.ENUM);
  keywords.get(0).replace(newKeyword);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:UtilityClassCanBeEnumInspection.java

示例11: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)
  throws IncorrectOperationException {
  final PsiElement element = descriptor.getPsiElement();
  final String text = element.getText();
  final int max = text.length() - 1;
  if (max < 1) {
    return;
  }
  int index = 0;
  while (index < max && (text.charAt(index) == '0' || text.charAt(index) == '_')) {
    index++;
  }
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiElementFactory factory = psiFacade.getElementFactory();
  final String textWithoutLeadingZeros = text.substring(index);
  final PsiExpression decimalNumber =
    factory.createExpressionFromText(textWithoutLeadingZeros,
                                     element);
  element.replace(decimalNumber);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:RemoveLeadingZeroFix.java

示例12: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiIdentifier name = (PsiIdentifier)descriptor.getPsiElement();
  final PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement)name.getParent();
  final PsiClass aClass = (PsiClass)reference.resolve();
  if (aClass == null) {
    return;
  }
  final PsiClass containingClass = aClass.getContainingClass();
  if (containingClass == null) {
    return;
  }
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(reference.getProject());
  final PsiJavaCodeReferenceElement newReferenceElement;
  if (reference instanceof PsiReferenceExpression) {
    newReferenceElement = factory.createReferenceExpression(containingClass);
  } else {
    newReferenceElement = factory.createClassReferenceElement(containingClass);
  }
  final PsiElement qualifier = reference.getQualifier();
  if (qualifier == null) {
    return;
  }
  qualifier.replace(newReferenceElement);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:InnerClassReferencedViaSubclassInspection.java

示例13: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor)
  throws IncorrectOperationException {
  final PsiElement leftBrace = descriptor.getPsiElement();
  final PsiElement parent = leftBrace.getParent();
  if (!(parent instanceof PsiCodeBlock)) {
    return;
  }
  final PsiCodeBlock block = (PsiCodeBlock)parent;
  final PsiBlockStatement blockStatement =
    (PsiBlockStatement)block.getParent();
  final PsiElement[] children = block.getChildren();
  if (children.length > 2) {
    final PsiElement element = blockStatement.getParent();
    element.addRangeBefore(children[1],
                           children[children.length - 2], blockStatement);
  }
  blockStatement.delete();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:UnnecessaryBlockStatementInspection.java

示例14: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PsiNewExpression newExpression =
    (PsiNewExpression)element.getParent();
  final PsiExpressionList argumentList =
    newExpression.getArgumentList();
  if (argumentList == null) {
    return;
  }
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length != 1) {
    return;
  }
  final PsiExpression argument = arguments[0];
  final String text = argument.getText();
  final String newArgument = '"' + StringUtil.escapeStringCharacters(StringUtil.stripQuotesAroundValue(text)) + '"';
  PsiReplacementUtil.replaceExpression(argument, newArgument);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:NewStringBufferWithCharArgumentInspection.java

示例15: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiElement castTypeElement = descriptor.getPsiElement();
  final PsiTypeCastExpression expression = (PsiTypeCastExpression)castTypeElement.getParent();
  if (expression == null) {
    return;
  }
  final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, true);
  if (expectedType == null) {
    return;
  }
  final PsiExpression operand = expression.getOperand();
  if (operand == null) {
    return;
  }
  @NonNls
  final String newExpression = '(' + expectedType.getCanonicalText() + ')' + operand.getText();
  PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:OverlyStrongTypeCastInspection.java


注:本文中的com.intellij.codeInspection.ProblemDescriptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。