Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Problem: Class after creation not found in model
Problem: Class after creation not found in model [message #247739] Wed, 12 September 2007 14:12 Go to next message
Eclipse UserFriend
Originally posted by: mail.nicetoeatyou.de

Hello,
we are working on some Tests for our Plugin.
There we need to build some classes from scratch:

IPackageFragmentRoot packageFragmentRoot = javaProject.getPackageFragmentRoot(javaProject.getResource() );
IPackageFragment packageFragment = packageFragmentRoot.createPackageFragment("de.unikassel.janus.tests.autocompletion ", true, null);
ICompilationUnit compilationUnit = packageFragment.createCompilationUnit("Simple.java",
"class Simple {" +
"}",
true, null);

After creation, the .java and .class files are found where expected and with right content,
but if try to find the class via SearchEngine.searchAllTypeNames i dont find it?

What did we miss? And what do we need to do, to get the new created classes into the model?
We experimented with getProject().build(IncrementalProjectBuilder.FULL_BUILD,..
and Platform.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_ BUILD,...
but no results.


Kind regards,

Dennis Keßler
Re: Problem: Class after creation not found in model [message #247753 is a reply to message #247739] Thu, 13 September 2007 13:27 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
Dennis Keßler wrote:
> Hello,
> we are working on some Tests for our Plugin.
> There we need to build some classes from scratch:
>
> IPackageFragmentRoot packageFragmentRoot =
> javaProject.getPackageFragmentRoot(javaProject.getResource() );
> IPackageFragment packageFragment =
> packageFragmentRoot.createPackageFragment("de.unikassel.janus.tests.autocompletion ",
> true, null);
> ICompilationUnit compilationUnit =
> packageFragment.createCompilationUnit("Simple.java",
> "class Simple {" +
> "}",
> true, null);
>
> After creation, the .java and .class files are found where expected and
> with right content,
> but if try to find the class via SearchEngine.searchAllTypeNames i dont
> find it?
>
> What did we miss? And what do we need to do, to get the new created
> classes into the model?
Could it be that the source of Simple.java doesn't contain a package
declaration ? e.g.
"package de.unikassel.janus.tests.autocompletion;" +
"public class Simple {" +
"}".
Also how do you use the SearchEngine ? What waiting policy do you use ?
Re: Problem: Class after creation not found in model [message #247766 is a reply to message #247753] Fri, 14 September 2007 20:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.nicetoeatyou.de

Jerome Lanneluc wrote:
>
> Could it be that the source of Simple.java doesn't contain a package
> declaration ? e.g.
> "package de.unikassel.janus.tests.autocompletion;" +
> "public class Simple {" +
> "}".
> Also how do you use the SearchEngine ? What waiting policy do you use ?

i have added the package, but still no results.
Waht iam doing is:
packageFragment = packageFragmentRoot.createPackageFragment("de.unikassel.janus.tests.autocompletion2 ", true, null);
compilationUnit = packageFragment.createCompilationUnit("Simple.java",
"package de.unikassel.janus.tests.autocompletion2;\n" +
"class Simple {\n" +
"}",
true, null);
javaProject.getProject().build(IncrementalProjectBuilder.FUL L_BUILD, null);
Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BU ILD, null);
Platform.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_ BUILD, null);

After that i use basicly the SearchEngine like this:
searchEngine.searchAllTypeNames(
packageName.toCharArray(),//final char[] packageName,
SearchPattern.R_PATTERN_MATCH,//final int packageMatchRule,
"Simpl".toCharArray(),
SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,//final int typeMatchRule,
IJavaSearchConstants.TYPE,//int searchFor,
scope,//IJavaSearchScope scope,
typeInfoRequestor,//final TypeNameMatchRequestor nameMatchRequestor,
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,//int waitingPolicy,
null//IProgressMonitor progressMonitor
);

But still no results.
If i try it in the working code, like opening our graphical editor,
rightclick on src folder in Package View, create class Simple and use then
an autocompletion in any of our type-autocompletion-enabled elements,
Simple is found and inserted correctly.

I tried it also with IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH


Kind regards,

Dennis Keßler
Re: Problem: Class after creation not found in model [message #247783 is a reply to message #247766] Tue, 18 September 2007 16:54 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
There must be something else going on with your code. I ran the following test successfully
(ie. it printed "de.unikassel.janus.tests.autocompletion2.Simple" to the console):

IJavaProject javaProject = createJavaProject("P");
IPackageFragmentRoot packageFragmentRoot = getPackageFragmentRoot("/P");
String packageName = "de.unikassel.janus.tests.autocompletion2";
IPackageFragment packageFragment = packageFragmentRoot.createPackageFragment(packageName, true, null);
packageFragment.createCompilationUnit("Simple.java",
"package de.unikassel.janus.tests.autocompletion2;\n" +
"class Simple {\n" +
"}",
true, null);
javaProject.getProject().build(IncrementalProjectBuilder.FUL L_BUILD, null);
Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BU ILD, null);
Platform.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_ BUILD, null);
SearchEngine searchEngine = new SearchEngine();
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
TypeNameMatchRequestor typeInfoRequestor = new TypeNameMatchRequestor(){
public void acceptTypeNameMatch(TypeNameMatch match) {
System.out.println(match.getFullyQualifiedName());
}
};
searchEngine.searchAllTypeNames(
packageName.toCharArray(),//final char[] packageName,
SearchPattern.R_PATTERN_MATCH,//final int packageMatchRule,
"Simpl".toCharArray(),
SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,//final int typeMatchRule,
IJavaSearchConstants.TYPE,//int searchFor,
scope,//IJavaSearchScope scope,
typeInfoRequestor,//final TypeNameMatchRequestor nameMatchRequestor,
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,//int waitingPolicy,
null//IProgressMonitor progressMonitor
);
Re: Problem: Class after creation not found in model [message #247821 is a reply to message #247783] Wed, 19 September 2007 01:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.nicetoeatyou.de

Jerome Lanneluc wrote:
> There must be something else going on with your code. I ran the
> following test successfully
> (ie. it printed "de.unikassel.janus.tests.autocompletion2.Simple" to the
> console):...
As i tested further, i found an exception:
Java Model Exception: Java Model Status [de.unikassel.janus.tests.autocompletion is read-only]
at this line:
IPackageFragment packageFragment = packageFragmentRoot.createPackageFragment("de.unikassel.janus.tests.autocompletion ", true, null);
Whats the meaning of this? Maybe we are doing something wrong at Projectcreation..
Can you Post your IJavaProject javaProject = createJavaProject("P"); code?


Kind regards,

Dennis Keßler
Re: Problem: Class after creation not found in model [message #247859 is a reply to message #247821] Wed, 19 September 2007 14:07 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
Dennis Keßler wrote:
> Jerome Lanneluc wrote:
>> There must be something else going on with your code. I ran the
>> following test successfully
>> (ie. it printed "de.unikassel.janus.tests.autocompletion2.Simple" to
>> the console):...
> As i tested further, i found an exception:
> Java Model Exception: Java Model Status
> [de.unikassel.janus.tests.autocompletion is read-only]
> at this line:
> IPackageFragment packageFragment =
> packageFragmentRoot.createPackageFragment("de.unikassel.janus.tests.autocompletion ",
> true, null);
It means that the package already exists on disk and that it has been set to read-only on the file system.

> Whats the meaning of this? Maybe we are doing something wrong at
> Projectcreation..
> Can you Post your IJavaProject javaProject = createJavaProject("P"); code?
public IJavaProject createJavaProject(String projectName) throws CoreException {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject project = workspaceRoot.getProject(projectName);
project.create(null);
project.open(null);
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] {JavaCore.NATURE_ID});
project.setDescription(description, null);
IJavaProject javaProject = JavaCore.create(project);
javaProject.setRawClasspath(
new IClasspathEntry[] {
JavaCore.newSourceEntry(project.getFullPath())
},
null);
return javaProject;
}
Re: Problem: Class after creation not found in model [message #247864 is a reply to message #247783] Wed, 19 September 2007 14:11 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
I just realized that you forced the project to be built. This is not necessary since the Java indexing
is independent from the Java builder.

So the following code also works for me:

createJavaProject("P");
IPackageFragmentRoot packageFragmentRoot = getPackageFragmentRoot("/P");
String packageName = "de.unikassel.janus.tests.autocompletion2";
IPackageFragment packageFragment = packageFragmentRoot.createPackageFragment(packageName, true, null);
packageFragment.createCompilationUnit("Simple.java",
"package de.unikassel.janus.tests.autocompletion2;\n" +
"class Simple {\n" +
"}",
true, null);
SearchEngine searchEngine = new SearchEngine();
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
TypeNameMatchRequestor typeInfoRequestor = new TypeNameMatchRequestor(){
public void acceptTypeNameMatch(TypeNameMatch match) {
System.out.println(match.getFullyQualifiedName());
}
};
searchEngine.searchAllTypeNames(
packageName.toCharArray(),//final char[] packageName,
SearchPattern.R_PATTERN_MATCH,//final int packageMatchRule,
"Simpl".toCharArray(),
SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,//final int typeMatchRule,
IJavaSearchConstants.TYPE,//int searchFor,
scope,//IJavaSearchScope scope,
typeInfoRequestor,//final TypeNameMatchRequestor nameMatchRequestor,
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,//int waitingPolicy,
null//IProgressMonitor progressMonitor
);
Re: Problem: Class after creation not found in model [message #248488 is a reply to message #247859] Mon, 08 October 2007 13:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.nicetoeatyou.de

Hi,
back from holidays.
And good news :-)
It finaly works, but to say what was all wrong... too many!
Best Thanks for your help


Kind regards,

Dennis Keßler
Re: Problem: Class after creation not found in model [message #248503 is a reply to message #248488] Tue, 09 October 2007 13:55 Go to previous message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
Dennis Keßler wrote:
> Hi,
> back from holidays.
> And good news :-)
> It finaly works, but to say what was all wrong... too many!
> Best Thanks for your help
>
>
> Kind regards,
>
> Dennis Keßler
I'm glad it now works. However it would be good to understand what
went wrong for future reference. Was it a misunderstanding of the API ?
In this case, what wasn't clear ? We might be able to clarify things.

Thanks,
Jerome
Previous Topic:Move refactoring via descriptors
Next Topic:How do I debug JDT?
Goto Forum:
  


Current Time: Wed Jun 26 20:03:14 GMT 2024

Powered by FUDForum. Page generated in 0.28533 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top