use of org.eclipse.jdt.internal.core.NameLookup in project xtext-eclipse by eclipse.
the class JdtTypeProvider method findPrimaryType.
/**
* @since 2.9
*/
protected IType findPrimaryType(String packageName, String typeName) throws JavaModelException {
JavaProject casted = (JavaProject) javaProject;
NameLookup nameLookup = getNameLookup(casted);
NameLookup.Answer answer = nameLookup.findType(typeName, packageName, false, NameLookup.ACCEPT_ALL, // do not consider secondary types
false, // wait for indexes (in case we need to consider secondary types)
true, false, /*don't check restrictions*/
null);
return answer == null ? null : answer.type;
}
use of org.eclipse.jdt.internal.core.NameLookup in project eclipse.pde by eclipse-pde.
the class Util method findSourceTypeinJavaProject.
/**
* Tries to find SourceType of name typeName in the project. It returns null
* if it cannot find SourceType of name typeName
*
* @param javaProject
* @param typeName
* @return
*/
public static IType findSourceTypeinJavaProject(IJavaProject javaProject, String typeName) {
IType type = null;
try {
String pkgName = typeName.substring(0, typeName.lastIndexOf('.'));
if (javaProject instanceof JavaProject) {
JavaProject jp = (JavaProject) javaProject;
NameLookup newNameLookup = null;
try {
newNameLookup = jp.newNameLookup(DefaultWorkingCopyOwner.PRIMARY);
} catch (JavaModelException e) {
ApiPlugin.log(e);
}
IPackageFragment[] findPackageFragment = newNameLookup.findPackageFragments(pkgName, false);
for (IPackageFragment iJavaElement : findPackageFragment) {
type = newNameLookup.findType(typeName.substring(typeName.lastIndexOf('.') + 1, typeName.length()), iJavaElement, false, NameLookup.ACCEPT_ALL);
if (type instanceof SourceType) {
break;
}
}
}
} catch (Exception e) {
// return null
}
return type;
}
Aggregations