Search in sources :

Example 66 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class NavBarModelExtensionUtils method getPresentableText.

@Nullable
public static String getPresentableText(@Nullable final Object object) {
    if (object instanceof Project) {
        Project project = (Project) object;
        StudyNode root = StepikProjectManager.getProjectRoot(project);
        if (root == null) {
            return null;
        }
        return root.getName();
    }
    if (object instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) object;
        PresentationData data = new PresentationData();
        updatePresentationData(data, psiDirectory);
        String text = data.getPresentableText();
        if (text != null)
            return text;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) PresentationData(com.intellij.ide.projectView.PresentationData) PresentationDataUtils.updatePresentationData(org.stepik.plugin.utils.PresentationDataUtils.updatePresentationData) PsiDirectory(com.intellij.psi.PsiDirectory) StudyNode(org.stepik.core.courseFormat.StudyNode) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.

the class GroovyHotSwapper method handleSpacesInPath.

@Nullable
private static String handleSpacesInPath(String agentPath) {
    if (agentPath.contains(" ")) {
        final File dir = new File(PathManager.getSystemPath(), "groovyHotSwap");
        if (dir.getAbsolutePath().contains(" ")) {
            LOG.info("Groovy hot-swap not used since the agent path contains spaces: " + agentPath + "\n" + "One can move the agent to a directory with no spaces in path," + " and specify its path in <IDEA dist>/bin/idea.properties as " + GROOVY_HOTSWAP_AGENT_PATH + "=<path>");
            return null;
        }
        final File toFile = new File(dir, "gragent.jar");
        try {
            FileUtil.copy(new File(agentPath), toFile);
            return toFile.getPath();
        } catch (IOException e) {
            LOG.info(e);
        }
    }
    return agentPath;
}
Also used : IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 68 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.

the class GroovyPositionManager method findReferenceTypeSourceImage.

@Nullable
private static GroovyPsiElement findReferenceTypeSourceImage(SourcePosition position) {
    PsiFile file = position.getFile();
    if (!(file instanceof GroovyFileBase))
        return null;
    PsiElement element = file.findElementAt(position.getOffset());
    if (element == null)
        return null;
    return PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class);
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.

the class GroovyGenerateMethodMissingHandler method genMethod.

@Nullable
private static GrMethod genMethod(PsiClass aClass, FileTemplate template) {
    Properties properties = FileTemplateManager.getInstance(aClass.getProject()).getDefaultProperties();
    properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, "java.lang.Object");
    properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, "null");
    properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, "");
    String fqn = aClass.getQualifiedName();
    if (fqn != null)
        properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, fqn);
    String className = aClass.getName();
    if (className != null)
        properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, className);
    properties.setProperty(FileTemplate.ATTRIBUTE_METHOD_NAME, "methodMissing");
    String bodyText;
    try {
        bodyText = StringUtil.replace(template.getText(properties), ";", "");
    } catch (IOException e) {
        return null;
    }
    return GroovyPsiElementFactory.getInstance(aClass.getProject()).createMethodFromText("def methodMissing(String name, def args) {\n" + bodyText + "\n}");
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.

the class GroovyGeneratePropertyMissingHandler method chooseOriginalMembers.

@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true);
    PsiMethod getter = null;
    PsiMethod setter = null;
    for (PsiMethod missing : missings) {
        final PsiParameter[] parameters = missing.getParameterList().getParameters();
        if (parameters.length == 1) {
            if (isNameParam(parameters[0])) {
                getter = missing;
            }
        } else if (parameters.length == 2) {
            if (isNameParam(parameters[0])) {
                setter = missing;
            }
        }
    }
    if (setter != null && getter != null) {
        String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning");
        if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
            final PsiMethod finalGetter = getter;
            final PsiMethod finalSetter = setter;
            if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {

                @Override
                public Boolean compute() {
                    try {
                        finalSetter.delete();
                        finalGetter.delete();
                        return Boolean.TRUE;
                    } catch (IncorrectOperationException e) {
                        LOG.error(e);
                        return Boolean.FALSE;
                    }
                }
            }).booleanValue()) {
                return null;
            }
        } else {
            return null;
        }
    }
    return new ClassMember[1];
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4694 VirtualFile (com.intellij.openapi.vfs.VirtualFile)812 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)405 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)320 NotNull (org.jetbrains.annotations.NotNull)259 IOException (java.io.IOException)247 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)178 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)116 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)102 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 XmlFile (com.intellij.psi.xml.XmlFile)78