本文整理匯總了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();
}
}
示例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);
}
}
}
}
}
示例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();
}
}
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}