List of usage examples for org.eclipse.jdt.core ICompilationUnit getPrimary
ICompilationUnit getPrimary();
From source file:com.google.gdt.eclipse.core.markers.quickfixes.JavaMarkerResolutionGenerator.java
License:Open Source License
public IMarkerResolution[] getResolutions(IMarker marker) { if (!hasResolutions(marker)) { return NO_RESOLUTIONS; }//from ww w . ja v a 2 s.c o m ICompilationUnit cu = getCompilationUnit(marker); if (cu != null) { IEditorInput input = new FileEditorInput((IFile) cu.getPrimary().getResource()); if (input != null) { int offset = marker.getAttribute(IMarker.CHAR_START, -1); int length = marker.getAttribute(IMarker.CHAR_END, -1) - offset; int problemId = marker.getAttribute(IJavaModelMarker.ID, -1); boolean isError = (marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR); String[] arguments = CorrectionEngine.getProblemArguments(marker); IProblemLocation location = new ProblemLocation(offset, length, problemId, arguments, isError, null); IInvocationContext context = new AssistContext(cu, offset, length); IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0]; try { proposals = getCorrections(context, new IProblemLocation[] { location }); } catch (CoreException e) { CorePluginLog.logError(e); } int nProposals = proposals.length; IMarkerResolution[] resolutions = new IMarkerResolution[nProposals]; for (int i = 0; i < nProposals; i++) { resolutions[i] = new QuickFixCompletionProposalWrapper(cu, offset, length, proposals[i]); } return resolutions; } } return NO_RESOLUTIONS; }
From source file:de.fu_berlin.inf.jtourbus.view.TourChangeListener.java
License:Open Source License
void visitInternal(IProgressMonitor pm, IJavaElementDelta delta) { IJavaElement elem = delta.getElement(); IJavaElementDelta[] children = delta.getAffectedChildren(); if (pm != null) pm.beginTask("", children.length + 2); if ((delta.getFlags() & IJavaElementDelta.F_CHILDREN) != 0) { if (delta.getKind() != IJavaElementDelta.CHANGED) { throw new RuntimeException("ASSERT: CHILDREN should always be CHANGE"); }/* ww w .ja v a 2s. c o m*/ for (int i = 0; i < children.length; i++) { visit(pm, children[i]); } return; } switch (delta.getKind()) { case IJavaElementDelta.ADDED: { if (!((delta.getFlags() & IJavaElementDelta.F_CHILDREN) == 0)) throw new RuntimeException("ASSERT: ADDED has no children"); switch (elem.getElementType()) { case IJavaElement.JAVA_MODEL: throw new RuntimeException("ASSERT: Adding Java Model not possible"); case IJavaElement.JAVA_PROJECT: throw new RuntimeException("ASSERT: Adding Java Project not possible"); case IJavaElement.PACKAGE_FRAGMENT_ROOT: // The user added a source folder for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.PACKAGE_FRAGMENT: // The user inserted a packaged for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.COMPILATION_UNIT: { ICompilationUnit cu = (ICompilationUnit) elem; if (cu.getPrimary().equals(cu)) { for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); } return; } default: ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); return; } } case IJavaElementDelta.REMOVED: if (!((delta.getFlags() & IJavaElementDelta.F_CHILDREN) == 0)) throw new RuntimeException("REMOVED has children"); switch (elem.getElementType()) { case IJavaElement.JAVA_MODEL: throw new RuntimeException("ASSERT: Java Model not possible"); case IJavaElement.JAVA_PROJECT: fContentProvider.fTourPlan.removeAll(); return; case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: fContentProvider.fTourPlan.removeAll(); for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getJavaProject().getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.COMPILATION_UNIT: { ICompilationUnit cu = (ICompilationUnit) elem; if (cu.getPrimary().equals(cu)) { fContentProvider.fTourPlan.removeCU(cu); } return; } default: { ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); return; } } case IJavaElementDelta.CHANGED: // F_CONTENT && F_FINE_GRAINED if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0 && (delta.getFlags() & IJavaElementDelta.F_FINE_GRAINED) != 0) { ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); } // Closing without saving will trigger this event. We thus re-read // the file. if ((delta.getFlags() & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0) { ICompilationUnit cu = (ICompilationUnit) delta.getElement(); /* FIXME */ redoCU(cu, pm); } break; } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
void renameResource(String proj, String bid, String file, String newname, IvyXmlWriter xw) throws BedrockException { FileData fd = file_map.get(file);//w w w .j a va2 s. c om ICompilationUnit icu; icu = fd.getEditableUnit(bid); icu = icu.getPrimary(); try { icu.rename(newname, true, new NullProgressMonitor()); } catch (JavaModelException e) { throw new BedrockException("Problem renaming compilation unit: " + e, e); } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
/********************************************************************************/ private synchronized FileData findFile(String proj, String file, String bid, String id) throws BedrockException { FileData fd = file_map.get(file);/*from ww w .j av a 2 s .com*/ if (fd == null) { ICompilationUnit icu = null; icu = our_plugin.getProjectManager().getCompilationUnit(proj, file); if (icu == null && proj != null) { icu = our_plugin.getProjectManager().getCompilationUnit(null, file); if (icu != null) proj = null; } if (icu == null) return null; BedrockPlugin.logD("START FILE " + proj + " " + file + " " + bid + " " + icu.isWorkingCopy() + " " + icu.hasResourceChanged() + " " + icu.isOpen() + " " + icu.getOwner() + " " + System.identityHashCode(icu) + " " + System.identityHashCode(icu.getPrimary())); icu = icu.getPrimary(); fd = new FileData(proj, file, icu); file_map.put(file, fd); } if (id != null) fd.setCurrentId(bid, id); return fd; }
From source file:org.dyno.visual.swing.parser.DefaultSourceParser.java
License:Open Source License
public WidgetAdapter parse(ICompilationUnit unit, IProgressMonitor monitor) throws ParserException { try {//from www .j a v a2s. c o m IType[] types = unit.getPrimary().getAllTypes(); for (IType type : types) { if (type.isClass() && Flags.isPublic(type.getFlags())) { WidgetAdapter result = processType(unit.getPrimary(), type); if (result != null) return result; } } } catch (JavaModelException jme) { ParserPlugin.getLogger().error(jme); throw new ParserException(jme); } return null; }
From source file:org.eclipse.jst.common.jdt.internal.integration.ui.WTPUIWorkingCopyManager.java
License:Open Source License
protected IEditorInput getEditorInput(IJavaElement element) throws JavaModelException { IJavaElement localElement = element; while (localElement != null) { switch (localElement.getElementType()) { case IJavaElement.COMPILATION_UNIT: { ICompilationUnit cu = (ICompilationUnit) localElement; if (cu.isWorkingCopy()) cu = cu.getPrimary(); IResource resource = cu.getUnderlyingResource(); if (resource.getType() == IResource.FILE) return new FileEditorInput((IFile) resource); break; }//from w w w. j a v a 2 s . co m case IJavaElement.CLASS_FILE: return new InternalClassFileEditorInput((IClassFile) localElement); } localElement = localElement.getParent(); } return null; }
From source file:org.eclipse.jst.common.jdt.internal.integration.ui.WTPUIWorkingCopyManager.java
License:Open Source License
/** * Returns the working copy remembered for the compilation unit encoded in the given editor * input.// ww w . ja v a 2s. com * * @param input * ICompilationUnit * @return the working copy of the compilation unit, or <code>null</code> if the input does * not encode an editor input, or if there is no remembered working copy for this * compilation unit */ @Override protected org.eclipse.jdt.core.ICompilationUnit primGetWorkingCopy(ICompilationUnit cu) throws CoreException { if (cu == null) { return cu; } ICompilationUnit primary = cu.getPrimary(); ICompilationUnit newCU = getNewCompilationUnitWorkingCopy(primary); if (newCU != null) return newCU; IEditorInput editorInput = primGetEditorInput(primary); if (editorInput == null) { editorInput = getEditorInput(cu); syncConnect(editorInput, cu); } if (cu.isWorkingCopy()) return cu; return javaWorkingCopyManager.getWorkingCopy(editorInput); }
From source file:org.eclipse.jst.common.jdt.internal.integration.WTPWorkingCopyManager.java
License:Open Source License
/** * This will delete// w w w . j a v a 2s .c om * * @cu from the workbench and fix the internal references for this working copy manager. */ public void delete(final ICompilationUnit cu, final IProgressMonitor monitor) { ICompilationUnit localCU = cu; if (localCU.isWorkingCopy()) localCU = localCU.getPrimary(); addDeletedCompilationUnit(localCU); try { localCU.delete(false, monitor); } catch (JavaModelException e) { if (e.getStatus().getCode() != org.eclipse.jdt.core.IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(e); } }
From source file:org.eclipse.jst.common.jdt.internal.integration.WTPWorkingCopyManager.java
License:Open Source License
protected void discardOriginalNewCompilationUnits() { if (getOriginalNewCompilationUnits().isEmpty()) return;//from ww w . j ava 2 s.co m List cus = getOriginalNewCompilationUnits(); ICompilationUnit cu; ICompilationUnit wc = null; for (int i = 0; i < cus.size(); i++) { cu = (ICompilationUnit) cus.get(i); if (cu.isWorkingCopy()) { wc = cu; cu = wc.getPrimary(); } primDelete(cu); if (wc != null) try { wc.discardWorkingCopy(); } catch (JavaModelException e) { Logger.getLogger().logError(e); } } }
From source file:org.eclipse.jst.common.jdt.internal.integration.WTPWorkingCopyManager.java
License:Open Source License
/** * It is possible that we have already created this CompilationUnit and its working copy. If * this is the case, return our new working copy and do not create a new one. *///from w w w .j a va2 s. c o m protected ICompilationUnit getNewCompilationUnitWorkingCopy(ICompilationUnit cu) { if (hasNewCompilationUnit(cu)) { List list = getNeedsSavingCompilationUnits(); ICompilationUnit copy; for (int i = 0; i < list.size(); i++) { copy = (ICompilationUnit) list.get(i); if (cu.equals(copy.getPrimary())) return copy; } } return null; }