List of usage examples for org.eclipse.jdt.core IJavaElement getHandleIdentifier
String getHandleIdentifier();
From source file:edu.buffalo.cse.green.editor.model.RootModel.java
License:Open Source License
/** * @param ancestor - The given element.//from ww w .ja va 2 s.co m * @return true if the given element is an ancestor of another element in * the editor; false otherwise. */ public boolean ancestorInEditor(IJavaElement ancestor) { List<IJavaElement> elements = getElementsOfKind(ancestor.getElementType()); for (IJavaElement element : elements) { if (element.getHandleIdentifier().equals(ancestor.getHandleIdentifier())) { return true; } } return false; }
From source file:edu.buffalo.cse.green.JavaModelListener.java
License:Open Source License
/** * Compares two elements by their handle identifiers. * //from ww w . jav a2s.co m * @param e1 - An element to compare. * @param e2 - An element to compare. * @return True if the elements have the same handles, false otherwise. */ public static boolean sameElements(IJavaElement e1, IJavaElement e2) { if (e1 == null || e2 == null) return false; return (e1.getHandleIdentifier().equals(e2.getHandleIdentifier())); }
From source file:edu.buffalo.cse.green.JavaModelListener.java
License:Open Source License
/** * @see edu.buffalo.cse.green.RefactorHandler#handleMove(edu.buffalo.cse.green.editor.model.RootModel, org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement) */// ww w . j a v a 2 s.c o m public void handleMove(RootModel root, E sourceElement, E targetElement) { // get all types represented in the diagram String scuId = sourceElement.getHandleIdentifier(); String tcuId = targetElement.getHandleIdentifier(); String scuName = scuId.substring(scuId.indexOf('{') + 1, scuId.indexOf(".java")); String tcuName = tcuId.substring(tcuId.indexOf('{') + 1, tcuId.indexOf(".java")); List<IJavaElement> cuTypes = root.getElementsOfKind(TYPE); // see if any types belong to the compilation unit // that is undergoing the move event for (IJavaElement oType : cuTypes) { if (JavaModelListener.sameElements(sourceElement, oType.getAncestor(COMPILATION_UNIT))) { String oId = oType.getHandleIdentifier(); String oName = oId.substring(oId.indexOf('[')); oName = oName.replaceAll("\\[" + scuName, "[" + tcuName); IJavaElement nType = JavaCore.create(tcuId + oName); TypeModel oModel = (TypeModel) root.getModelFromElement(oType); TypeModel nModel = root.createTypeModel((IType) nType); if (oModel != null) { // TODO We tried to catch a ResourceException, // but it is caught in MemberModel oModel.removeFromParent(); nModel.setLocation(oModel.getLocation()); nModel.setSize(oModel.getSize()); } } } }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * Converts an AspectJ (IProgramElement) handle to its Java (IJavaElement) * counterpart./*from w w w . j av a 2s .c o m*/ * @param ajHandle AspectJ Model (IProgramElement) handle * @return the Java Model (IJavaElement) counterpart to ajHandle */ private String ajHandleToJavaHandle(String ajHandle) { IJavaElement jElement = ajModel.programElementToJavaElement(ajHandle); return jElement.getHandleIdentifier(); }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * @param ajElement/* w w w . ja v a2 s . com*/ * @param child */ private void printChildInfo(IProgramElement ajElement, IProgramElement child) { String childType = child.getKind().toString(); String childHandle = child.getHandleIdentifier(); IJavaElement jChild = programElementToJavaElement(child); String jChildHandle = jChild.getHandleIdentifier(); //BEGIN TEMPORARY STUFF System.err.println(ajElement.getName() + " " + childType + " " + child.getName()); // System.out.println(" bytecode name:" + child.getBytecodeName()); // System.out.println(" bytecode sig:" + child.getBytecodeSignature()); // System.out.println(" corresponding type:" + child.getCorrespondingType(false)); // System.out.println(" fully qual'd corresponding type:" + child.getCorrespondingType(true)); // System.out.println(" declaring type:" + child.getDeclaringType()); // System.out.println(" details:" + child.getDetails()); // System.out.println(" formal comment:" + child.getFormalComment()); System.err.println(" Program Element handle:" + childHandle); System.err.println(" Java Element handle:" + jChildHandle); // System.out.println(" package name:" + child.getPackageName()); // System.out.println(" raw modifiers:" + child.getRawModifiers()); // System.out.println(" source signature:" + child.getSourceSignature()); // printList(child.getParameterNames(), "parm names"); // printList(child.getParameterSignatures(), "parm sigs"); // printList(child.getParameterSignaturesSourceRefs(), "parm sig source refs"); // printList(child.getParameterTypes(), "parm types"); // printList(child.getChildren(), "children"); //END TEMPORARY STUFF }
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. * //from w w w. j a v a 2 s . c om * @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:edu.wpi.cs.jburge.SEURAT.SEURATElementChangedManager.java
License:Open Source License
/** * Checks whether an association is in the DB. If it is, updates the association. * Used for compilation unit children.//from w w w . j a v a 2 s . com * * @param elt - the element that needs to be checked/updated * @param newRes - the new resource * @param oldName - the old name of the element, if it differed from the new name (this only happens * for constructors when the class name is changed), and null if not */ private void checkAssocAndUpdate(IJavaElement elt, String newRes, String oldName) { Association asc = new Association(); if (oldName != null) { // if old name differed from new name, get it from DB using old name asc.fromDatabase(oldName); } else { asc.fromDatabase(elt.getElementName()); } if (asc.getAlt() != -1) { // Field was in DB, set variables IJavaElement subNewElt = elt; String subNewArtName = subNewElt.getElementName(); String subNewArt = subNewElt.getHandleIdentifier(); // Update them asc.setArtifact(subNewArt); asc.setResource(newRes); asc.setArtName(subNewArtName); System.out.println(" (child of comp unit) became " + subNewArt); // Send the update to the DB asc.toDatabase(subNewArtName); // name should be unchanged } }
From source file:fr.imag.adele.cadse.cadseg.eclipse.RenameJavaClassMappingOperartion.java
License:Apache License
protected void refactoringRename(String id, String... params) { try {// w w w. j av a 2s.c o m IJavaElement oldElement = getJavaElement(_oldcontext); IJavaElement newElement = getJavaElement(_newcontext); Map<String, String> arguments = new HashMap<String, String>(); for (int i = 0; i < params.length;) { String k = params[i++]; String v = params[i++]; arguments.put(k, v); } arguments.put("name", newElement.getElementName()); arguments.put("input", oldElement.getHandleIdentifier()); RenameJavaElementDescriptor javaElementDescriptor = new RenameJavaElementDescriptor(id, id == IJavaRefactorings.RENAME_JAVA_PROJECT ? null : oldElement.getResource().getProject().getName(), _desc, _desc, arguments, 0); javaElementDescriptor.setJavaElement(oldElement); javaElementDescriptor.setNewName(newElement.getElementName()); int type = oldElement.getElementType(); switch (type) { case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.TYPE: javaElementDescriptor.setUpdateQualifiedNames(true); break; default: } if (oldElement.getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT) { javaElementDescriptor.setUpdateReferences(true); } RenameSupport renameSupport = RenameSupport.create(javaElementDescriptor); Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); renameSupport.perform(parent, new ProgressMonitorDialog(parent)); } catch (CoreException e1) { e1.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:navclus.userinterface.classdiagram.java.analyzer.RootModel.java
License:Open Source License
public boolean addElement(IType topType, IJavaElement locElement) { boolean bExist = false; if (topType == null) return false; if (locElement == null) return false; if (topType.getHandleIdentifier().equals(locElement.getHandleIdentifier())) return false; // finding the node having itypeTop // if finding the node, add the javaelement methods IType locType = (IType) locElement.getAncestor(IJavaElement.TYPE); TypeNode topNode = rootNode.findNode(topType); TypeNode locNode = rootNode.findNode(locType); if (topNode == null) return false; boolean bCreateType = false; if (locNode == null) { locNode = createType(locType);//from www .j a v a 2 s .com // rootNode.synchronizeNodesinView(); bCreateType = true; } if (locNode != null) { if (!topType.getHandleIdentifier().equals(locType.getHandleIdentifier())) { topNode.embeddedTypes.add(locType); TypeHistory.setPreType(locType); } if (locElement instanceof IMethod) { bExist = locNode.addMethod((IMethod) locElement); } else if (locElement instanceof IField) { bExist = locNode.addField((IField) locElement); } else if (bCreateType) return true; else return false; } if (bExist) { return true; } else return false; }
From source file:navclus.userinterface.classdiagram.java.analyzer.TypeModel.java
License:Open Source License
public boolean removeElement(IType topType, IJavaElement locElement) { if (topType == null) return false; if (locElement == null) return false; if (topType.getHandleIdentifier().equals(locElement.getHandleIdentifier())) return false; // finding the node having itypeTop // if finding the node, add the javaelement methods IType locType = (IType) locElement.getAncestor(IJavaElement.TYPE); TypeNode topNode = rootNode.findNode(topType); TypeNode locNode = rootNode.findNode(locType); if (topNode == null) return false; if (locNode == null) return false; if (IsRemoved(locNode, locElement)) { // rootNode.synchronizeNodesinView(); return true; } else/*from w ww. ja v a 2 s . c o m*/ return false; }