use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class StubUtility method suggestArgumentNamesWithProposals.
public static String[][] suggestArgumentNamesWithProposals(IJavaProject project, IMethodBinding binding) {
int nParams = binding.getParameterTypes().length;
if (nParams > 0) {
try {
IMethod method = (IMethod) binding.getMethodDeclaration().getJavaElement();
if (method != null) {
String[] parameterNames = method.getParameterNames();
if (parameterNames.length == nParams) {
return suggestArgumentNamesWithProposals(project, parameterNames);
}
}
} catch (JavaModelException e) {
// ignore
e.printStackTrace();
}
}
String[][] names = new String[nParams][];
for (int i = 0; i < names.length; i++) {
//$NON-NLS-1$
names[i] = new String[] { "arg" + i };
}
return names;
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class StubUtility method getLineDelimiterUsed.
/**
* @param elem a Java element (doesn't have to exist)
* @return the existing or default line delimiter for the element
*/
public static String getLineDelimiterUsed(IJavaElement elem) {
IOpenable openable = elem.getOpenable();
if (openable instanceof ITypeRoot) {
try {
return openable.findRecommendedLineSeparator();
} catch (JavaModelException exception) {
// Use project setting
}
}
IJavaProject project = elem.getJavaProject();
return getProjectLineDelimiter(project.exists() ? project : null);
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class ContextSensitiveImportRewriteContext method findInContext.
@Override
public int findInContext(String qualifier, String name, int kind) {
IBinding[] declarationsInScope = getDeclarationsInScope();
for (int i = 0; i < declarationsInScope.length; i++) {
if (declarationsInScope[i] instanceof ITypeBinding) {
ITypeBinding typeBinding = (ITypeBinding) declarationsInScope[i];
if (isSameType(typeBinding, qualifier, name)) {
return RES_NAME_FOUND;
} else if (isConflicting(typeBinding, name)) {
return RES_NAME_CONFLICT;
}
} else if (declarationsInScope[i] != null) {
if (isConflicting(declarationsInScope[i], name)) {
return RES_NAME_CONFLICT;
}
}
}
Name[] names = getImportedNames();
for (int i = 0; i < names.length; i++) {
IBinding binding = names[i].resolveBinding();
if (binding instanceof ITypeBinding && !binding.isRecovered()) {
ITypeBinding typeBinding = (ITypeBinding) binding;
if (isConflictingType(typeBinding, qualifier, name)) {
return RES_NAME_CONFLICT;
}
}
}
List<AbstractTypeDeclaration> list = fCompilationUnit.types();
for (Iterator<AbstractTypeDeclaration> iter = list.iterator(); iter.hasNext(); ) {
AbstractTypeDeclaration type = iter.next();
ITypeBinding binding = type.resolveBinding();
if (binding != null) {
if (isSameType(binding, qualifier, name)) {
return RES_NAME_FOUND;
} else {
ITypeBinding decl = containingDeclaration(binding, qualifier, name);
while (decl != null && !decl.equals(binding)) {
int modifiers = decl.getModifiers();
if (Modifier.isPrivate(modifiers))
return RES_NAME_CONFLICT;
decl = decl.getDeclaringClass();
}
}
}
}
String[] addedImports = fImportRewrite.getAddedImports();
String qualifiedName = JavaModelUtil.concatenateName(qualifier, name);
for (int i = 0; i < addedImports.length; i++) {
String addedImport = addedImports[i];
if (qualifiedName.equals(addedImport)) {
return RES_NAME_FOUND;
} else {
if (isConflicting(name, addedImport))
return RES_NAME_CONFLICT;
}
}
if (qualifier.equals("java.lang")) {
//$NON-NLS-1$
//No explicit import statement required
ITypeRoot typeRoot = fCompilationUnit.getTypeRoot();
if (typeRoot != null) {
IPackageFragment packageFragment = (IPackageFragment) typeRoot.getParent();
try {
ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
for (int i = 0; i < compilationUnits.length; i++) {
ICompilationUnit cu = compilationUnits[i];
IType[] allTypes = cu.getAllTypes();
for (int j = 0; j < allTypes.length; j++) {
IType type = allTypes[j];
String packageTypeName = type.getFullyQualifiedName();
if (isConflicting(name, packageTypeName))
return RES_NAME_CONFLICT;
}
}
} catch (JavaModelException e) {
}
}
}
return fImportRewrite.getDefaultImportRewriteContext().findInContext(qualifier, name, kind);
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class HandleFactory method getJarPkgFragmentRoot.
private PackageFragmentRoot getJarPkgFragmentRoot(IPath jarPath, Object target, IJavaProject[] projects) {
for (int i = 0, projectCount = projects.length; i < projectCount; i++) {
try {
JavaProject javaProject = (JavaProject) projects[i];
IClasspathEntry classpathEnty = javaProject.getClasspathEntryFor(jarPath);
if (classpathEnty != null) {
if (target instanceof IFile) {
// internal jar
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot((IFile) target);
} else {
// external jar
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot0(jarPath);
}
}
} catch (JavaModelException e) {
// JavaModelException from getResolvedClasspath - a problem occurred while accessing project: nothing we can do, ignore
}
}
return null;
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class ASTNodes method getNodeSource.
/**
* Returns the source of the given node from the location where it was parsed.
* @param node the node to get the source from
* @param extendedRange if set, the extended ranges of the nodes should ne used
* @param removeIndent if set, the indentation is removed.
* @return return the source for the given node or null if accessing the source failed.
*/
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
ASTNode root = node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit astRoot = (CompilationUnit) root;
ITypeRoot typeRoot = astRoot.getTypeRoot();
try {
if (typeRoot != null && typeRoot.getBuffer() != null) {
IBuffer buffer = typeRoot.getBuffer();
int offset = extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
int length = extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
String str = buffer.getText(offset, length);
if (removeIndent) {
IJavaProject project = typeRoot.getJavaProject();
int indent = StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
str = Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
Aggregations