Example usage for com.intellij.openapi.fileTypes StdFileTypes CLASS

List of usage examples for com.intellij.openapi.fileTypes StdFileTypes CLASS

Introduction

In this page you can find the example usage for com.intellij.openapi.fileTypes StdFileTypes CLASS.

Prototype

FileType CLASS

To view the source code for com.intellij.openapi.fileTypes StdFileTypes CLASS.

Click Source Link

Usage

From source file:com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.java

License:Apache License

/**
 * We can only place a cloud breakpoint on a line if: 1) Its normally ok to do so with a java
 * breakpoint. 2) The selected run config is a {@link CloudDebugRunConfiguration}.
 *//*  www  .  j  a  v  a 2  s. co  m*/
@Override
public final boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) {
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
    if (runManager.getSelectedConfiguration() == null || !(runManager.getSelectedConfiguration()
            .getConfiguration() instanceof CloudDebugRunConfiguration)) {
        return false;
    }

    // Most of this code is reused from java linebreakpoint.
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null || psiFile.getVirtualFile().getFileType() == StdFileTypes.XHTML) {
        return false;
    }

    if (!StdFileTypes.CLASS.equals(psiFile.getFileType()) && !DebuggerUtils.isBreakpointAware(psiFile)) {
        return false;
    }

    final Document document = FileDocumentManager.getInstance().getDocument(file);
    final Ref<Class<? extends CloudLineBreakpointType>> result = Ref.create();
    assert document != null;
    XDebuggerUtil.getInstance().iterateLine(project, document, line, new Processor<PsiElement>() {
        @Override
        public boolean process(PsiElement element) {
            // avoid comments
            if ((element instanceof PsiWhiteSpace)
                    || (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null)) {
                return true;
            }
            PsiElement parent = element;
            while (element != null) {
                // skip modifiers
                if (element instanceof PsiModifierList) {
                    element = element.getParent();
                    continue;
                }

                final int offset = element.getTextOffset();
                if (offset >= 0) {
                    if (document.getLineNumber(offset) != line) {
                        break;
                    }
                }
                parent = element;
                element = element.getParent();
            }

            if (parent instanceof PsiMethod) {
                if (parent.getTextRange().getEndOffset() >= document.getLineEndOffset(line)) {
                    PsiCodeBlock body = ((PsiMethod) parent).getBody();
                    if (body != null) {
                        PsiStatement[] statements = body.getStatements();
                        if (statements.length > 0
                                && document.getLineNumber(statements[0].getTextOffset()) == line) {
                            result.set(CloudLineBreakpointType.class);
                        }
                    }
                }
            } else {
                result.set(CloudLineBreakpointType.class);
            }
            return true;
        }
    });

    UsageTrackerProvider.getInstance().trackEvent(GctTracking.CLOUD_DEBUGGER_CREATE_BREAKPOINT).ping();
    return result.get() == getClass();
}

From source file:com.google.gct.idea.debugger.CloudLineBreakpointType.java

License:Apache License

/**
 * We can only place a cloud breakpoint on a line if: 1) Its normally ok to do so with a java breakpoint. 2) The
 * selected run config is a {@link CloudDebugRunConfiguration}.
 *//*ww  w.  j a  va2s.  c  o m*/
@Override
public final boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) {
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
    if (runManager.getSelectedConfiguration() == null || !(runManager.getSelectedConfiguration()
            .getConfiguration() instanceof CloudDebugRunConfiguration)) {
        return false;
    }

    // Most of this code is reused from java linebreakpoint.
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null || psiFile.getVirtualFile().getFileType() == StdFileTypes.XHTML) {
        return false;
    }

    if (!StdFileTypes.CLASS.equals(psiFile.getFileType()) && !DebuggerUtils.isBreakpointAware(psiFile)) {
        return false;
    }

    final Document document = FileDocumentManager.getInstance().getDocument(file);
    final Ref<Class<? extends CloudLineBreakpointType>> result = Ref.create();
    assert document != null;
    XDebuggerUtil.getInstance().iterateLine(project, document, line, new Processor<PsiElement>() {
        @Override
        public boolean process(PsiElement element) {
            // avoid comments
            if ((element instanceof PsiWhiteSpace)
                    || (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null)) {
                return true;
            }
            PsiElement parent = element;
            while (element != null) {
                // skip modifiers
                if (element instanceof PsiModifierList) {
                    element = element.getParent();
                    continue;
                }

                final int offset = element.getTextOffset();
                if (offset >= 0) {
                    if (document.getLineNumber(offset) != line) {
                        break;
                    }
                }
                parent = element;
                element = element.getParent();
            }

            if (parent instanceof PsiMethod) {
                if (parent.getTextRange().getEndOffset() >= document.getLineEndOffset(line)) {
                    PsiCodeBlock body = ((PsiMethod) parent).getBody();
                    if (body != null) {
                        PsiStatement[] statements = body.getStatements();
                        if (statements.length > 0
                                && document.getLineNumber(statements[0].getTextOffset()) == line) {
                            result.set(CloudLineBreakpointType.class);
                        }
                    }
                }
            } else {
                result.set(CloudLineBreakpointType.class);
            }
            return true;
        }
    });
    return result.get() == getClass();
}

From source file:org.jetbrains.jet.plugin.compiler.JetCompilerManager.java

License:Apache License

public JetCompilerManager(CompilerManager manager) {
    manager.addTranslatingCompiler(new JetCompiler(), Collections.<FileType>singleton(JetFileType.INSTANCE),
            Collections.singleton(StdFileTypes.CLASS));
    manager.addTranslatingCompiler(new K2JSCompiler(), Collections.<FileType>singleton(JetFileType.INSTANCE),
            Collections.<FileType>singleton(StdFileTypes.JS));
    manager.addCompilableFileType(JetFileType.INSTANCE);
}

From source file:org.jetbrains.jet.plugin.libraries.DecompiledUtils.java

License:Apache License

public static boolean isKotlinCompiledFile(@NotNull Project project, @NotNull VirtualFile file) {
    if (!StdFileTypes.CLASS.getDefaultExtension().equals(file.getExtension())) {
        return false;
    }//from  ww w  .j  a  v a  2 s  .  c  o m
    //TODO: check index
    KotlinJvmBinaryClass kotlinClass = VirtualFileFinder.SERVICE.getInstance(project).createKotlinClass(file);
    KotlinClassHeader header = kotlinClass.getClassHeader();
    return header != null && header.getAnnotationData() != null;
}

From source file:org.jetbrains.jet.plugin.stubindex.builder.EmptyPackageFragmentClsStubBuilderFactory.java

License:Apache License

@Override
public boolean canBeProcessed(VirtualFile file, byte[] bytes) {
    if (file.getName().contains(PackageClassUtils.PACKAGE_CLASS_NAME_SUFFIX + "-")
            && StdFileTypes.CLASS.getDefaultExtension().equals(file.getExtension())) {
        KotlinClassHeader header = new VirtualFileKotlinClass(LockBasedStorageManager.NO_LOCKS, file)
                .getClassHeader();/*  w  w  w  . j  a v a  2 s. c o m*/
        return header != null && header.getKind() == KotlinClassHeader.Kind.PACKAGE_PART;
    }
    return false;
}

From source file:org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope.java

License:Apache License

@Override
public boolean contains(final VirtualFile file) {
    if (!super.contains(file)) {
        return false;
    }/*from  w w  w.  j  av  a  2 s .  c  o  m*/

    if (StdFileTypes.CLASS == file.getFileType()) {
        return myIndex.isInLibraryClasses(file);
    }

    return file.getFileType().equals(JetFileType.INSTANCE)
            && (myIndex.isInSourceContent(file) || myIndex.isInLibrarySource(file));
}