Example usage for org.springframework.ide.eclipse.core.model ISourceModelElement getElementStartLine

List of usage examples for org.springframework.ide.eclipse.core.model ISourceModelElement getElementStartLine

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.core.model ISourceModelElement getElementStartLine.

Prototype

int getElementStartLine();

Source Link

Document

Returns the line number with the start of the element's source code.

Usage

From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java

@Override
protected void readConfig() {
    if (!isModelPopulated) {

        w.lock();//from   w  w  w .ja  v  a  2s .  c  o  m
        if (this.isModelPopulated) {
            w.unlock();
            return;
        }

        try {
            if (this.configClass == null) {
                return;
            }

            IBeansProject beansProject = BeansModelUtils.getParentOfClass(this, IBeansProject.class);
            if (beansProject == null) {
                return;
            }

            final ClassLoader cl = JdtUtils.getClassLoader(beansProject.getProject(),
                    ApplicationContext.class.getClassLoader());

            if (cl.getResource(this.configClass.getFullyQualifiedName().replace('.', '/') + ".class") == null) {
                return;
            }

            Callable<Integer> loadBeanDefinitionOperation = new Callable<Integer>() {
                public Integer call() throws Exception {
                    // Obtain thread context classloader and override with the project classloader
                    ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(cl);

                    // Create special ReaderEventListener that essentially just passes through component definitions
                    ReaderEventListener eventListener = new BeansConfigPostProcessorReaderEventListener();
                    problemReporter = new BeansConfigProblemReporter();
                    beanNameGenerator = new UniqueBeanNameGenerator(BeansJavaConfig.this);
                    registry = new ScannedGenericBeanDefinitionSuppressingBeanDefinitionRegistry();

                    try {
                        registerAnnotationProcessors(eventListener);
                        registerBean(eventListener, cl);

                        IBeansConfigPostProcessor[] postProcessors = BeansConfigPostProcessorFactory
                                .createPostProcessor(ConfigurationClassPostProcessor.class.getName());
                        for (IBeansConfigPostProcessor postProcessor : postProcessors) {
                            executePostProcessor(postProcessor, eventListener);
                        }
                    } finally {
                        // Reset the context classloader
                        Thread.currentThread().setContextClassLoader(threadClassLoader);
                        LogFactory.release(cl); //Otherwise permgen leak?
                    }
                    return 0;
                }
            };

            FutureTask<Integer> task = new FutureTask<Integer>(loadBeanDefinitionOperation);
            BeansCorePlugin.getExecutorService().submit(task);
            task.get(BeansCorePlugin.getDefault().getPreferenceStore()
                    .getInt(BeansCorePlugin.TIMEOUT_CONFIG_LOADING_PREFERENCE_ID), TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR,
                    "Loading of configuration '" + this.configClass.getFullyQualifiedName()
                            + "' took more than "
                            + BeansCorePlugin.getDefault().getPreferenceStore()
                                    .getInt(BeansCorePlugin.TIMEOUT_CONFIG_LOADING_PREFERENCE_ID)
                            + "sec",
                    file, 1));
        } catch (Exception e) {
            problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR,
                    String.format("Error occured processing Java config '%s'. See Error Log for more details",
                            e.getCause().getMessage()),
                    getElementResource()));
            BeansCorePlugin.log(new Status(IStatus.INFO, BeansCorePlugin.PLUGIN_ID,
                    String.format("Error occured processing '%s'", this.configClass.getFullyQualifiedName()),
                    e.getCause()));
        } finally {
            // Prepare the internal cache of all children for faster access
            List<ISourceModelElement> allChildren = new ArrayList<ISourceModelElement>(imports);
            allChildren.addAll(aliases.values());
            allChildren.addAll(components);
            allChildren.addAll(beans.values());
            Collections.sort(allChildren, new Comparator<ISourceModelElement>() {
                public int compare(ISourceModelElement element1, ISourceModelElement element2) {
                    return element1.getElementStartLine() - element2.getElementStartLine();
                }
            });
            this.children = allChildren.toArray(new IModelElement[allChildren.size()]);

            this.isModelPopulated = true;
            w.unlock();
        }

    }
}