use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GetInvocation method invoke.
@Override
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable {
if (myConverter == Converter.EMPTY_CONVERTER) {
return getValueInner(handler, myConverter);
}
CachedValue<List<Pair<Converter, Object>>> value = handler.getUserData(DOM_VALUE_KEY);
if (value == null) {
final DomManagerImpl domManager = handler.getManager();
final Project project = domManager.getProject();
final CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(project);
handler.putUserData(DOM_VALUE_KEY, value = cachedValuesManager.createCachedValue(() -> {
List<Pair<Converter, Object>> list = ContainerUtil.createLockFreeCopyOnWriteList();
return CachedValueProvider.Result.create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, domManager, ProjectRootManager.getInstance(project));
}, false));
}
return getOrCalcValue(handler, value.getValue());
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GroovyDocumentationProvider method generateDocumentationContentStub.
@Override
public String generateDocumentationContentStub(PsiComment contextComment) {
if (!(contextComment instanceof GrDocComment)) {
return null;
}
final GrDocCommentOwner owner = GrDocCommentUtil.findDocOwner((GrDocComment) contextComment);
if (owner == null)
return null;
Project project = contextComment.getProject();
final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter) LanguageCommenters.INSTANCE.forLanguage(owner.getLanguage());
StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
if (owner instanceof GrMethod) {
final GrMethod method = (GrMethod) owner;
JavaDocumentationProvider.generateParametersTakingDocFromSuperMethods(project, builder, commenter, method);
final PsiType returnType = method.getInferredReturnType();
if ((returnType != null || method.getModifierList().hasModifierProperty(GrModifier.DEF)) && !PsiType.VOID.equals(returnType)) {
builder.append(CodeDocumentationUtil.createDocCommentLine(RETURN_TAG, project, commenter));
builder.append(LINE_SEPARATOR);
}
final PsiClassType[] references = method.getThrowsList().getReferencedTypes();
for (PsiClassType reference : references) {
builder.append(CodeDocumentationUtil.createDocCommentLine(THROWS_TAG, project, commenter));
builder.append(reference.getClassName());
builder.append(LINE_SEPARATOR);
}
} else if (owner instanceof GrTypeDefinition) {
final PsiTypeParameterList typeParameterList = ((PsiClass) owner).getTypeParameterList();
if (typeParameterList != null) {
JavaDocumentationProvider.createTypeParamsListComment(builder, project, commenter, typeParameterList);
}
}
return builder.length() > 0 ? builder.toString() : null;
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GroovyRefactoringUtil method createTempVar.
public static String createTempVar(GrExpression expr, final GroovyPsiElement context, boolean declareFinal) {
expr = addBlockIntoParent(expr);
final GrVariableDeclarationOwner block = PsiTreeUtil.getParentOfType(expr, GrVariableDeclarationOwner.class);
LOG.assertTrue(block != null);
final PsiElement anchorStatement = PsiTreeUtil.findPrevParent(block, expr);
LOG.assertTrue(anchorStatement instanceof GrStatement);
Project project = expr.getProject();
String[] suggestedNames = GroovyNameSuggestionUtil.suggestVariableNames(expr, new NameValidator() {
@Override
public String validateName(String name, boolean increaseNumber) {
return name;
}
@Override
public Project getProject() {
return context.getProject();
}
});
/*
JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expr, null).names;*/
final String prefix = suggestedNames[0];
final String id = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(prefix, context, true);
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(expr.getProject());
String[] modifiers;
if (declareFinal) {
modifiers = finalModifiers;
} else {
modifiers = ArrayUtil.EMPTY_STRING_ARRAY;
}
GrVariableDeclaration decl = factory.createVariableDeclaration(modifiers, (GrExpression) org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.skipParentheses(expr, false), expr.getType(), id);
/* if (declareFinal) {
com.intellij.psi.util.PsiUtil.setModifierProperty((decl.getMembers()[0]), PsiModifier.FINAL, true);
}*/
final GrStatement statement = ((GrStatementOwner) anchorStatement.getParent()).addStatementBefore(decl, (GrStatement) anchorStatement);
JavaCodeStyleManager.getInstance(statement.getProject()).shortenClassReferences(statement);
return id;
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class ArgumentListGenerator method generate.
public void generate(@Nullable GrClosureSignature signature, @NotNull GrExpression[] exprs, @NotNull GrNamedArgument[] namedArgs, @NotNull GrClosableBlock[] clArgs, @NotNull GroovyPsiElement context) {
GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = signature == null ? null : GrClosureSignatureUtil.mapParametersToArguments(signature, namedArgs, exprs, clArgs, context, false, false);
if (argInfos == null && signature != null) {
argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, namedArgs, exprs, clArgs, context, true, true);
}
final PsiSubstitutor substitutor = signature == null ? PsiSubstitutor.EMPTY : signature.getSubstitutor();
if (argInfos == null || NullUtils.hasNull(argInfos)) {
generateSimple(exprs, namedArgs, clArgs, context, substitutor);
return;
}
final GrClosureParameter[] params = signature.getParameters();
final Project project = context.getProject();
myBuilder.append('(');
boolean hasCommaAtEnd = false;
for (int i = 0; i < argInfos.length; i++) {
GrClosureSignatureUtil.ArgInfo<PsiElement> arg = argInfos[i];
if (arg == null)
continue;
final GrClosureParameter param = params[i];
boolean generated = arg.isMultiArg ? generateMultiArg(arg, param, substitutor, project, context) : generateSingeArg(arg, param);
if (generated) {
hasCommaAtEnd = true;
myBuilder.append(", ");
}
}
if (hasCommaAtEnd) {
myBuilder.delete(myBuilder.length() - 2, myBuilder.length());
//myBuilder.removeFromTheEnd(2);
}
myBuilder.append(')');
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class JavaI18nizeQuickFixDialog method isAvailable.
public static boolean isAvailable(PsiFile file) {
final Project project = file.getProject();
final String title = CodeInsightBundle.message("i18nize.dialog.error.jdk.title");
try {
return ResourceBundleManager.getManager(file) != null;
} catch (ResourceBundleManager.ResourceBundleNotFoundException e) {
final IntentionAction fix = e.getFix();
if (fix != null) {
if (Messages.showOkCancelDialog(project, e.getMessage(), title, Messages.getErrorIcon()) == Messages.OK) {
try {
fix.invoke(project, null, file);
return false;
} catch (IncorrectOperationException e1) {
LOG.error(e1);
}
}
}
Messages.showErrorDialog(project, e.getMessage(), title);
return false;
}
}
Aggregations