List of usage examples for org.eclipse.jdt.core IJavaModelStatusConstants CORE_EXCEPTION
int CORE_EXCEPTION
To view the source code for org.eclipse.jdt.core IJavaModelStatusConstants CORE_EXCEPTION.
Click Source Link
From source file:com.motorola.studio.android.generatecode.JavaCodeModifier.java
License:Apache License
/** * Insert code into the class (activity / fragment) and adds imports if necessary. * @throws JavaModelException Thrown if there were problems parsing the java file. *//* ww w.j a v a2 s. c o m*/ public void insertCode(IProgressMonitor monitor, IEditorPart editor) throws JavaModelException { final SubMonitor theMonitor = SubMonitor.convert(monitor); IResource resource = codeGeneratorData.getResource(); if (resource instanceof IFile) { IFile java = (IFile) resource; StudioLogger.info("Trying to insert code for class: " + java.getFullPath() + " based on resource " //$NON-NLS-1$ + getDataResource()); IDocument document = null; try { document = ((AbstractTextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput()); final ICompilationUnit compUnit = getCodeGeneratorData().getICompilationUnit(); CompilationUnit cpU = getCodeGeneratorData().getCompilationUnit(); try { cpU.recordModifications(); initVariables(); codeGenerators.clear(); codeGenerators = populateListOfCodeGenerators(getCodeGeneratorData()); theMonitor.beginTask(CodeUtilsNLS.JavaViewBasedOnLayoutModifier_InsertingCode, 1000 * getNumberOfTasks()); callCodeGenerators(theMonitor, java); addImportsIfRequired(theMonitor, cpU); Map<?, ?> mapOptions = JavaCore.create(java.getProject()).getOptions(true); final TextEdit edit = cpU.rewrite(document, mapOptions); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { try { compUnit.applyTextEdit(edit, theMonitor); } catch (JavaModelException e) { StudioLogger.error(this.getClass(), "Error applying changes: " + e.getMessage(), e); //$NON-NLS-1$ } } }); } catch (CoreException e) { StudioLogger.error(this.getClass(), "Error changing AST activity/fragment: " + e.getMessage()); //$NON-NLS-1$ throw new JavaModelException(e); } catch (RuntimeException rte) { StudioLogger.error(this.getClass(), "Error changing AST activity/fragment: " + rte.getMessage()); //$NON-NLS-1$ throw new JavaModelException(rte, IJavaModelStatusConstants.CORE_EXCEPTION); } } catch (CoreException e) { StudioLogger.error(this.getClass(), "Error creating IDocument from java file: " + java + " message: " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } finally { theMonitor.done(); } } }
From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java
License:Open Source License
private void flushZipFiles() throws JavaModelException { Method flushZipFilesMethod;//w w w.java 2 s .com JavaModelManager manager = JavaModelManager.getJavaModelManager(); try { try { // Eclipse 3.5.1 flushZipFilesMethod = JavaModelManager.class.getMethod("flushZipFiles", new Class[0]); flushZipFilesMethod.invoke(manager, new Object[0]); } catch (NoSuchMethodException e) { // Eclipse 3.5.2 try { flushZipFilesMethod = JavaModelManager.class.getMethod("flushZipFiles", new Class[] { Object.class }); flushZipFilesMethod.invoke(manager, new Object[] { this }); } catch (NoSuchMethodException e1) { throw new JavaModelException(e1, IJavaModelStatusConstants.CORE_EXCEPTION); } } } catch (SecurityException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalArgumentException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalAccessException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (InvocationTargetException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } }
From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java
License:Open Source License
private void cacheZipFiles() throws JavaModelException { Method cacheZipFilesMethod;//from www . jav a 2 s . com JavaModelManager manager = JavaModelManager.getJavaModelManager(); try { try { // Eclipse 3.5.1 cacheZipFilesMethod = JavaModelManager.class.getMethod("cacheZipFiles", new Class[0]); cacheZipFilesMethod.invoke(manager, new Object[0]); } catch (NoSuchMethodException e) { // Eclipse 3.5.2 try { cacheZipFilesMethod = JavaModelManager.class.getMethod("cacheZipFiles", new Class[] { Object.class }); cacheZipFilesMethod.invoke(manager, new Object[] { this }); } catch (NoSuchMethodException e1) { throw new JavaModelException(e1, IJavaModelStatusConstants.CORE_EXCEPTION); } } } catch (SecurityException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalArgumentException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalAccessException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (InvocationTargetException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } }
From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java
License:Open Source License
private JavaElement getType(JavaElement type, String typeName) { try {/*from ww w. j a va 2s . c om*/ try { Constructor cons = SourceType.class .getDeclaredConstructor(new Class[] { JavaElement.class, String.class }); cons.setAccessible(true); Object obj = cons.newInstance(new Object[] { type, typeName }); return (JavaElement) obj; } catch (SecurityException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (NoSuchMethodException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalArgumentException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (InstantiationException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (IllegalAccessException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } catch (InvocationTargetException e) { throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } } catch (JavaModelException jme) { AspectJPlugin.getDefault().getLog().log(jme.getStatus()); } return null; }
From source file:org.eclipse.andmore.android.generatecode.JavaCodeModifier.java
License:Apache License
/** * Insert code into the class (activity / fragment) and adds imports if * necessary.//from w ww . j a v a 2 s . co m * * @throws JavaModelException * Thrown if there were problems parsing the java file. */ public void insertCode(IProgressMonitor monitor, IEditorPart editor) throws JavaModelException { final SubMonitor theMonitor = SubMonitor.convert(monitor); IResource resource = codeGeneratorData.getResource(); if (resource instanceof IFile) { IFile java = (IFile) resource; AndmoreLogger.info("Trying to insert code for class: " + java.getFullPath() + " based on resource " //$NON-NLS-1$ + getDataResource()); IDocument document = null; try { document = ((AbstractTextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput()); final ICompilationUnit compUnit = getCodeGeneratorData().getICompilationUnit(); CompilationUnit cpU = getCodeGeneratorData().getCompilationUnit(); try { cpU.recordModifications(); initVariables(); codeGenerators.clear(); codeGenerators = populateListOfCodeGenerators(getCodeGeneratorData()); theMonitor.beginTask(CodeUtilsNLS.JavaViewBasedOnLayoutModifier_InsertingCode, 1000 * getNumberOfTasks()); callCodeGenerators(theMonitor, java); addImportsIfRequired(theMonitor, cpU); Map<?, ?> mapOptions = JavaCore.create(java.getProject()).getOptions(true); final TextEdit edit = cpU.rewrite(document, mapOptions); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { try { compUnit.applyTextEdit(edit, theMonitor); } catch (JavaModelException e) { AndmoreLogger.error(this.getClass(), "Error applying changes: " + e.getMessage(), //$NON-NLS-1$ e); } } }); } catch (CoreException e) { AndmoreLogger.error(this.getClass(), "Error changing AST activity/fragment: " + e.getMessage()); //$NON-NLS-1$ throw new JavaModelException(e); } catch (RuntimeException rte) { AndmoreLogger.error(this.getClass(), "Error changing AST activity/fragment: " + rte.getMessage()); //$NON-NLS-1$ throw new JavaModelException(rte, IJavaModelStatusConstants.CORE_EXCEPTION); } } catch (CoreException e) { AndmoreLogger.error(this.getClass(), "Error creating IDocument from java file: " + java + " message: " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); } finally { theMonitor.done(); } } }
From source file:org.eclipse.che.jdt.CodeAssist.java
License:Open Source License
@SuppressWarnings("unchecked") public Proposals computeAssistProposals(IJavaProject project, String fqn, int offset, List<Problem> problems) throws CoreException { ICompilationUnit compilationUnit;//from w ww .jav a 2 s. c o m IType type = project.findType(fqn); if (type == null) { return null; } if (type.isBinary()) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't calculate Quick Assist on binary file")); } else { compilationUnit = type.getCompilationUnit(); } IBuffer buffer = compilationUnit.getBuffer(); ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); bufferManager.connect(compilationUnit.getPath(), LocationKind.IFILE, new NullProgressMonitor()); ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(compilationUnit.getPath(), LocationKind.IFILE); IDocument document = textFileBuffer.getDocument(); TextViewer viewer = new TextViewer(document, new Point(offset, 0)); AssistContext context = new AssistContext(compilationUnit, offset, 0); ArrayList proposals = new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, problems, true, true, proposals); return convertProposals(offset, compilationUnit, viewer, proposals); }
From source file:org.eclipse.che.plugin.java.server.CodeAssist.java
License:Open Source License
private ICompilationUnit prepareCompilationUnit(IJavaProject project, String fqn) throws JavaModelException { ICompilationUnit compilationUnit;//from ww w . ja va 2 s .c o m IType type = project.findType(fqn); if (type == null) { throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't find a file: " + fqn)); } if (type.isBinary()) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't organize imports on binary file")); } else { compilationUnit = type.getCompilationUnit(); } return compilationUnit; }