Example usage for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject.

Prototype

IJavaProject getJavaProject();

Source Link

Document

Returns the Java project this element is contained in, or null if this element is not contained in any Java project (for instance, the IJavaModel is not contained in any Java project).

Usage

From source file:org.jboss.tools.arquillian.ui.internal.wizards.NewArquillianJUnitTestCasePageOne.java

License:Open Source License

/**
 * Hook method that gets called when the class under test has changed. The method class under test
 * returns the status of the validation.
 * <p>//w  ww  . j  a  va  2 s.  c  om
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus classUnderTestChanged() {
    JUnitStatus status = new JUnitStatus();

    fClassUnderTest = null;
    fPage2.setClassUnderTest(null);
    fPage3.setClassUnderTest(null);

    IPackageFragmentRoot root = getPackageFragmentRoot();
    if (root == null) {
        return status;
    }

    String classToTestName = getClassUnderTestText();
    if (classToTestName.length() == 0) {
        return status;
    }

    IStatus val = JavaConventionsUtil.validateJavaTypeName(classToTestName, root);
    if (val.getSeverity() == IStatus.ERROR) {
        status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid);
        return status;
    }

    IPackageFragment pack = getPackageFragment(); // can be null
    try {
        IType type = resolveClassNameToType(root.getJavaProject(), pack, classToTestName);
        if (type == null) {
            status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_exist);
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(
                    Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_is_interface,
                            BasicElementLabels.getJavaElementName(classToTestName)));
        }

        if (pack != null && !JUnitStubUtility.isVisible(type, pack)) {
            status.setWarning(
                    Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_not_visible,
                            BasicElementLabels.getJavaElementName(classToTestName)));
        }
        fClassUnderTest = type;
        fPage2.setClassUnderTest(fClassUnderTest);
        fPage3.setClassUnderTest(fClassUnderTest);
    } catch (JavaModelException e) {
        status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid);
    }
    return status;
}

From source file:org.jboss.tools.arquillian.ui.internal.wizards.NewArquillianJUnitTestCasePageOne.java

License:Open Source License

/**
 * The method is called when the container has changed to validate if the project
 * is suited for the JUnit test class. Clients can override to modify or remove that validation.
 *
 * @return the status of the validation/*from w  w  w.  jav  a 2  s  .c  o m*/
 */
protected IStatus validateIfJUnitProject() {
    JUnitStatus status = new JUnitStatus();
    IPackageFragmentRoot root = getPackageFragmentRoot();
    if (root != null) {
        try {
            IJavaProject project = root.getJavaProject();
            if (project.exists()) {
                if (!JUnitStubUtility.is50OrHigher(project)) {
                    status.setError(WizardMessages.NewTestCaseWizardPageOne_error_java5required);
                    return status;
                }
                try {
                    if (!project.getProject().hasNature(ArquillianNature.ARQUILLIAN_NATURE_ID)) {
                        status.setWarning("The project doesn't have the Arquillian nature");
                        return status;
                    }
                } catch (CoreException e) {
                    ArquillianUIActivator.log(e);
                }
                if (project.findType(JUNIT4_ANNOTATION_NAME) == null) {
                    status.setWarning(WizardMessages.NewTestCaseWizardPageOne__error_junit4NotOnbuildpath);
                    return status;
                }
            }
        } catch (JavaModelException e) {
        }
    }
    return status;
}

From source file:org.jboss.tools.as.sourcelookup.ui.actions.AttachSourcesActionDelegate.java

License:Open Source License

private void attachSource(IPackageFragmentRoot fragment, IPath newSourcePath) {
    try {/*from ww w.  ja v  a  2 s .  c o m*/
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        IPath containerPath = null;
        IJavaProject jproject = fragment.getJavaProject();
        IClasspathEntry entry = fragment.getRawClasspathEntry();
        if (entry == null) {
            entry = JavaCore.newLibraryEntry(fragment.getPath(), null, null);
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                containerPath = entry.getPath();
                ClasspathContainerInitializer initializer = JavaCore
                        .getClasspathContainerInitializer(containerPath.segment(0));
                IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
                if (initializer == null || container == null) {
                    return;
                }
                IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject);
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                    return;
                }
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                    return;
                }
                entry = JavaModelUtil.findEntryInContainer(container, fragment.getPath());
                if (entry == null) {
                    return;
                }
            }
        }
        IClasspathEntry entry1;
        CPListElement elem = CPListElement.createFromExisting(entry, null);
        elem.setAttribute(CPListElement.SOURCEATTACHMENT, newSourcePath);
        entry1 = elem.getClasspathEntry();
        if (entry1.equals(entry)) {
            return;
        }
        IClasspathEntry newEntry = entry1;
        String[] changedAttributes = { CPListElement.SOURCEATTACHMENT };
        BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, jproject, containerPath,
                newEntry.getReferencingEntry() != null, new NullProgressMonitor());
    } catch (CoreException e) {
        // ignore
    }
}

From source file:org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralWizardPage.java

License:Open Source License

public void init(IStructuredSelection selection) {
    super.init(selection);
    defaultTypeName = null;/*from   www  .ja v  a2s.  c  om*/
    if (!selection.isEmpty()) {
        Object o = selection.iterator().next();
        IType type = null;
        if (o instanceof IType) {
            type = (IType) o;
        } else if (o instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) o;
            try {
                IType[] ts = cu.getTypes();
                if (ts != null && ts.length > 0)
                    type = ts[0];
            } catch (JavaModelException e) {
                CDICorePlugin.getDefault().logError(e);
            }

        }
        boolean isInterface = false;
        try {
            isInterface = type != null && type.isInterface();
        } catch (JavaModelException e) {
            CDICorePlugin.getDefault().logError(e);
        }
        if (isInterface) {
            String name = "";
            try {
                name = type.getFullyQualifiedParameterizedName();
            } catch (JavaModelException e) {
                name = type.getFullyQualifiedName();
            }
            IPackageFragmentRoot r = getPackageFragmentRoot();
            if (r != null) {
                ICDIProject cdi = NewCDIAnnotationWizardPage.getCDIProject(r.getJavaProject());
                IQualifier q = cdi != null ? cdi.getQualifier(name) : null;
                if (q != null) {
                    selected = q;
                    ArrayList<String> interfacesNames = new ArrayList<String>();
                    interfacesNames.add(name);
                    setSuperInterfaces(interfacesNames, true);
                    superInterfacesChanged();
                    setSuperClass(CDIConstants.ANNOTATION_LITERAL_TYPE_NAME + "<" + type.getElementName() + ">",
                            false);
                    setDefaultTypeName(name);
                }
            }
        }
    }

    doStatusUpdate();
}

From source file:org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralWizardPage.java

License:Open Source License

void validateQualifierSelection(Object value) {
    boolean done = false;
    if (value != null) {
        String name = value.toString();
        IPackageFragmentRoot r = getPackageFragmentRoot();
        if (r != null) {
            ICDIProject cdi = NewCDIAnnotationWizardPage.getCDIProject(r.getJavaProject());
            selected = cdi != null ? cdi.getQualifier(name) : null;
            if (selected != null) {
                ArrayList<String> interfacesNames = new ArrayList<String>();
                interfacesNames.add(name);
                setSuperInterfaces(interfacesNames, true);
                superInterfacesChanged();
                setSuperClass(CDIConstants.ANNOTATION_LITERAL_TYPE_NAME + "<"
                        + selected.getSourceType().getElementName() + ">", false);
                setDefaultTypeName(name);
                done = true;/*from w w  w  .j av  a  2s  . c o m*/
            }
        }
    }
    if (!done) {
        selected = null;
        setSuperInterfaces(new ArrayList<String>(), true);
        superInterfacesChanged();
    }

}

From source file:org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralWizardPage.java

License:Open Source License

void setQualifiers(IPackageFragmentRoot root) {
    qualifiersProvider.setProject(null);
    if (root != null) {
        IJavaProject jp = root.getJavaProject();
        ICDIProject cdi = NewCDIAnnotationWizardPage.getCDIProject(jp);
        if (cdi != null) {
            qualifiersProvider.setProject(cdi);
        }//from  w  ww  . j a v a2s .co  m
    }
}

From source file:org.jboss.tools.cdi.ui.wizard.NewBeanWizardPage.java

License:Open Source License

void setScopes(IPackageFragmentRoot root) {
    if (root != null) {
        IJavaProject jp = root.getJavaProject();
        ICDIProject cdi = NewCDIAnnotationWizardPage.getCDIProject(jp);
        if (cdi != null) {
            setScopes(cdi.getScopeNames().toArray(new String[0]));
        } else {//from  w w  w  .j ava2 s  . co  m
            setScopes(new String[] { "" });
        }
    } else {
        setScopes(new String[] { "" });
    }
}

From source file:org.jboss.tools.cdi.ui.wizard.NewBeanWizardPage.java

License:Open Source License

void setQualifiers(IPackageFragmentRoot root) {
    qualifiersProvider.setProject(null);
    if (root != null) {
        IJavaProject jp = root.getJavaProject();
        ICDIProject cdi = CDICorePlugin.getCDIProject(jp.getProject(), true);
        if (cdi != null)
            qualifiersProvider.setProject(cdi);
    }/*  www.ja  va 2  s.c om*/
}

From source file:org.jboss.tools.cdi.ui.wizard.NewInterceptorBindingWizardPage.java

License:Open Source License

void setInterceptorBindings(IPackageFragmentRoot root) {
    interceptorBindingsProvider.setProject(null);
    if (root != null) {
        IJavaProject jp = root.getJavaProject();
        ICDIProject cdi = getCDIProject(jp);
        if (cdi != null) {
            interceptorBindingsProvider.setProject(cdi);
        }/*from   w w  w  .  ja v a  2  s.co m*/
    }
}

From source file:org.jboss.tools.cdi.ui.wizard.NewInterceptorWizardPage.java

License:Open Source License

void setInterceptorBindings(IPackageFragmentRoot root) {
    interceptorBindingsProvider.setProject(null);
    if (root != null) {
        IJavaProject jp = root.getJavaProject();
        ICDIProject cdi = NewCDIAnnotationWizardPage.getCDIProject(jp);
        if (cdi != null) {
            interceptorBindingsProvider.setProject(cdi);
        }/* w ww .  j  av  a 2  s .co m*/
    }
    interceptorBindingsProvider.setPackageFragment(getPackageFragment());
}