List of usage examples for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT
int PACKAGE_FRAGMENT_ROOT
To view the source code for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT.
Click Source Link
From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java
License:Open Source License
private IClasspathEntry findGwtUserClasspathEntry() throws JavaModelException { /*//from w w w. j a v a2 s .c om * Note that the type that we're looking for to determine if we're part of the gwt-user library * is different than the one that is used by the superclass. This is because the class that the * superclass is querying for, "com.google.gwt.core.client.GWT", also exists in the gwt-servlet * library, and for some reason, this sometimes ends up on the build path for Maven projects. * * TODO: See why Maven is putting gwt-servlet on the build path. * * TODO: Change the class query in the superclass to "com.google.gwt.junit.client.GWTTestCase" */ IType type = javaProject.findType("com.google.gwt.junit.client.GWTTestCase"); if (type == null) { return null; } IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { // TODO: If the Maven javadoc and source libs for gwt-dev.jar are // available, attach them here. return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java
License:Open Source License
private IClasspathEntry findJavaXValidationClasspathEntry() throws JavaModelException { IType type = javaProject.findType("javax.validation.Constraint"); if (type == null) { return null; }//w ww.j a va 2s. co m IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
From source file:com.google.gwt.eclipse.core.validators.java.JsniJavaRef.java
License:Open Source License
public IJavaElement resolveJavaElement(IJavaProject project) throws UnresolvedJsniJavaRefException { IJavaElement element = null;/*from w w w .j a v a 2 s .c o m*/ // 0. Ignore the magic null reference if (className().equals("null")) { throw new UnresolvedJsniJavaRefException(null, this); } // 1. Try to find the type in the project's classpath IType type = JavaModelSearch.findType(project, dottedClassName()); if (type == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_UNRESOLVED_TYPE, this); } // TODO: remove this check once we can validate against super source // 1A. Do not validate JRE types (they could contain references to members // which are only defined in the emulated versions in super source) if (type.isBinary()) { IPackageFragmentRoot pkgRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry cpEntry = pkgRoot.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && cpEntry.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)) { throw new UnresolvedJsniJavaRefException(null, this); } } catch (JavaModelException e) { GWTPluginLog.logError(e); throw new UnresolvedJsniJavaRefException(null, this); } } // 2. Create a super-type hierarchy for the type, which we'll use for // finding its super classes and implemented interfaces ITypeHierarchy hierarchy; try { hierarchy = type.newSupertypeHierarchy(null); } catch (JavaModelException e) { GWTPluginLog.logError(e, "Error creating type hierarchy for " + className()); throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_UNRESOLVED_TYPE, this); } if (isMethod()) { if (isConstructor()) { if (matchesAnyOverload()) { element = JavaModelSearch.findFirstCtor(type); } else { String[] ctorParamTypes = paramTypes(); try { /* * If the constructor is on a non-static inner class, the reference * will have an extra parameter that specifies the enclosing type. * We'll need to check that type and then remove the parameter * before using JavaModelSearch to find the constructor. */ IJavaElement typeParent = type.getParent(); if (typeParent.getElementType() == IJavaElement.TYPE && !Flags.isStatic(type.getFlags())) { // Make sure we do have the enclosing type as the first parameter if (ctorParamTypes.length == 0) { throw new UnresolvedJsniJavaRefException( GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } // Now verify that the type of the first parameter is actually the // the same type as the enclosing type IType parentType = (IType) typeParent; String enclosingTypeName = parentType.getFullyQualifiedName('.'); String enclosingTypeParam = JavaModelSearch.getQualifiedTypeName(ctorParamTypes[0]); if (!enclosingTypeName.equals(enclosingTypeParam)) { throw new UnresolvedJsniJavaRefException( GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } // Drop the first parameter (the enclosing type) ctorParamTypes = new String[paramTypes().length - 1]; System.arraycopy(paramTypes(), 1, ctorParamTypes, 0, ctorParamTypes.length); } } catch (JavaModelException e) { GWTPluginLog.logError(e); // Continue on and try to resolve the reference anyway } // 3A. Find a constructor for this type with matching parameter types element = JavaModelSearch.findCtorInHierarchy(hierarchy, type, ctorParamTypes); if (element == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } } } else { // 3B. Find a method for this type with the same name element = JavaModelSearch.findMethodInHierarchy(hierarchy, type, memberName()); if (element == null) { try { if (type.isEnum()) { // Ignore the magic Enum::values() method if (memberName().equals("values") && !matchesAnyOverload() && paramTypes().length == 0) { // Throwing this exception with a null GWTProblemType indicates // that the ref doesn't resolve, but can be ignored anyway. throw new UnresolvedJsniJavaRefException(null, this); } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_MISSING_METHOD, this); } if (!matchesAnyOverload()) { // Now try to match the method's parameter types element = JavaModelSearch.findMethodInHierarchy(hierarchy, type, memberName(), paramTypes()); if (element == null) { try { if (type.isEnum()) { // Ignore the synthetic Enum::valueOf(String) method. // Note that valueOf(Class,String) is not synthetic. if (memberName().equals("valueOf") && paramTypes().length == 1 && paramTypes()[0].equals("Ljava/lang/String;")) { // Throwing this exception with a null GWTProblemType // indicates that the ref doesn't resolve, but can be ignored // anyway. throw new UnresolvedJsniJavaRefException(null, this); } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_METHOD, this); } } } } else { // 3C. Find a field with the same name assert (isField()); element = JavaModelSearch.findFieldInHierarchy(hierarchy, type, memberName()); if (element == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_MISSING_FIELD, this); } } assert (element != null); return element; }
From source file:com.google.gwt.eclipse.devtoolsgen.actions.PopulateGwtDevTools.java
License:Open Source License
public void run(IAction action) { try {//from ww w .j av a 2s. c om if (gwtDev == null) { System.err.println("Must import the gwt-dev project"); return; } if (gwtUser == null) { System.err.println("Must import the gwt-user project"); return; } if (gwtDevTools == null) { System.err.println("Must import the gwt-dev-tools project"); return; } System.out.println("Searching for dependecies in GWT source projects..."); deps.clear(); IType searchRoot = gwtDevTools.findType("Deps"); // Find compilation units and resources we depend on findAllDependencies(searchRoot.getCompilationUnit(), 0); int totalDepsCount = deps.size(); // Prune out files already in gwt-dev-tools. This eliminates most of the // bulk copy when you've already run this tool at least once. Iterator<IFile> iter = deps.iterator(); while (iter.hasNext()) { IFile dep = iter.next(); IJavaElement srcRoot = JavaCore.create(dep.getParent()) .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPath srcPathRelativePath = dep.getFullPath().removeFirstSegments(srcRoot.getPath().segmentCount()); IFile existingFile = findFileOnClasspath(gwtDevTools, srcPathRelativePath); if (existingFile != null) { iter.remove(); } } System.out.format("Finished dependency search (%d files found; %d new)\n", totalDepsCount, deps.size()); if (!deps.isEmpty()) { IWorkspaceRunnable op = new CopyDepsToGwtDevTools(); ISchedulingRule lock = ResourcesPlugin.getWorkspace().getRoot(); ResourcesPlugin.getWorkspace().run(op, lock, IWorkspace.AVOID_UPDATE, null); } else { System.out.println("Done"); } } catch (CoreException e) { e.printStackTrace(); } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void processDelta(final IJavaElementDelta delta, Set<IJavaProject> remove, Set<IJavaProject> add) throws CoreException { final IJavaElement element = delta.getElement(); final int kind = delta.getKind(); switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: processChangedChildren(delta, remove, add); break;/*from www . j a va 2 s . c o m*/ case IJavaElement.JAVA_PROJECT: switch (kind) { case IJavaElementDelta.REMOVED: remove.add((IJavaProject) element); break; case IJavaElementDelta.ADDED: add.add((IJavaProject) element); break; case IJavaElementDelta.CHANGED: switch (delta.getFlags()) { case IJavaElementDelta.F_CLOSED: remove.add((IJavaProject) element); break; case IJavaElementDelta.F_OPENED: add.add((IJavaProject) element); break; } break; } processChangedChildren(delta, remove, add); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: remove.add(element.getJavaProject()); add.add(element.getJavaProject()); break; } }
From source file:com.iw.plugins.spindle.core.util.CoreUtils.java
License:Mozilla Public License
/** * Returns the package fragment root of <code>IJavaElement</code>. If the given element is * already a package fragment root, the element itself is returned. *//*from ww w. ja va 2 s . c o m*/ public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element) { return (IPackageFragmentRoot) findElementOfKind(element, IJavaElement.PACKAGE_FRAGMENT_ROOT); }
From source file:com.liferay.ide.portlet.ui.wizard.NewPortletClassWizardPage.java
License:Open Source License
protected IPackageFragmentRoot getSelectedPackageFragmentRoot() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; }//from w ww . j ava 2s . c om ISelection selection = window.getSelectionService().getSelection(); if (selection == null) { return null; } // StructuredSelection stucturedSelection = (StructuredSelection) // selection; IJavaElement element = getInitialJavaElement(selection); if (element != null) { if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { return (IPackageFragmentRoot) element; } } return null; }
From source file:com.liferay.ide.service.ui.editor.ServiceMethodHyperlinkDetector.java
License:Open Source License
private IJavaElement[] selectOpenableElements(IJavaElement[] elements) { final List<IJavaElement> result = new ArrayList<IJavaElement>(elements.length); for (int i = 0; i < elements.length; i++) { final IJavaElement element = elements[i]; switch (element.getElementType()) { case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: break; default://from w ww. j a va2s .c om result.add(element); break; } } return result.toArray(new IJavaElement[result.size()]); }
From source file:com.liferay.ide.service.ui.wizard.NewServiceBuilderWizardPage.java
License:Open Source License
protected IPackageFragmentRoot getSelectedPackageFragmentRoot() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; }// w ww .j ava 2 s .co m ISelection selection = window.getSelectionService().getSelection(); if (selection == null) { return null; } // StructuredSelection stucturedSelection = (StructuredSelection) // selection; IJavaElement element = getInitialJavaElement(selection); if (element != null) { if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) return (IPackageFragmentRoot) element; } return null; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the label for a Java element with the flags as defined by this class. * * @param element the element to render/*from w w w .j av a2s .c o m*/ * @param flags the rendering flags. */ public void appendElementLabel(IJavaElement element, long flags) { int type = element.getElementType(); IPackageFragmentRoot root = null; if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) { appendPackageFragmentRootLabel(root, ROOT_QUALIFIED); fBuffer.append(CONCAT_STRING); } switch (type) { case IJavaElement.METHOD: appendMethodLabel((IMethod) element, flags); break; case IJavaElement.FIELD: appendFieldLabel((IField) element, flags); break; case IJavaElement.LOCAL_VARIABLE: appendLocalVariableLabel((ILocalVariable) element, flags); break; case IJavaElement.TYPE_PARAMETER: appendTypeParameterLabel((ITypeParameter) element, flags); break; case IJavaElement.INITIALIZER: appendInitializerLabel((IInitializer) element, flags); break; case IJavaElement.TYPE: appendTypeLabel((IType) element, flags); break; case IJavaElement.CLASS_FILE: appendClassFileLabel((IClassFile) element, flags); break; case IJavaElement.COMPILATION_UNIT: appendCompilationUnitLabel((ICompilationUnit) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT: appendPackageFragmentLabel((IPackageFragment) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags); break; case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.PACKAGE_DECLARATION: appendDeclarationLabel(element, flags); break; case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: fBuffer.append(element.getElementName()); break; default: fBuffer.append(element.getElementName()); } if (root != null && getFlag(flags, APPEND_ROOT_PATH)) { int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); appendPackageFragmentRootLabel(root, ROOT_QUALIFIED); } }