List of usage examples for org.eclipse.jdt.core JavaModelException toString
@Override
public String toString()
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
private void commitFile(FileData fd, boolean refresh, boolean save, IvyXmlWriter xw) { if (xw != null) { xw.begin("FILE"); xw.field("NAME", fd.getFileName()); }//from ww w .ja v a 2s . c o m try { fd.commit(refresh, save); } catch (JavaModelException e) { if (xw != null) xw.field("ERROR", e.toString()); } if (xw != null) xw.end("FILE"); }
From source file:edu.wpi.cs.jburge.SEURAT.SEURATElementChangedManager.java
License:Open Source License
/** * Determines whether a change occurred to an associated artifact, and if it did, * handles the change. It basically works by saving the first element it gets and * mapping it to a corresponding element later on (provided that the elements are actually * associated with some alternative). Two exceptions come up: one, if it's a compilation unit, * we just use the getMovedToElement() method to take care of the mapping for us (we don't have * access to this for single methods due to the confusing/arcane way they decided to code * java element changes). The other exception is also for compilation units- we have to manually check * the java elements attached to it such as methods and fields to see if any of those are associated * and handle the changes if they are, because we don't get deltas for them. * /* ww w . jav a2 s .com*/ * @param change - the possible change, an IJavaElementDelta */ private void handleChange(IJavaElementDelta change) { System.out .println("HandleChange: " + change.getElement() + " " + change.toString() + " " + change.getKind()); //System.out.println("Saved Delta: " + savedDelta.getElement() + " " + savedDelta.toString() + " " + savedDelta.getKind()); IJavaElement movedTo = change.getMovedToElement(); if (change.getKind() == IJavaElementDelta.ADDED || change.getKind() == IJavaElementDelta.REMOVED) { if (change.getKind() == IJavaElementDelta.REMOVED && savedDelta == null && movedTo == null) { checkDeltaAndSave(change); } else if (change.getKind() == IJavaElementDelta.ADDED && savedDelta == null && movedTo == null) { // always save this kind of delta, can't check if in DB without reference to removed delta savedDelta = change; System.out.println("Saved a delta"); } else { IJavaElement oldElt = null; IJavaElement newElt = null; if (change.getKind() == IJavaElementDelta.ADDED) { // get the saved added delta oldElt = savedDelta.getElement(); newElt = change.getElement(); } else { // change.getKind() == IJavaElementDelta.REMOVED if (movedTo != null) { // process the move checkDeltaAndSave(change); // in this case we're not really saving, just checking newElt = movedTo; oldElt = change.getElement(); } else { // check the removed delta, then get the saved added delta checkDeltaAndSave(change); if (savedDelta != null) { // sanity check newElt = savedDelta.getElement(); oldElt = change.getElement(); } } } // Get the saved association and the old artName Association ourAssoc = savedAssoc; String oldArtName = oldElt.getElementName(); // Reset the saved delta and association savedDelta = null; savedAssoc = null; // Make sure the association is in the database if (ourAssoc != null && ourAssoc.getAlt() != -1) { // Find the artifact itself IResource newResource = null; int cstart = 0; IField[] fields = null; IMethod[] methods = null; try { ICompilationUnit compUnit = null; if (newElt.getElementType() != IJavaElement.COMPILATION_UNIT) { newResource = newElt.getUnderlyingResource(); compUnit = (ICompilationUnit) newElt.getAncestor(IJavaElement.COMPILATION_UNIT); } else { newResource = newElt.getCorrespondingResource(); compUnit = (ICompilationUnit) newElt; } IType[] myTypes = compUnit.getTypes(); boolean found = false; int i = 0; while ((!found) && i < myTypes.length) { //selected item was the class itself if (newElt.getElementType() == IJavaElement.COMPILATION_UNIT) { if (myTypes[i].isClass()) { found = true; cstart = myTypes[i].getNameRange().getOffset(); fields = myTypes[i].getFields(); methods = myTypes[i].getMethods(); } } else if (newElt.getElementType() == IJavaElement.FIELD) { IField[] myFields = myTypes[i].getFields(); for (int j = 0; j < myFields.length; j++) { if (myFields[j].getElementName().compareTo(newElt.getElementName()) == 0) { found = true; cstart = myFields[j].getNameRange().getOffset(); } } } else if (newElt.getElementType() == IJavaElement.METHOD) { IMethod[] myMethods = myTypes[i].getMethods(); for (int j = 0; j < myMethods.length; j++) { if (myMethods[j].getElementName().compareTo(newElt.getElementName()) == 0) { found = true; cstart = myMethods[j].getNameRange().getOffset(); } } } i++; } //end while } catch (JavaModelException jme) { System.err.println(jme.toString()); } System.out.println("DEBUG: newresource " + newResource.getName() + " cstart " + cstart); // Get new values for association data String newRes = newResource.getName(); String newArtName = newElt.getElementName(); String newArt = newElt.getHandleIdentifier(); IResource oldResource = null; // Now, the time-consuming part. If this is a compilation unit, we need to go through // all of its fields and methods and if they have associations, update them. if (newElt.getElementType() == IJavaElement.COMPILATION_UNIT) { for (int i = 0; i < fields.length; i++) { checkAssocAndUpdate(fields[i], newRes, null); } for (int i = 0; i < methods.length; i++) { String oldSubArtName = methods[i].getElementName(); String oldSubArtNameJava = oldSubArtName + ".java"; if ((oldSubArtName == oldArtName || oldSubArtNameJava == oldArtName) && oldArtName != newArtName) { // Names of old comp unit and old method are same; this is a constructor, and its name has changed checkAssocAndUpdate(methods[i], newRes, oldSubArtName); } else { checkAssocAndUpdate(methods[i], newRes, null); } } } // If we're not dealing with a compilation unit, a single method/field was renamed or moved. // If it was moved we need to know the old resource to change resource properties (it might not // have rationale anymore) so we save that now. else { oldResource = oldElt.getResource(); } // Update them ourAssoc.setArtifact(newArt); ourAssoc.setResource(newRes); ourAssoc.setArtName(newArtName); System.out.println("oldArt became " + newArt); System.out.println("oldRes became " + newRes); System.out.println(oldArtName + " became " + newArtName); // Send the update to the DB ourAssoc.toDatabase(oldArtName); // Update the marker- this will sometimes give us "resource tree locked" exceptions. // However, in the cases where it does, we're making changes to a compilation unit // and the markers will stay where they are. try { IMarker ratM = newResource.createMarker("SEURAT.ratmarker"); String markD = ourAssoc.getMsg(); ratM.setAttribute(IMarker.MESSAGE, markD); ratM.setAttribute(IMarker.CHAR_START, cstart); ratM.setAttribute(IMarker.CHAR_END, cstart + 1); ratM.setAttribute(IMarker.SEVERITY, 0); System.out.println(cstart); Alternative ourAlt = (Alternative) RationaleDB.getRationaleElement(ourAssoc.getAlt(), RationaleElementType.ALTERNATIVE); ratM.setAttribute("alternative", ourAlt.getName()); } catch (CoreException e) { System.err.println(e.toString()); } // If the element was moved, remove the persistent property from the old resource. // This is a hack, because if there is associated rationale remaining in the old resource // it still removes the decorator, but the next time restoreAssociations is called it will // be back. I couldn't see a better way to do it short of rewriting the decorator and/or resource properties manager. if (oldResource != null) { // it will be null for a compilation unit because we didn't set it SEURATResourcePropertiesManager.addPersistentProperty(oldResource, "Rat", "false"); SEURATDecoratorManager.addSuccessResources(oldResource); } // add property for the new resource in all cases SEURATResourcePropertiesManager.addPersistentProperty(newResource, "Rat", "true"); SEURATDecoratorManager.addSuccessResources(newResource); } } } }
From source file:org.eclipse.ant.internal.ui.datatransfer.AntBuildfileExportPage.java
License:Open Source License
/** * Convert Eclipse Java projects to Ant build files. Displays error dialogs. *//*from w w w . j av a 2 s . c o m*/ public boolean generateBuildfiles() { setErrorMessage(null); final List<String> projectNames = new ArrayList<>(); final Set<IJavaProject> projects; try { projects = getProjects(true); if (projects.size() == 0) { return false; } } catch (JavaModelException e) { AntUIPlugin.log(e); setErrorMessage(MessageFormat.format(DataTransferMessages.AntBuildfileExportPage_10, new Object[] { e.toString() })); return false; } IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor pm) throws InterruptedException { SubMonitor localmonitor = SubMonitor.convert(pm, DataTransferMessages.AntBuildfileExportPage_creating_build_files, projects.size()); Exception problem = null; try { BuildFileCreator.setOptions(buildfilenameText.getText(), junitdirText.getText(), compatibilityCheckbox.getSelection(), compilerCheckbox.getSelection()); projectNames.addAll(BuildFileCreator.createBuildFiles(projects, getShell(), localmonitor.newChild(projects.size()))); } catch (JavaModelException e) { problem = e; } catch (TransformerConfigurationException e) { problem = e; } catch (ParserConfigurationException e) { problem = e; } catch (TransformerException e) { problem = e; } catch (IOException e) { problem = e; } catch (CoreException e) { problem = e; } if (problem != null) { AntUIPlugin.log(problem); setErrorMessage(MessageFormat.format(DataTransferMessages.AntBuildfileExportPage_10, new Object[] { problem.toString() })); } } }; try { getContainer().run(false, false, runnable); } catch (InvocationTargetException e) { AntUIPlugin.log(e); return false; } catch (InterruptedException e) { AntUIPlugin.log(e); return false; } if (getErrorMessage() != null) { return false; } return true; }
From source file:org.eclipse.gmt.mod.infra.common.core.internal.utils.FileUtils.java
License:Open Source License
/** * Whether the given workspace file is in its project's output location * (e.g. "bin" directory)// w w w . ja v a2 s . co m */ public static boolean isInOutputLocation(final IFile file) { try { IJavaProject javaProject = JavaCore.create(file.getProject()); if (javaProject != null) { if (javaProject.getOutputLocation().isPrefixOf(file.getFullPath())) { return true; } IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : rawClasspath) { if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(file.getFullPath())) { return true; } } } } } catch (JavaModelException e) { log.error(e.toString()); //FP } return false; }
From source file:org.neuro4j.studio.core.util.ParameterDefinitionLoader.java
License:Apache License
private void processClassInProject(IProject project, String className, String inOut, Map<String, ParameterDefinition> definitions) { IJavaProject javaProject = JavaCore.create(project); IType parentType = null;//from w w w. j a va2 s . com try { parentType = javaProject.findType(className); if (parentType != null) { IAnnotation an = parentType.getAnnotation("ParameterDefinitionList"); IMemberValuePair[] members = an.getMemberValuePairs(); if (members != null && members.length >= 1) { for (IMemberValuePair para : members) { if (!para.getMemberName().equals(inOut)) { continue; } Object[] obj = (Object[]) para.getValue(); for (Object ob : obj) { Map<String, String> variableMap = new HashMap<String, String>(); IAnnotation parameterDefinitionAnnotation = (IAnnotation) ob; IMemberValuePair[] parameterDefinitionPara = parameterDefinitionAnnotation .getMemberValuePairs(); String name = null; String type = null; Boolean optional = Boolean.TRUE; parse(parentType.getCompilationUnit().getSource().toCharArray(), variableMap); for (IMemberValuePair p : parameterDefinitionPara) { String memberName = p.getMemberName(); if ("name".equals(memberName)) { name = (String) p.getValue(); String nameFromMap = variableMap.get(name); if (nameFromMap != null) { name = nameFromMap; } } else if ("type".equals(memberName)) { type = (String) p.getValue(); } else if ("isOptional".equals(memberName)) { optional = (Boolean) p.getValue(); } } ParameterDefinition ioParameter = new ParameterDefinitionImpl(name, type, optional); definitions.put(ioParameter.name(), ioParameter); } return; } } } } catch (JavaModelException e1) { Neuro4jCorePlugin.logErrorMessage(e1.toString(), null); } return; }
From source file:org.sf.feeling.decompiler.editor.DecompilerSourceMapper.java
License:Open Source License
protected String getArchivePath(IPackageFragmentRoot root) { String archivePath = null;//from ww w .j a va2s. co m IResource resource; try { if ((resource = root.getUnderlyingResource()) != null) // jar in workspace archivePath = resource.getLocation().toOSString(); else // external jar archivePath = root.getPath().toOSString(); } catch (JavaModelException e) { throw new RuntimeException("Unexpected Java model exception: " //$NON-NLS-1$ + e.toString()); } return archivePath; }