Search in sources :

Example 56 with Project

use of com.intellij.openapi.project.Project in project Main by SpartanRefactoring.

the class SpartanizerAnnotator method annotate.

@Override
public void annotate(@NotNull final PsiElement e, @NotNull AnnotationHolder h) {
    try {
        if (!Spartanizer.canTip(e) || e.getContainingFile().getName().contains("Spartanizer"))
            return;
        Annotation annotation = h.createInfoAnnotation(e, "Spartanize This!");
        annotation.registerFix(new IntentionAction() {

            @SuppressWarnings("unchecked")
            @Nls
            @NotNull
            @Override
            public String getText() {
                return Toolbox.getInstance().getTipper(e).description(e);
            }

            @Nls
            @NotNull
            @Override
            public String getFamilyName() {
                return "SpartanizerAction";
            }

            @Override
            public boolean isAvailable(@NotNull Project __, Editor e, PsiFile f) {
                return true;
            }

            @Override
            public void invoke(@NotNull Project p, Editor ed, PsiFile f) throws IncorrectOperationException {
                Spartanizer.spartanizeElement(e);
            }

            @Override
            public boolean startInWriteAction() {
                return false;
            }
        });
        TextAttributesKey.createTextAttributesKey("");
        annotation.setEnforcedTextAttributes((new TextAttributes(null, null, JBColor.BLUE, EffectType.WAVE_UNDERSCORE, 0)));
    } catch (Throwable t) {
        Logger l = new Logger(this.getClass());
        l.error("", t);
    }
}
Also used : Logger(il.org.spartan.Leonidas.plugin.utils.logging.Logger) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) Nls(org.jetbrains.annotations.Nls) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor)

Example 57 with Project

use of com.intellij.openapi.project.Project in project kotlin by JetBrains.

the class KotlinTestNgConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    // TODO: check TestNG Pattern running first, before method/class (see TestNGInClassConfigurationProducer for logic)
    // TODO: and PsiClassOwner not handled, which is in TestNGInClassConfigurationProducer
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    Project project = context.getProject();
    PsiElement leaf = location.getPsiElement();
    if (!ProjectRootsUtil.isInProjectOrLibSource(leaf)) {
        return false;
    }
    if (!(leaf.getContainingFile() instanceof KtFile)) {
        return false;
    }
    KtFile ktFile = (KtFile) leaf.getContainingFile();
    if (TargetPlatformDetector.getPlatform(ktFile) != JvmPlatform.INSTANCE) {
        return false;
    }
    KtNamedDeclaration declarationToRun = getDeclarationToRun(leaf);
    if (declarationToRun instanceof KtNamedFunction) {
        KtNamedFunction function = (KtNamedFunction) declarationToRun;
        @SuppressWarnings("unchecked") KtElement owner = PsiTreeUtil.getParentOfType(function, KtFunction.class, KtClass.class);
        if (owner instanceof KtClass) {
            PsiClass delegate = toLightClass((KtClass) owner);
            if (delegate != null) {
                for (PsiMethod method : delegate.getMethods()) {
                    if (method.getNavigationElement() == function) {
                        if (TestNGUtil.hasTest(method)) {
                            return configure(configuration, location, context, project, delegate, method);
                        }
                        break;
                    }
                }
            }
        }
    }
    if (declarationToRun instanceof KtClass) {
        PsiClass delegate = toLightClass((KtClassOrObject) declarationToRun);
        if (!isTestNGClass(delegate)) {
            return false;
        }
        return configure(configuration, location, context, project, delegate, null);
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 58 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class DomDescriptorProvider method getDescriptor.

@Override
@Nullable
public XmlElementDescriptor getDescriptor(final XmlTag tag) {
    Project project = tag.getProject();
    if (project.isDefault())
        return null;
    final DomInvocationHandler<?, ?> handler = DomManagerImpl.getDomManager(project).getDomHandler(tag);
    if (handler != null) {
        final DefinesXml definesXml = handler.getAnnotation(DefinesXml.class);
        if (definesXml != null) {
            return new DomElementXmlDescriptor(handler);
        }
        final PsiElement parent = tag.getParent();
        if (parent instanceof XmlTag) {
            final XmlElementDescriptor descriptor = ((XmlTag) parent).getDescriptor();
            if (descriptor instanceof DomElementXmlDescriptor) {
                return descriptor.getElementDescriptor(tag, (XmlTag) parent);
            }
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) DomElementXmlDescriptor(com.intellij.xml.impl.dom.DomElementXmlDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) DefinesXml(com.intellij.util.xml.DefinesXml) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class DynamicGenericInfo method runDomExtenders.

@Nullable
private DomExtensionsRegistrarImpl runDomExtenders() {
    DomExtensionsRegistrarImpl registrar = null;
    final Project project = myInvocationHandler.getManager().getProject();
    DomExtenderEP[] extenders = Extensions.getExtensions(DomExtenderEP.EP_NAME);
    if (extenders.length > 0) {
        for (final DomExtenderEP extenderEP : extenders) {
            registrar = extenderEP.extend(project, myInvocationHandler, registrar);
        }
    }
    final AbstractDomChildDescriptionImpl description = myInvocationHandler.getChildDescription();
    if (description != null) {
        final List<DomExtender> extendersFromParent = description.getUserData(DomExtensionImpl.DOM_EXTENDER_KEY);
        if (extendersFromParent != null) {
            if (registrar == null)
                registrar = new DomExtensionsRegistrarImpl();
            for (final DomExtender extender : extendersFromParent) {
                //noinspection unchecked
                extender.registerExtensions(myInvocationHandler.getProxy(), registrar);
            }
        }
    }
    return registrar;
}
Also used : Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class EditorTextFieldControl method createMainComponent.

@Override
protected T createMainComponent(T boundedComponent) {
    final Project project = getProject();
    boundedComponent = createMainComponent(boundedComponent, project);
    final EditorTextField editorTextField = getEditorTextField(boundedComponent);
    editorTextField.setSupplementary(true);
    editorTextField.getDocument().addDocumentListener(myListener);
    return boundedComponent;
}
Also used : Project(com.intellij.openapi.project.Project) EditorTextField(com.intellij.ui.EditorTextField)

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