Search in sources :

Example 61 with Project

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());
}
Also used : Project(com.intellij.openapi.project.Project) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) List(java.util.List) Pair(com.intellij.openapi.util.Pair)

Example 62 with Project

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) CodeDocumentationAwareCommenter(com.intellij.lang.CodeDocumentationAwareCommenter) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Example 63 with Project

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;
}
Also used : Project(com.intellij.openapi.project.Project) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) GrVariableDeclarationOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrVariableDeclarationOwner) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 64 with Project

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(')');
}
Also used : GrClosureSignatureUtil(org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil) Project(com.intellij.openapi.project.Project) GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 65 with Project

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;
    }
}
Also used : Project(com.intellij.openapi.project.Project) ResourceBundleManager(com.intellij.lang.properties.psi.ResourceBundleManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90