use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavadocUrlTest method binaryFieldUri.
@Test
public void binaryFieldUri() throws JavaModelException, URISyntaxException, UnsupportedEncodingException {
IType type = project.findType("java.util.ArrayList");
IField field = type.getField("size");
String uri = JavaElementLinks.createURI(urlPart, field);
String handle = uri.substring(urlPart.length());
handle = URLDecoder.decode(handle, "UTF-8");
IJavaElement element = JavaElementLinks.parseURI(handle, project);
assertThat(element).isNotNull().isEqualTo(field);
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavadocFromSourceTest method testResolveBinaryMethodsParam.
@Test
public void testResolveBinaryMethodsParam() throws Exception {
IJavaElement element = project.findElement("Ljava/lang/String;.endsWith(Ljava.lang.String;)Z", null);
assertThat(element).isNotNull().isInstanceOf(IMethod.class);
assertThat(element.getElementName()).isEqualTo("endsWith");
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class PackageFragmentRootReorgChange method getUpdateModelFlags.
protected int getUpdateModelFlags(boolean isCopy) throws JavaModelException {
final int destination = IPackageFragmentRoot.DESTINATION_PROJECT_CLASSPATH;
final int replace = IPackageFragmentRoot.REPLACE;
final int originating;
final int otherProjects;
if (isCopy) {
//ORIGINATING_PROJECT_CLASSPATH does not apply to copy
originating = 0;
//OTHER_REFERRING_PROJECTS_CLASSPATH does not apply to copy
otherProjects = 0;
} else {
originating = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH;
otherProjects = IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
}
IJavaElement javaElement = JavaCore.create(getDestination());
if (javaElement == null || !javaElement.exists())
return replace | originating;
if (fUpdateClasspathQuery == null)
return replace | originating | destination;
IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(getRoot());
if (referencingProjects.length <= 1)
return replace | originating | destination;
boolean updateOtherProjectsToo = fUpdateClasspathQuery.confirmManipulation(getRoot(), referencingProjects);
if (updateOtherProjectsToo)
return replace | originating | destination | otherProjects;
else
return replace | originating | destination;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class StubCreator method appendMembers.
protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
try {
monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
final IJavaElement[] children = type.getChildren();
for (int index = 0; index < children.length; index++) {
final IMember child = (IMember) children[index];
final int flags = child.getFlags();
final boolean isPrivate = Flags.isPrivate(flags);
final boolean isDefault = !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
final boolean stub = fStubInvisible || (!isPrivate && !isDefault);
if (child instanceof IType) {
if (stub)
appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
} else if (child instanceof IField) {
if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
appendFieldDeclaration((IField) child);
} else if (child instanceof IMethod) {
final IMethod method = (IMethod) child;
final String name = method.getElementName();
if (method.getDeclaringType().isEnum()) {
final int count = method.getNumberOfParameters();
if (//$NON-NLS-1$
count == 0 && "values".equals(name))
continue;
if (//$NON-NLS-1$ //$NON-NLS-2$
count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0]))
continue;
if (method.isConstructor())
continue;
}
//$NON-NLS-1$
boolean skip = !stub || name.equals("<clinit>");
if (method.isConstructor())
skip = false;
skip = skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
if (!skip)
appendMethodDeclaration(method);
}
//$NON-NLS-1$
fBuffer.append("\n");
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RefactoringSearchEngine method findAffectedCompilationUnits.
//TODO: throw CoreException
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern, IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {
boolean hasNonCuMatches = false;
class ResourceSearchRequestor extends SearchRequestor {
boolean hasPotentialMatches = false;
Set<IResource> resources = new HashSet<IResource>(5);
private IResource fLastResource;
@Override
public void acceptSearchMatch(SearchMatch match) {
if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
hasPotentialMatches = true;
}
if (fLastResource != match.getResource()) {
fLastResource = match.getResource();
resources.add(fLastResource);
}
}
}
ResourceSearchRequestor requestor = new ResourceSearchRequestor();
try {
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
} catch (CoreException e) {
throw new JavaModelException(e);
}
List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
IResource resource = iter.next();
IJavaElement element = JavaCore.create(resource);
if (element instanceof ICompilationUnit) {
result.add(element);
} else {
hasNonCuMatches = true;
}
}
addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
return result.toArray(new ICompilationUnit[result.size()]);
}
Aggregations