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


Java ProblemDescriptor.getPsiElement方法代碼示例

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


在下文中一共展示了ProblemDescriptor.getPsiElement方法的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: 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

示例5: applyFix

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

  PyArgumentList argumentList = PsiTreeUtil.getParentOfType(element, PyArgumentList.class);
  if (argumentList == null) return;
  StringBuilder newArgumentList = new StringBuilder("foo(");

  PyExpression[] arguments = argumentList.getArguments();
  List<String> newArgs = new ArrayList<String>();
  for (int i = 0; i != arguments.length; ++i) {
    if (!myProblemElements.contains(arguments[i])) {
      newArgs.add(arguments[i].getText());
    }
  }

  newArgumentList.append(StringUtil.join(newArgs, ", ")).append(")");
  PyExpression expression = PyElementGenerator.getInstance(project).createFromText(
    LanguageLevel.forElement(argumentList), PyExpressionStatement.class, newArgumentList.toString()).getExpression();
  if (expression instanceof PyCallExpression)
    argumentList.replace(((PyCallExpression)expression).getArgumentList());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:RemoveArgumentEqualDefaultQuickFix.java

示例6: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project,
                     @NotNull ProblemDescriptor descriptor) {
  final PsiElement problemElement = descriptor.getPsiElement();
  if (problemElement == null || !problemElement.isValid()) {
    return;
  }
  if (isQuickFixOnReadOnlyFile(problemElement)) {
    return;
  }
  try {
    doFix(project, descriptor);
  } catch (IncorrectOperationException e) {
    final Class<? extends GroovyFix> aClass = getClass();
    final String className = aClass.getName();
    final Logger logger = Logger.getInstance(className);
    logger.error(e);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:GroovyFix.java

示例7: applyFix

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

    PsiElement context = item.getContext();
    if (context instanceof ArrayCreationExpression) {
        ArrayCreationExpression params = (ArrayCreationExpression) item.getParent();

        PsiUtil.deleteArrayElement(item);

        if (!params.getHashElements().iterator().hasNext()) {
            if (params.getPrevSibling() instanceof PsiWhiteSpace) {
                params.getPrevSibling().delete();
            }
            params.getPrevSibling().delete();
            params.delete();
        }
    }
    if (context instanceof ParameterList && context.getParent() instanceof FunctionReference) {
        FunctionReference functionReference = (FunctionReference) context.getParent();
        if (functionReference.getName() != null && functionReference.getName().equals("compact")) {
            PsiUtil.deleteFunctionParam(item);

            if (functionReference.getParameters().length == 0) {
                PsiUtil.deleteFunctionParam(functionReference);
            }
        }
    }
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:30,代碼來源:UnusedParameterLocalQuickFix.java

示例8: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement expression = descriptor.getPsiElement();
    if (null != expression && expression.getParent() instanceof ArrayCreationExpression) {
        final ArrayCreationExpression container = (ArrayCreationExpression) expression.getParent();
        final PsiElement closingBracket         = container.getLastChild();
        if (null == closingBracket) {
            return;
        }

        for (String translation : missing) {
            /* reach or create a comma */
            PsiElement last = closingBracket.getPrevSibling();
            if (last instanceof PsiWhiteSpace) {
                last = last.getPrevSibling();
            }
            if (null != last && PhpTokenTypes.opCOMMA != last.getNode().getElementType()) {
                last.getParent().addAfter(PhpPsiElementFactory.createComma(project), last);
                last = last.getNextSibling();
            }

            /* add a new translation */
            final String escaped                = PhpStringUtil.escapeText(translation, true, '\n', '\t');
            final String pairPattern            = "array('%s%' => '%s%')".replace("%s%", escaped).replace("%s%", escaped);
            final ArrayCreationExpression array = PhpPsiElementFactory.createFromText(project, ArrayCreationExpression.class, pairPattern);
            final PhpPsiElement pair            = null == array ? null : array.getHashElements().iterator().next();
            final PsiWhiteSpace space           = PhpPsiElementFactory.createFromText(project, PsiWhiteSpace.class, " ");
            if (null == last || null == pair || null == space) {
                continue;
            }
            last.getParent().addAfter(pair, last);
            last.getParent().addAfter(space, last);
        }
    }
}
 
開發者ID:kalessil,項目名稱:yii2inspections,代碼行數:36,代碼來源:MissingTranslationsInspector.java

示例9: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor)
{
    PsiElement problemElement = problemDescriptor.getPsiElement();
    PsiElement parent = getParentProperty(problemElement);

    // If there are still other settings present, just remove this one.
    if (childCount(parent) > 1)
    {
        problemElement.delete();

        CodeStyleManager
            .getInstance(project)
            .adjustLineIndent(parent.getContainingFile(), parent.getTextRange());

        return;
    }

    // Navigate upwards until a node containing more than one setting is found.
    while (true)
    {
        PsiElement nextParent = getParentProperty(parent);

        if (nextParent == null || childCount(nextParent) != 1)
        {
            // Remove entire unused tree.
            parent.delete();
            return;
        }

        parent = nextParent;
    }
}
 
開發者ID:whitefire,項目名稱:roc-completion,代碼行數:34,代碼來源:QuickFix.java

示例10: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  PsiElement element = descriptor.getPsiElement();
  if (!LanguageLevel.forElement(element).isPy3K() && element instanceof PyDictCompExpression) {
    replaceComprehension(project, (PyDictCompExpression)element);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:ConvertDictCompQuickFix.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 PsiElementFactory factory =
    JavaPsiFacade.getElementFactory(project);
  final PsiExpression newExpression =
    factory.createExpressionFromText(
      "new java.lang.NullPointerException()", element);
  element.replace(newExpression);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:NullThrownInspection.java

示例12: applyFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
  try {
    final XmlTag tag = (XmlTag)descriptor.getPsiElement();
    if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement().getContainingFile())) return;
    final XmlAttribute attribute = tag.setAttribute(myAttrName, myNamespace, "");
    new OpenFileDescriptor(project, tag.getContainingFile().getVirtualFile(),
                           attribute.getValueElement().getTextRange().getStartOffset() + 1).navigate(true);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:DefineAttributeQuickFix.java

示例13: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiElement element = descriptor.getPsiElement();
  final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(element, PsiAnnotation.class);
  if (annotation == null) {
    return;
  }
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final String annotationText = buildAnnotationText(annotation);
  final PsiAnnotation newAnnotation = factory.createAnnotationFromText(annotationText, element);
  annotation.replace(newAnnotation);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:SimplifiableAnnotationInspection.java

示例14: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiElement element = descriptor.getPsiElement();
  final PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(element, PsiTryStatement.class);
  if (tryStatement == null) {
    return;
  }
  final PsiResourceList resources = tryStatement.getResourceList();
  if (resources != null) {
    return;
  }
  final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
  if (tryBlock == null) {
    return;
  }
  final PsiElement parent = tryStatement.getParent();
  if (parent == null) {
    return;
  }

  final PsiElement first = tryBlock.getFirstBodyElement();
  final PsiElement last = tryBlock.getLastBodyElement();
  if (first != null && last != null) {
    parent.addRangeAfter(first, last, tryStatement);
  }

  tryStatement.delete();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:29,代碼來源:EmptyFinallyBlockInspection.java

示例15: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PsiMethod method = (PsiMethod)element.getParent();
  final PsiParameterList parameterList = method.getParameterList();
  final PsiParameter[] parameters = parameterList.getParameters();
  final PsiParameter lastParameter = parameters[parameters.length - 1];
  if (!lastParameter.isVarArgs()) {
    return;
  }
  final PsiEllipsisType type = (PsiEllipsisType)lastParameter.getType();
  final Query<PsiReference> query = ReferencesSearch.search(method);
  final PsiType componentType = type.getComponentType();
  final String typeText;
  if (componentType instanceof PsiClassType) {
    final PsiClassType classType = (PsiClassType)componentType;
    typeText = classType.rawType().getCanonicalText();
  } else {
    typeText = componentType.getCanonicalText();
  }
  final Collection<PsiReference> references = query.findAll();
  for (PsiReference reference : references) {
    modifyCalls(reference, typeText, parameters.length - 1);
  }
  final PsiType arrayType = type.toArrayType();
  final PsiManager psiManager = lastParameter.getManager();
  final PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
  final PsiTypeElement newTypeElement = factory.createTypeElement(arrayType);
  final PsiTypeElement typeElement = lastParameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, "java.lang.SafeVarargs");
  if (annotation != null) {
    annotation.delete();
  }
  typeElement.replace(newTypeElement);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:39,代碼來源:VarargParameterInspection.java


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