List of usage examples for org.aspectj.asm IProgramElement getSourceLocation
public ISourceLocation getSourceLocation();
From source file:org.caesarj.compiler.asm.StructureModelDump.java
License:Open Source License
protected void printNodeHeader(PrintStream outArg, IProgramElement node) { outArg.print("[" + node.getKind() + "] " + node.getName()); ISourceLocation srcLoc = node.getSourceLocation(); if (srcLoc != null) { outArg.print("(L " + srcLoc.getLine() + ") "); }// w w w . j a v a 2 s . c om }
From source file:org.caesarj.launching.CaesarLaunchShortcut.java
License:Open Source License
/** * Finds the source file node for the given filename in the structuremodel with * given root element.//from w w w . j av a2 s. c om * * @param root * @param filename absolute filename * @return */ protected IProgramElement findSourceFileNode(IProgramElement root, String filename) { if (root == null) { return null; } if (filename == null) { return null; } if (root.getKind() != null && root.getKind().isSourceFile()) { if (root.getSourceLocation().getSourceFile().getAbsolutePath().equals(filename)) { return root; } else { return null; } } else { IProgramElement res = null; for (Iterator it = root.getChildren().iterator(); it.hasNext() && res == null;) { res = findSourceFileNode((IProgramElement) it.next(), filename); } return res; } }
From source file:org.caesarj.ui.editor.CaesarJContentOutlinePage.java
License:Open Source License
/** * This method is called when the user select a node in the content tree. * It searches the location of this node and opens it in the editor. * //from ww w .j ava 2 s . c om * @see org.eclipse.jface.viewers.ISelectionChangedListener */ public void selectionChanged(SelectionChangedEvent event) { super.selectionChanged(event); /* ignore the first selection message that comes from initialization */ /* necessary for navigation by crosscutting links */ if (bFirstSelection) { bFirstSelection = false; return; } ISelection selection = event.getSelection(); if (selection.isEmpty()) { } else { Object item = ((IStructuredSelection) selection).getFirstElement(); if (item instanceof LinkNode) { if (((LinkNode) item).getType() == LinkNode.LINK_NODE_RELATIONSHIP) { return; } item = ((LinkNode) item).getTargetElement(); } IProgramElement selectedNode = (IProgramElement) item; ISourceLocation sourceLocation = selectedNode.getSourceLocation(); if (sourceLocation != null) { try { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath path = new Path(sourceLocation.getSourceFile().getAbsolutePath()); IResource resource = root.getFileForLocation(path); IMarker marker; if (resource != null) { marker = resource.createMarker(IMarker.MARKER); marker.setAttribute(IMarker.LINE_NUMBER, sourceLocation.getLine()); marker.setAttribute(IMarker.CHAR_START, sourceLocation.getColumn()); IDE.openEditor( CaesarPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker); } } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.caesarj.ui.editor.CaesarJContentOutlinePage.java
License:Open Source License
protected IProgramElement getInput(IProgramElement node) { String filename = null;// www.java 2 s .c om IEditorInput editorInput = this.caesarEditor.getEditorInput(); if (editorInput instanceof IPathEditorInput) { filename = ((IPathEditorInput) editorInput).getPath().toFile().getAbsolutePath(); } if (node == null) { return null; } if (filename == null) { return null; } IProgramElement r = null; //if (node.getName().equals(this.caesarEditor.getEditorInput().getName())) { if (node.getKind() != null && node.getKind().isSourceFile() && node.getSourceLocation().getSourceFile().getAbsolutePath().equals(filename)) { r = node; } else { IProgramElement res = null; for (Iterator it = node.getChildren().iterator(); it.hasNext() && res == null;) { res = getInput((IProgramElement) it.next()); } r = res; } return r; }
From source file:org.caesarj.ui.marker.AdviceMarkerGenerator.java
License:Open Source License
/** * Used to add Markers to the editor./*w ww.j a v a2 s . c o m*/ * @param node - CaesarProgramElement representing the Position where to add the Marker * @param relation - defines the Marker */ private void setMarkers(IProgramElement parent) { Logger.getLogger(this.getClass()).info("setMarkers() for relation node"); String messageLocal = ""; HashMap args = new HashMap(); List lElems = new ArrayList(); Iterator i = parent.getChildren().iterator(); while (i.hasNext()) { IProgramElement elem = (IProgramElement) i.next(); if (elem instanceof LinkNode) { // Add if it is a link node LinkNode node = (LinkNode) elem; Iterator i2 = node.getChildren().iterator(); while (i2.hasNext()) { IProgramElement elem2 = (IProgramElement) i2.next(); if (elem2 instanceof LinkNode) { // Add if it is a link node IProgramElement target = ((LinkNode) elem2).getTargetElement(); //if (!lElems.contains(target)) { if (target.getKind().equals(IProgramElement.Kind.ADVICE)) { args.put(AdviceMarker.ID, "AdviceLink"); } else { args.put(AdviceMarker.ID, "MethodeLink"); } if (!messageLocal.equals("")) { messageLocal += ", "; } if (target.getParent() != null) { String parentName = target.getParent().getName(); parentName = parentName.replaceAll("_Impl.*", ""); messageLocal += parentName + "." + target.getName(); } else { messageLocal += target.getName(); } lElems.add(target); //} } } } } if (!lElems.isEmpty()) { IResource resource = ProjectProperties .findResource(parent.getSourceLocation().getSourceFile().getAbsolutePath(), project); args.put(IMarker.LINE_NUMBER, new Integer(parent.getSourceLocation().getLine())); args.put(IMarker.MESSAGE, messageLocal); args.put(AdviceMarker.LINKS, lElems.toArray(new IProgramElement[0])); try { IMarker marker = resource.createMarker(AdviceMarker.ADVICEMARKER); marker.setAttributes(args); } catch (CoreException e) { Logger.getLogger(this.getClass()).error("FEHLER BEIM MARKER ERZEUGEN", e); //$NON-NLS-1$ } } }
From source file:org.eclipse.ajdt.core.javaelements.AdviceElement.java
License:Open Source License
protected Object createElementInfo() { try {/* w w w. j a v a2 s .c om*/ IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); AdviceElementInfo info = new AdviceElementInfo(); info.setAJExtraInfo(ipe.getExtraInfo()); info.setName(name.toCharArray()); info.setAJKind(IProgramElement.Kind.ADVICE); info.setAJModifiers(ipe.getModifiers()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); return info; } catch (Exception e) { // can fail for any of a number of reasons. // return null so that we can try again later. return null; } }
From source file:org.eclipse.ajdt.core.javaelements.AJCodeElement.java
License:Open Source License
public void initializeLocations() { // try the easy way: IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); ISourceLocation sloc = ipe.getSourceLocation(); if (sloc != null) { startLine = sloc.getLine();//w ww. j av a2 s. c om nameStart = sloc.getOffset(); if (sloc instanceof EclipseSourceLocation) { EclipseSourceLocation esloc = (EclipseSourceLocation) sloc; nameEnd = esloc.getEndPos(); } } // sometimes the start and end values are not set...so do it the hard way // so calculate it from the line if (nameStart <= 0 || nameEnd <= 0) { try { IOpenable openable = this.parent.getOpenableParent(); IBuffer buffer; if (openable instanceof AJCompilationUnit) { AJCompilationUnit ajCompUnit = (AJCompilationUnit) openable; ajCompUnit.requestOriginalContentMode(); buffer = openable.getBuffer(); ajCompUnit.discardOriginalContentMode(); } else { buffer = openable.getBuffer(); } String source = buffer.getContents(); int lines = 0; for (int i = 0; i < source.length(); i++) { if (source.charAt(i) == '\n') { lines++; if (lines == startLine - 1) { // starting remove white space i++; while (i < source.length() && (Character.isWhitespace(source.charAt(i)) && source.charAt(i) != '\n')) { i++; } nameStart = i; break; } } } for (int i = nameStart + 1; i < source.length(); i++) { if (source.charAt(i) == '\n' || source.charAt(i) == ';') { nameEnd = i - 1; break; } } nameStart = Math.min(nameStart, nameEnd); } catch (JavaModelException e) { } } }
From source file:org.eclipse.ajdt.core.javaelements.AspectElement.java
License:Open Source License
protected Object createElementInfo() { AspectElementInfo info = new AspectElementInfo(); info.setAJKind(IProgramElement.Kind.ASPECT); info.setHandle(this); info.setSourceRangeStart(0);/*from ww w. jav a2s . com*/ IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); if (ipe != null && ipe != IHierarchy.NO_STRUCTURE) { info.setAJExtraInfo(ipe.getExtraInfo()); info.setAJModifiers(ipe.getModifiers()); info.setFlags(getProgramElementModifiers(ipe)); info.setAJAccessibility(ipe.getAccessibility()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // info.setPrivileged(???); not setting this yet } return info; }
From source file:org.eclipse.ajdt.core.javaelements.BinaryAspectElementInfo.java
License:Open Source License
public BinaryAspectElementInfo(IProgramElement elt) { try {//from w w w . ja v a 2s. co m fileName = elt.getSourceLocation().getSourceFile().getName().toCharArray(); } catch (NullPointerException e) { fileName = new char[0]; } typeName = elt.getName().toCharArray(); genericSignature = new char[0]; superName = new char[0]; interfaceNames = new char[0][]; }
From source file:org.eclipse.ajdt.core.javaelements.DeclareElement.java
License:Open Source License
protected Object createElementInfo() { try {/*from ww w . j a v a 2s . c om*/ IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); DeclareElementInfo elementInfo = new DeclareElementInfo(); if (ipe != IHierarchy.NO_STRUCTURE) { elementInfo.setSourceRangeStart(ipe.getSourceLocation().getOffset()); elementInfo.setName(name.toCharArray()); elementInfo.setAJKind(getKindForString(name)); List<String> types = ipe.getParentTypes(); if (types != null) { List<String> typesConverted = new ArrayList<String>(types.size()); for (String parentTypeName : types) { parentTypeName = parentTypeName.replaceAll("\\$", "\\."); typesConverted.add(parentTypeName); } elementInfo.setTypes((String[]) typesConverted.toArray(new String[typesConverted.size()])); } elementInfo.setAnnotationRemover(ipe.isAnnotationRemover()); } return elementInfo; } catch (Exception e) { // can fail for any of a number of reasons. // return null so that we can try again later. return null; } }