use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class SuppressAllForClassFix method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final PsiElement element) throws IncorrectOperationException {
final PsiJavaDocumentedElement container = getContainer(element);
LOG.assertTrue(container != null);
if (use15Suppressions(container)) {
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
final PsiAnnotation annotation = modifierList.findAnnotation(JavaSuppressionUtil.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
if (annotation != null) {
String annoText = "@" + JavaSuppressionUtil.SUPPRESS_INSPECTIONS_ANNOTATION_NAME + "(\"" + SuppressionUtil.ALL + "\")";
Runnable runnable = () -> annotation.replace(JavaPsiFacade.getElementFactory(project).createAnnotationFromText(annoText, container));
WriteCommandAction.runWriteCommandAction(project, null, null, runnable, annotation.getContainingFile());
return;
}
}
} else {
PsiDocComment docComment = container.getDocComment();
if (docComment != null) {
PsiDocTag noInspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (noInspectionTag != null) {
String tagText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + SuppressionUtil.ALL;
Runnable runnable = () -> noInspectionTag.replace(JavaPsiFacade.getElementFactory(project).createDocTagFromText(tagText));
WriteCommandAction.runWriteCommandAction(project, null, null, runnable, noInspectionTag.getContainingFile());
//DaemonCodeAnalyzer.getInstance(project).restart();
return;
}
}
}
super.invoke(project, element);
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class SuppressFix method suppressByDocComment.
private void suppressByDocComment(@NotNull Project project, PsiJavaDocumentedElement container) {
PsiDocComment docComment = container.getDocComment();
PsiManager manager = PsiManager.getInstance(project);
if (docComment == null) {
String commentText = "/** @" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container) + "*/";
docComment = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocCommentFromText(commentText);
PsiElement firstChild = container.getFirstChild();
container.addBefore(docComment, firstChild);
} else {
PsiDocTag noInspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (noInspectionTag != null) {
String tagText = noInspectionTag.getText() + ", " + getID(container);
noInspectionTag.replace(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
} else {
String tagText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container);
docComment.add(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
}
}
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavaSafeDeleteProcessor method findParameterUsages.
private static void findParameterUsages(final PsiParameter parameter, final List<UsageInfo> usages) {
final PsiMethod method = (PsiMethod) parameter.getDeclarationScope();
final int parameterIndex = method.getParameterList().getParameterIndex(parameter);
//search for refs to current method only, do not search for refs to overriding methods, they'll be searched separately
ReferencesSearch.search(method).forEach(reference -> {
PsiElement element = reference.getElement();
if (element != null) {
final JavaSafeDeleteDelegate safeDeleteDelegate = JavaSafeDeleteDelegate.EP.forLanguage(element.getLanguage());
if (safeDeleteDelegate != null) {
safeDeleteDelegate.createUsageInfoForParameter(reference, usages, parameter, method);
}
if (!parameter.isVarArgs() && !RefactoringChangeUtil.isSuperMethodCall(element.getParent())) {
final PsiParameter paramInCaller = SafeDeleteJavaCallerChooser.isTheOnlyOneParameterUsage(element.getParent(), parameterIndex, method);
if (paramInCaller != null) {
final PsiMethod callerMethod = (PsiMethod) paramInCaller.getDeclarationScope();
if (ApplicationManager.getApplication().isUnitTestMode()) {
usages.add(new SafeDeleteParameterCallHierarchyUsageInfo(callerMethod, paramInCaller, callerMethod));
} else {
usages.add(new SafeDeleteParameterCallHierarchyUsageInfo(method, parameter, callerMethod));
}
}
}
}
return true;
});
ReferencesSearch.search(parameter).forEach(reference -> {
PsiElement element = reference.getElement();
final PsiDocTag docTag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
if (docTag != null) {
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(docTag, parameter, true));
return true;
}
boolean isSafeDelete = false;
if (element.getParent().getParent() instanceof PsiMethodCallExpression) {
PsiMethodCallExpression call = (PsiMethodCallExpression) element.getParent().getParent();
PsiReferenceExpression methodExpression = call.getMethodExpression();
if (methodExpression.getText().equals(PsiKeyword.SUPER)) {
isSafeDelete = true;
} else if (methodExpression.getQualifierExpression() instanceof PsiSuperExpression) {
final PsiMethod superMethod = call.resolveMethod();
if (superMethod != null && MethodSignatureUtil.isSuperMethod(superMethod, method)) {
isSafeDelete = true;
}
}
}
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, isSafeDelete));
return true;
});
findFunctionalExpressions(usages, method);
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class MakeMethodStaticProcessor method changeSelf.
protected void changeSelf(PsiElementFactory factory, UsageInfo[] usages) throws IncorrectOperationException {
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(myMember);
PsiParameterList paramList = myMember.getParameterList();
PsiElement addParameterAfter = null;
PsiDocTag anchor = null;
List<PsiType> addedTypes = new ArrayList<>();
final PsiClass containingClass = myMember.getContainingClass();
LOG.assertTrue(containingClass != null);
if (mySettings.isDelegate()) {
List<ParameterInfoImpl> params = new ArrayList<>();
PsiParameter[] parameters = myMember.getParameterList().getParameters();
if (mySettings.isMakeClassParameter()) {
params.add(new ParameterInfoImpl(-1, mySettings.getClassParameterName(), factory.createType(containingClass, PsiSubstitutor.EMPTY), "this"));
}
if (mySettings.isMakeFieldParameters()) {
for (Settings.FieldParameter parameter : mySettings.getParameterOrderList()) {
params.add(new ParameterInfoImpl(-1, mySettings.getClassParameterName(), parameter.type, parameter.field.getName()));
}
}
for (int i = 0; i < parameters.length; i++) {
params.add(new ParameterInfoImpl(i));
}
final PsiType returnType = myMember.getReturnType();
LOG.assertTrue(returnType != null);
JavaChangeSignatureUsageProcessor.generateDelegate(new JavaChangeInfoImpl(VisibilityUtil.getVisibilityModifier(myMember.getModifierList()), myMember, myMember.getName(), CanonicalTypes.createTypeWrapper(returnType), params.toArray(new ParameterInfoImpl[params.size()]), new ThrownExceptionInfo[0], false, Collections.<PsiMethod>emptySet(), Collections.<PsiMethod>emptySet()));
}
if (mySettings.isMakeClassParameter()) {
// Add parameter for object
PsiType parameterType = factory.createType(containingClass, PsiSubstitutor.EMPTY);
addedTypes.add(parameterType);
final String classParameterName = mySettings.getClassParameterName();
PsiParameter parameter = factory.createParameter(classParameterName, parameterType);
if (makeClassParameterFinal(usages)) {
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, true);
}
addParameterAfter = paramList.addAfter(parameter, null);
anchor = javaDocHelper.addParameterAfter(classParameterName, anchor);
}
if (mySettings.isMakeFieldParameters()) {
List<Settings.FieldParameter> parameters = mySettings.getParameterOrderList();
for (Settings.FieldParameter fieldParameter : parameters) {
final PsiType fieldParameterType = fieldParameter.field.getType();
final PsiParameter parameter = factory.createParameter(fieldParameter.name, fieldParameterType);
addedTypes.add(fieldParameterType);
if (makeFieldParameterFinal(fieldParameter.field, usages)) {
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, true);
}
addParameterAfter = paramList.addAfter(parameter, addParameterAfter);
anchor = javaDocHelper.addParameterAfter(fieldParameter.name, anchor);
}
}
makeStatic(myMember);
if (myAdditionalMethods != null) {
for (PsiMethod method : myAdditionalMethods) {
makeStatic(method);
}
}
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class MakeClassStaticProcessor method changeSelf.
protected void changeSelf(final PsiElementFactory factory, final UsageInfo[] usages) throws IncorrectOperationException {
PsiClass containingClass = myMember.getContainingClass();
//Add fields
if (mySettings.isMakeClassParameter()) {
PsiType type = factory.createType(containingClass, PsiSubstitutor.EMPTY);
final String classParameterName = mySettings.getClassParameterName();
final String fieldName = convertToFieldName(classParameterName);
myMember.add(factory.createField(fieldName, type));
}
if (mySettings.isMakeFieldParameters()) {
List<Settings.FieldParameter> parameters = mySettings.getParameterOrderList();
for (Settings.FieldParameter fieldParameter : parameters) {
final PsiType type = fieldParameter.type;
final PsiField field = factory.createField(convertToFieldName(fieldParameter.name), type);
myMember.add(field);
}
}
PsiMethod[] constructors = myMember.getConstructors();
if (constructors.length == 0) {
final PsiMethod defConstructor = (PsiMethod) myMember.add(factory.createConstructor());
constructors = new PsiMethod[] { defConstructor };
}
boolean generateFinalParams = CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS;
for (PsiMethod constructor : constructors) {
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(constructor);
PsiParameterList paramList = constructor.getParameterList();
PsiElement addParameterAfter = null;
PsiDocTag anchor = null;
if (mySettings.isMakeClassParameter()) {
// Add parameter for object
PsiType parameterType = factory.createType(containingClass, PsiSubstitutor.EMPTY);
final String classParameterName = mySettings.getClassParameterName();
PsiParameter parameter = factory.createParameter(classParameterName, parameterType);
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, makeClassParameterFinal(usages) || generateFinalParams);
addParameterAfter = paramList.addAfter(parameter, null);
anchor = javaDocHelper.addParameterAfter(classParameterName, anchor);
addAssignmentToField(classParameterName, constructor);
}
if (mySettings.isMakeFieldParameters()) {
List<Settings.FieldParameter> parameters = mySettings.getParameterOrderList();
for (Settings.FieldParameter fieldParameter : parameters) {
final PsiType fieldParameterType = fieldParameter.field.getType();
final PsiParameter parameter = factory.createParameter(fieldParameter.name, fieldParameterType);
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, makeFieldParameterFinal(fieldParameter.field, usages) || generateFinalParams);
addParameterAfter = paramList.addAfter(parameter, addParameterAfter);
anchor = javaDocHelper.addParameterAfter(fieldParameter.name, anchor);
addAssignmentToField(fieldParameter.name, constructor);
}
for (UsageInfo usage : usages) {
if (usage instanceof InternalUsageInfo) {
final PsiElement element = usage.getElement();
final PsiElement referencedElement = ((InternalUsageInfo) usage).getReferencedElement();
if (referencedElement instanceof PsiField && mySettings.getNameForField((PsiField) referencedElement) != null) {
final PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class);
if (field != null) {
MoveInstanceMembersUtil.moveInitializerToConstructor(factory, constructor, field);
}
}
}
}
}
for (PsiField field : myFieldsToSplit) {
MoveInstanceMembersUtil.moveInitializerToConstructor(factory, constructor, field);
}
}
setupTypeParameterList(myMember);
// Add static modifier
final PsiModifierList modifierList = myMember.getModifierList();
modifierList.setModifierProperty(PsiModifier.STATIC, true);
modifierList.setModifierProperty(PsiModifier.FINAL, false);
}
Aggregations