Example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

List of usage examples for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Prototype

int COMPILATION_UNIT

To view the source code for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Click Source Link

Document

Constant representing a Java compilation unit.

Usage

From source file:org.mobicents.eclipslee.servicecreation.wizards.generic.FilenamePage.java

License:Apache License

/**
 * Tests if the current workbench selection is a suitable
 * container to use./*from ww w.  j  a v  a2s.c  om*/
 */

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {

        IJavaElement element = getInitialJavaElement((IStructuredSelection) selection);
        IPackageFragmentRoot initialRoot;
        initialRoot = JavaModelUtil.getPackageFragmentRoot(element);
        if (initialRoot == null || initialRoot.isArchive()) {
            IJavaProject javaProject = element.getJavaProject();
            if (javaProject != null) {
                try {
                    initialRoot = null;
                    if (javaProject.exists()) {
                        IPackageFragmentRoot roots[] = javaProject.getPackageFragmentRoots();
                        for (int i = 0; i < roots.length; i++) {
                            if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
                                initialRoot = roots[i];
                                break;
                            }
                        }
                    }
                } catch (JavaModelException e) {
                    ServiceCreationPlugin.log("JavaModelException determining project root.");
                }
                if (initialRoot == null) {
                    initialRoot = javaProject.getPackageFragmentRoot(javaProject.getResource());
                }
            }
        }

        try {
            setSourceContainer((IFolder) initialRoot.getCorrespondingResource());
        } catch (JavaModelException e) {
            ServiceCreationPlugin.log("JavaModelException thrown setting source container on FilenamePage");
        }

        //         // Initialize the maven module dialog
        //         mavenModuleText.setText(mavenModule);

        // Initialize the filename dialog
        fileText.setText("__Replace_Me__" + ends);

        if (element != null && element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
            IPackageFragment fragment = (IPackageFragment) element;
            setPackage(fragment);
            return;
        }

        if (element != null && element.getElementType() == IJavaElement.COMPILATION_UNIT) {
            ICompilationUnit unit = (ICompilationUnit) element;
            IPackageFragment fragment = (IPackageFragment) unit.getParent();
            setPackage(fragment);
            return;
        }

        setPackage(null);
    }

}

From source file:org.nuxeo.ide.sdk.deploy.Deployment.java

License:Open Source License

protected void copyPackageRoot(Set<String> commands, IPackageFragmentRoot root) throws Exception {
    for (IJavaElement child : root.getChildren()) {
        switch (child.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
            copyPackageFragment(commands, root, (IPackageFragment) child);
            break;
        case IJavaElement.COMPILATION_UNIT:
            copyCompilationUnit(commands, root, (ICompilationUnit) child);
            break;
        }//from  w  ww  .ja v  a2  s.  c  o  m
    }
    root.getNonJavaResources();
}

From source file:org.nuxeo.ide.sdk.java.ProjectDeployer.java

License:Open Source License

protected void copyRoot(IPackageFragmentRoot root, IProgressMonitor monitor) throws CoreException {
    for (IJavaElement child : root.getChildren()) {
        switch (child.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
            moveSeamPackageFragment(root, (IPackageFragment) child, monitor);
            break;
        case IJavaElement.COMPILATION_UNIT:
            moveSeamCompilationUnit(root, (ICompilationUnit) child, monitor);
            break;
        }//  w ww  . j a  v a 2 s . c  o m
    }
    //        int rootLength = root.getPath().segmentCount();
    //        char[][] exclusionChars = ((ClasspathEntry) root.getRawClasspathEntry()).fullExclusionPatternChars();
    //        char[][] inclusionChars = ((ClasspathEntry) root.getRawClasspathEntry()).fullInclusionPatternChars();
    //        for (Object object : root.getNonJavaResources()) {
    //            if (object instanceof IResource) {
    //                IResource resource = (IResource)object;
    //                if (org.eclipse.jdt.internal.core.util.Util.isExcluded(resource.getFullPath(), inclusionChars, exclusionChars, false)) {
    //                    continue;
    //                }
    //                IPath path = resource.getFullPath().removeFirstSegments(rootLength);
    //                copyResource(root, resource, mainFolder, path, monitor);
    //            }
    //        }
}

From source file:org.parallelj.designer.launching.internal.ParallelJPropertyTester.java

License:Open Source License

private boolean canLaunchAsParallelJ(IJavaElement element) {
    switch (element.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
    case IJavaElement.TYPE:
        return isParallelJProgram(element);
    default:/*  w  w  w  .  ja  v  a 2s.  com*/
        return false;
    }
}

From source file:org.projectusus.ui.internal.proportions.infopresenter.infomodel.UsusInfoBuilder.java

License:Open Source License

public static IUsusInfo of(IJavaElement element) {
    try {/*from  w w w.jav  a 2s  .  com*/
        IJavaElement currentElement = element;
        while (currentElement != null) {
            if (currentElement.getElementType() == IJavaElement.METHOD) {
                return new UsusInfoForMethod((IMethod) currentElement);
            }
            if (currentElement.getElementType() == IJavaElement.TYPE) {
                return new UsusInfoForClass((IType) currentElement);
            }
            if (currentElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                return new UsusInfoForFile(currentElement.getUnderlyingResource());
            }
            currentElement = currentElement.getParent();
        }
    } catch (JavaModelException e) {
        // do nothing
    }
    return new UnavailableUsusInfo(element);
}

From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.command.NewConcreteWizardCommand.java

License:Apache License

protected boolean executeSelection(ISelection selection) {
    if (selection instanceof StructuredSelection) {
        Object firstElement = ((StructuredSelection) selection).getFirstElement();
        if (firstElement instanceof IFile) {
            NewConcreteClassWizard wizard = new NewConcreteClassWizard();
            wizard.init(PlatformUI.getWorkbench(), (StructuredSelection) selection);
            this.getWorkbench(wizard);
            return true;
        }//from   w  ww. ja va2s .c  o  m
        if (firstElement instanceof FileEditorInput) {
            final IFile file = ((FileEditorInput) firstElement).getFile();
            NewConcreteClassWizard wizard = new NewConcreteClassWizard();
            wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file));
            this.getWorkbench(wizard);
            return true;
        }
        if (firstElement instanceof CompilationUnit) {
            IJavaElement javaElement = ((CompilationUnit) firstElement).getPrimaryElement();
            if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                final IFile file = javaElement.getJavaProject().getProject().getWorkspace().getRoot()
                        .getFile(javaElement.getPath());
                NewConcreteClassWizard wizard = new NewConcreteClassWizard();
                wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file));
                this.getWorkbench(wizard);
                return true;
            }
        }
        if (firstElement instanceof SourceType) {
            IJavaElement primaryElement = ((SourceType) firstElement).getPrimaryElement();
            if (primaryElement.getElementType() == IJavaElement.TYPE) {
                final IFile file = primaryElement.getJavaProject().getProject().getWorkspace().getRoot()
                        .getFile(primaryElement.getPath());
                NewConcreteClassWizard wizard = new NewConcreteClassWizard();
                wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file));
                this.getWorkbench(wizard);
                return true;
            }
        }
    }
    return false;
}

From source file:org.seasar.diigu.eclipse.preferences.DiiguClassPropertyPage.java

License:Apache License

private EnhanceProperty getEnhanceProperty(IAdaptable adaptable) {
    EnhanceProperty result = new EnhanceProperty();
    try {//from   ww w  . j  av a 2s .  co  m
        IJavaElement element = null;
        if (adaptable instanceof IJavaElement) {
            element = (IJavaElement) adaptable;

        } else {
            IResource resource = (IResource) adaptable.getAdapter(IResource.class);
            element = JavaCore.create(resource);
        }

        if (element != null) {
            switch (element.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                result.type = ((ICompilationUnit) element).findPrimaryType();
                result.enhanced = isEnhanced(findClassFile(result.type));
                break;
            case IJavaElement.TYPE:
                result.type = (IType) element;
                result.enhanced = isEnhanced(findClassFile(result.type));
                break;
            default:
                break;
            }
        }
    } catch (CoreException e) {
        DiiguPlugin.log(e);
    }
    return result;
}

From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TestCaseWizardPageOne.java

License:Apache License

/**
 * Initialized the page with the current selection
 * @param selection The selection//from   w w w .  j  a va 2 s  . c o  m
 */
public void init(IStructuredSelection selection) {
    IJavaElement element = getInitialJavaElement(selection);

    try {
        String mainTestPath = PreferenceStoreUtil.getPreferenceStoreOfWorkspace()
                .getString(Constants.PREF_TEST_JAVA_PATH);
        IJavaProject javaProject = element.getJavaProject();
        IFolder folder = javaProject.getProject().getFolder(mainTestPath);
        if (folder.exists()) {
            IPackageFragmentRoot findPackageFragmentRoot = javaProject
                    .findPackageFragmentRoot(folder.getFullPath());
            setPackageFragmentRoot(findPackageFragmentRoot, true);
        } else {
            initContainerPage(element);
        }
    } catch (JavaModelException e) {
        Logger.error(e, this);
    }
    initTypePage(element);
    // put default class to test      
    if (element != null) {
        IType classToTest = null;
        // evaluate the enclosing type
        IType typeInCompUnit = (IType) element.getAncestor(IJavaElement.TYPE);
        if (typeInCompUnit != null) {
            if (typeInCompUnit.getCompilationUnit() != null) {
                classToTest = typeInCompUnit;
            }
        } else {
            ICompilationUnit cu = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
            if (cu != null)
                classToTest = cu.findPrimaryType();
            else {
                if (element instanceof IClassFile) {
                    try {
                        IClassFile cf = (IClassFile) element;
                        if (cf.isStructureKnown())
                            classToTest = cf.getType();
                    } catch (JavaModelException e) {
                        Logger.error(e, this);
                    }
                }
            }
        }
        if (classToTest != null) {
            try {
                if (!TestSearchEngine.isTestImplementor(classToTest)) {
                    setClassUnderTest(classToTest.getFullyQualifiedName('.'));
                }
            } catch (JavaModelException e) {
                Logger.error(e, this);
            }
        }
    }

    restoreWidgetValues();

    boolean isJunit4 = false;
    //      if (element != null && element.getElementType() != IJavaElement.JAVA_MODEL) {
    //         IJavaProject project= element.getJavaProject();
    //         try {
    //            isJunit4= project.findType(JUnitPlugin.JUNIT4_ANNOTATION_NAME) != null;
    //         } catch (JavaModelException e) {
    //            // ignore
    //         }
    //      }
    if (store.getString(Constants.PREF_TEST_GENERATION_TYPE)
            .equals(org.seasar.s2junit4plugin.Messages.getString("Preference.JUnit4"))) {
        isJunit4 = true;
    }
    setJUnit4(isJunit4, true);

    boolean isS2Junit4 = false;
    //      if (element != null && element.getElementType() != IJavaElement.JAVA_MODEL) {
    //         IJavaProject project= element.getJavaProject();
    //         try {
    //            isS2Junit4= project.findType("org.seasar.framework.unit.Seasar2") != null;
    //         } catch (JavaModelException e) {
    //            // ignore
    //         }
    //      }
    if (store.getString(Constants.PREF_TEST_GENERATION_TYPE)
            .equals(org.seasar.s2junit4plugin.Messages.getString("Preference.S2JUnit4"))) {
        isS2Junit4 = true;
    }
    setS2JUnit4(isS2Junit4, true);

    updateStatus(getStatusList());
}

From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TypeWizardPage.java

License:Apache License

/**
 * Initializes all fields provided by the page with a given selection.
 * //from  ww  w .jav  a 2 s . c o  m
 * @param elem the selection used to initialize this page or <code>
 * null</code> if no selection was available
 */
protected void initTypePage(IJavaElement elem) {
    String initSuperclass = "java.lang.Object"; //$NON-NLS-1$
    ArrayList initSuperinterfaces = new ArrayList(5);

    IJavaProject project = null;
    IPackageFragment pack = null;
    IType enclosingType = null;

    if (elem != null) {
        // evaluate the enclosing type
        project = elem.getJavaProject();
        pack = (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
        IType typeInCU = (IType) elem.getAncestor(IJavaElement.TYPE);
        if (typeInCU != null) {
            if (typeInCU.getCompilationUnit() != null) {
                enclosingType = typeInCU;
            }
        } else {
            ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
            if (cu != null) {
                enclosingType = cu.findPrimaryType();
            }
        }

        try {
            IType type = null;
            if (elem.getElementType() == IJavaElement.TYPE) {
                type = (IType) elem;
                if (type.exists()) {
                    String superName = S2JUnit4SuperInterfaceSelectionDialog.getNameWithTypeParameters(type);
                    if (type.isInterface()) {
                        initSuperinterfaces.add(superName);
                    } else {
                        initSuperclass = superName;
                    }
                }
            }
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
            // ignore this exception now
        }
    }

    String typeName = ""; //$NON-NLS-1$

    ITextSelection selection = getCurrentTextSelection();
    if (selection != null) {
        String text = selection.getText();
        if (text != null && validateJavaTypeName(text, project).isOK()) {
            typeName = text;
        }
    }

    setPackageFragment(pack, true);
    setEnclosingType(enclosingType, true);
    setEnclosingTypeSelection(false, true);

    setTypeName(typeName, true);
    setSuperClass(initSuperclass, true);
    setSuperInterfaces(initSuperinterfaces, true);

    setAddComments(StubUtility.doAddComments(project), true); // from project or workspace
}

From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java

License:Open Source License

protected void decorateJavaElement(IJavaElement element, IDecoration decoration) {
    int type = element.getElementType();
    if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT || type == IJavaElement.CLASS_FILE
            || type == IJavaElement.COMPILATION_UNIT) {
        IBeansModel model = BeansCorePlugin.getModel();
        IBeansProject project = model.getProject(element.getJavaProject().getProject());
        if (project instanceof ILazyInitializedModelElement
                && ((ILazyInitializedModelElement) project).isInitialized()) {
            try {
                if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT) {

                    // Decorate JAR file
                    IResource resource = ((IPackageFragmentRoot) element).getResource();
                    if (resource instanceof IFile) {
                        for (IBeansConfig config : project.getConfigs()) {
                            if (config.getElementResource().equals(resource)) {
                                decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                                break;
                            }/*from w  w w.j  a  va2 s  .c  om*/
                        }
                    }
                } else if (type == IJavaElement.CLASS_FILE) {

                    // Decorate Java class file
                    IType javaType = ((IClassFile) element).getType();
                    if (BeansModelUtils.isBeanClass(javaType)) {
                        decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                    }
                } else if (type == IJavaElement.COMPILATION_UNIT) {

                    // Decorate Java source file
                    for (IType javaType : ((ICompilationUnit) element).getTypes()) {
                        if (BeansModelUtils.isBeanClass(javaType)) {
                            decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                            break;
                        }
                    }
                }
            } catch (JavaModelException e) {
                // Ignore
            }
        }
    }
}